Better handling if a bot is missing a DID, which could be a corrupt or outdated database.
This commit is contained in:
Brian Martin 2019-10-19 15:06:08 -04:00
parent da9d2bbea7
commit e690436a37
3 changed files with 28 additions and 3 deletions

View file

@ -489,7 +489,10 @@ class ConfServer:
bumper.user_add_device(tmpuser["userid"], user_devid) bumper.user_add_device(tmpuser["userid"], user_devid)
for bot in bots: # Add all bots to the user for bot in bots: # Add all bots to the user
if "did" in bot:
bumper.user_add_bot(tmpuser["userid"], bot["did"]) bumper.user_add_bot(tmpuser["userid"], bot["did"])
else:
confserverlog.error("No DID for bot: {}".format(bot))
if "checkLogin" in request.path: # If request was to check a token do so if "checkLogin" in request.path: # If request was to check a token do so
checkToken = self.check_token( checkToken = self.check_token(

View file

@ -309,7 +309,10 @@ def bot_toEcoVacsHome_JSON(bot): # EcoVacs Home
def bot_full_upsert(vacbot): def bot_full_upsert(vacbot):
bots = db_get().table("bots") bots = db_get().table("bots")
Bot = Query() Bot = Query()
if "did" in vacbot:
bots.upsert(vacbot, Bot.did == vacbot["did"]) bots.upsert(vacbot, Bot.did == vacbot["did"])
else:
bumperlog.error("No DID in vacbot: {}".format(vacbot))
def bot_set_nick(did, nick): def bot_set_nick(did, nick):

View file

@ -118,6 +118,25 @@ async def test_login(aiohttp_client):
assert "uid" in jsonresp["data"] assert "uid" in jsonresp["data"]
assert "username" in jsonresp["data"] assert "username" in jsonresp["data"]
# Add a bot to db that doesn't have a did
newbot = {
"class": "dev_1234",
"company": "com_123",
#"did": self.did,
"name": "sn_1234",
"resource": "res_1234",
}
bumper.bot_full_upsert(newbot)
resp = await client.get("/v1/private/us/en/dev_1234/ios/1/0/0/user/login")
assert resp.status == 200
text = await resp.text()
jsonresp = json.loads(text)
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
assert "accessToken" in jsonresp["data"]
assert "uid" in jsonresp["data"]
assert "username" in jsonresp["data"]
async def test_logout(aiohttp_client): async def test_logout(aiohttp_client):
remove_existing_db() remove_existing_db()