remove last star import
This commit is contained in:
parent
89f4b56859
commit
40c972e938
28 changed files with 346 additions and 357 deletions
|
|
@ -1,13 +1,13 @@
|
|||
import asyncio
|
||||
import importlib
|
||||
import logging
|
||||
import os
|
||||
import pkgutil
|
||||
import socket
|
||||
import sys
|
||||
|
||||
from bumper.confserver import ConfServer, WebserverBinding
|
||||
from bumper.db import *
|
||||
from bumper.models import *
|
||||
from bumper.db import revoke_expired_oauths, revoke_expired_tokens
|
||||
from bumper.mqttserver import MQTTHelperBot, MQTTServer
|
||||
from bumper.util import get_logger, log_to_stdout
|
||||
from bumper.xmppserver import XMPPServer
|
||||
|
|
@ -50,7 +50,6 @@ bumper_debug = strtobool(os.environ.get("BUMPER_DEBUG")) or False
|
|||
use_auth = False
|
||||
token_validity_seconds = 3600 # 1 hour
|
||||
oauth_validity_days = 15
|
||||
db = None
|
||||
|
||||
mqtt_server: MQTTServer
|
||||
mqtt_helperbot: MQTTHelperBot
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ from aiohttp.web_response import Response, StreamResponse
|
|||
|
||||
import bumper
|
||||
|
||||
from .db import bot_get, bot_remove, client_get, client_remove, db_get
|
||||
from .plugins import ConfServerApp, WebserverPlugin, WebserverSubApi
|
||||
from .util import get_logger
|
||||
|
||||
|
|
@ -191,8 +192,8 @@ class ConfServer:
|
|||
|
||||
async def _handle_base(self, request: Request) -> Response:
|
||||
try:
|
||||
bots = bumper.db_get().table("bots").all()
|
||||
clients = bumper.db_get().table("clients").all()
|
||||
bots = db_get().table("bots").all()
|
||||
clients = db_get().table("clients").all()
|
||||
mq_sessions = []
|
||||
for (session, _) in bumper.mqtt_server.broker._sessions.values():
|
||||
mq_sessions.append(
|
||||
|
|
@ -333,8 +334,8 @@ class ConfServer:
|
|||
async def _handle_remove_bot(self, request: Request) -> Response:
|
||||
try:
|
||||
did = request.match_info.get("did", "")
|
||||
bumper.bot_remove(did)
|
||||
if bumper.bot_get(did):
|
||||
bot_remove(did)
|
||||
if bot_get(did):
|
||||
return web.json_response({"status": "failed to remove bot"})
|
||||
else:
|
||||
return web.json_response({"status": "successfully removed bot"})
|
||||
|
|
@ -347,8 +348,8 @@ class ConfServer:
|
|||
async def _handle_remove_client(self, request: Request) -> Response:
|
||||
try:
|
||||
resource = request.match_info.get("resource", "")
|
||||
bumper.client_remove(resource)
|
||||
if bumper.client_get(resource):
|
||||
client_remove(resource)
|
||||
if client_get(resource):
|
||||
return web.json_response({"status": "failed to remove client"})
|
||||
else:
|
||||
return web.json_response({"status": "successfully removed client"})
|
||||
|
|
|
|||
|
|
@ -12,10 +12,7 @@ bumperlog = get_logger("bumper")
|
|||
|
||||
|
||||
def db_file():
|
||||
if bumper.db:
|
||||
return bumper.db
|
||||
|
||||
return os_db_path()
|
||||
return os.environ.get("DB_FILE") or os_db_path()
|
||||
|
||||
|
||||
def os_db_path(): # createdir=True):
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ from cachetools import TTLCache
|
|||
from passlib.apps import custom_app_context as pwd_context
|
||||
|
||||
import bumper
|
||||
import bumper.db
|
||||
from bumper.util import get_logger
|
||||
|
||||
mqttserverlog = get_logger("mqttserver")
|
||||
|
|
@ -296,7 +297,7 @@ class BumperMQTTServerPlugin:
|
|||
"ecouser" in didsplit[1] or "bumper" in didsplit[1]
|
||||
):
|
||||
tmpbotdetail = str(didsplit[1]).split("/")
|
||||
bumper.bot_add(
|
||||
db.bot_add(
|
||||
username,
|
||||
didsplit[0],
|
||||
tmpbotdetail[0],
|
||||
|
|
@ -321,8 +322,8 @@ class BumperMQTTServerPlugin:
|
|||
"Bumper Authentication Success - Helperbot: %s", client_id
|
||||
)
|
||||
return True
|
||||
if bumper.check_authcode(didsplit[0], password) or not bumper.use_auth:
|
||||
bumper.client_add(userid, realm, resource)
|
||||
if db.check_authcode(didsplit[0], password) or not bumper.use_auth:
|
||||
db.client_add(userid, realm, resource)
|
||||
mqttserverlog.info(
|
||||
"Bumper Authentication Success - Client - Username: %s - ClientID: %s",
|
||||
username,
|
||||
|
|
@ -397,15 +398,15 @@ class BumperMQTTServerPlugin:
|
|||
) -> None:
|
||||
didsplit = str(client_id).split("@")
|
||||
|
||||
bot = bumper.bot_get(didsplit[0])
|
||||
bot = db.bot_get(didsplit[0])
|
||||
if bot:
|
||||
bumper.bot_set_mqtt(bot["did"], connected)
|
||||
db.bot_set_mqtt(bot["did"], connected)
|
||||
return
|
||||
|
||||
clientresource = didsplit[1].split("/")[1]
|
||||
client = bumper.client_get(clientresource)
|
||||
client = db.client_get(clientresource)
|
||||
if client:
|
||||
bumper.client_set_mqtt(client["resource"], connected)
|
||||
db.client_set_mqtt(client["resource"], connected)
|
||||
|
||||
async def on_broker_message_received( # pylint: disable=no-self-use
|
||||
self, message: IncomingApplicationMessage, **_: dict[str, Any]
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ from aiohttp.web_request import Request
|
|||
from aiohttp.web_response import Response
|
||||
from aiohttp.web_routedef import AbstractRouteDef
|
||||
|
||||
import bumper
|
||||
from bumper.db import db_get, token_by_authcode, user_add_oauth
|
||||
from bumper.models import include_EcoVacsHomeProducts_info
|
||||
from bumper.plugins import WebserverPlugin, WebserverSubApi
|
||||
|
||||
|
||||
|
|
@ -54,11 +55,11 @@ class ApiAppsvrPlugin(WebserverPlugin):
|
|||
todo = postbody["todo"]
|
||||
|
||||
if todo == "GetGlobalDeviceList": # EcoVacs Home
|
||||
bots = bumper.db_get().table("bots").all()
|
||||
bots = db_get().table("bots").all()
|
||||
devices = []
|
||||
for bot in bots:
|
||||
if bot["class"] != "":
|
||||
device = bumper.include_EcoVacsHomeProducts_info(bot)
|
||||
device = include_EcoVacsHomeProducts_info(bot)
|
||||
# Happens if the bot isn't on the EcoVacs Home list
|
||||
if device is not None:
|
||||
devices.append(device)
|
||||
|
|
@ -110,8 +111,8 @@ class ApiAppsvrPlugin(WebserverPlugin):
|
|||
|
||||
async def _handle_appsvr_oauth_callback(self, request: Request) -> Response:
|
||||
try:
|
||||
token = bumper.token_by_authcode(request.query["code"])
|
||||
oauth = bumper.user_add_oauth(token["userid"])
|
||||
token = token_by_authcode(request.query["code"])
|
||||
oauth = user_add_oauth(token["userid"])
|
||||
body = {
|
||||
"code": 0,
|
||||
"data": oauth.toResponse(),
|
||||
|
|
|
|||
|
|
@ -6,10 +6,12 @@ import string
|
|||
from aiohttp import web
|
||||
|
||||
import bumper
|
||||
from bumper import plugins
|
||||
from bumper.db import bot_get
|
||||
from bumper.models import ERR_COMMON
|
||||
from bumper.plugins import ConfServerApp
|
||||
|
||||
|
||||
class portal_api_dim(plugins.ConfServerApp):
|
||||
class portal_api_dim(ConfServerApp):
|
||||
def __init__(self):
|
||||
self.name = "portal_api_dimr"
|
||||
self.plugin_type = "sub_api"
|
||||
|
|
@ -34,7 +36,7 @@ class portal_api_dim(plugins.ConfServerApp):
|
|||
did = json_body["toId"]
|
||||
|
||||
if did != "":
|
||||
bot = bumper.bot_get(did)
|
||||
bot = bot_get(did)
|
||||
if bot["company"] == "eco-ng" and bot["mqtt_connection"] == True:
|
||||
retcmd = await bumper.mqtt_helperbot.send_command(
|
||||
json_body, randomid
|
||||
|
|
@ -50,7 +52,7 @@ class portal_api_dim(plugins.ConfServerApp):
|
|||
json_body["toId"]
|
||||
)
|
||||
)
|
||||
body = {"id": randomid, "errno": bumper.ERR_COMMON, "ret": "fail"}
|
||||
body = {"id": randomid, "errno": ERR_COMMON, "ret": "fail"}
|
||||
return web.json_response(body)
|
||||
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -6,10 +6,11 @@ import string
|
|||
from aiohttp import web
|
||||
|
||||
import bumper
|
||||
from bumper import plugins
|
||||
from bumper.db import bot_get
|
||||
from bumper.plugins import ConfServerApp
|
||||
|
||||
|
||||
class portal_api_iot(plugins.ConfServerApp):
|
||||
class portal_api_iot(ConfServerApp):
|
||||
def __init__(self):
|
||||
self.name = "portal_api_iot"
|
||||
self.plugin_type = "sub_api"
|
||||
|
|
@ -34,7 +35,7 @@ class portal_api_iot(plugins.ConfServerApp):
|
|||
did = json_body["toId"]
|
||||
|
||||
if did != "":
|
||||
bot = bumper.bot_get(did)
|
||||
bot = bot_get(did)
|
||||
if bot["company"] == "eco-ng":
|
||||
retcmd = await bumper.mqtt_helperbot.send_command(
|
||||
json_body, randomid
|
||||
|
|
|
|||
|
|
@ -7,10 +7,12 @@ import xml.etree.ElementTree as ET
|
|||
from aiohttp import web
|
||||
|
||||
import bumper
|
||||
from bumper import plugins
|
||||
from bumper.db import bot_get
|
||||
from bumper.models import ERR_COMMON
|
||||
from bumper.plugins import ConfServerApp
|
||||
|
||||
|
||||
class portal_api_lg(plugins.ConfServerApp):
|
||||
class portal_api_lg(ConfServerApp):
|
||||
def __init__(self):
|
||||
self.name = "portal_api_lg"
|
||||
self.plugin_type = "sub_api"
|
||||
|
|
@ -28,7 +30,7 @@ class portal_api_lg(plugins.ConfServerApp):
|
|||
|
||||
did = json_body["did"]
|
||||
|
||||
botdetails = bumper.bot_get(did)
|
||||
botdetails = bot_get(did)
|
||||
if botdetails:
|
||||
if not "cmdName" in json_body:
|
||||
if "td" in json_body:
|
||||
|
|
@ -53,7 +55,7 @@ class portal_api_lg(plugins.ConfServerApp):
|
|||
json_body["payload"] = '<ctl count="30"/>'
|
||||
|
||||
if did != "":
|
||||
bot = bumper.bot_get(did)
|
||||
bot = bot_get(did)
|
||||
if bot["company"] == "eco-ng":
|
||||
retcmd = await bumper.mqtt_helperbot.send_command(
|
||||
json_body, randomid
|
||||
|
|
@ -95,5 +97,5 @@ class portal_api_lg(plugins.ConfServerApp):
|
|||
except Exception as e:
|
||||
logging.exception(f"{e}")
|
||||
|
||||
body = {"id": randomid, "errno": bumper.ERR_COMMON, "ret": "fail"}
|
||||
body = {"id": randomid, "errno": ERR_COMMON, "ret": "fail"}
|
||||
return web.json_response(body)
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import os
|
|||
|
||||
from aiohttp import web
|
||||
|
||||
import bumper
|
||||
from bumper import EcoVacsHomeProducts, plugins
|
||||
from bumper import bumper_dir, plugins
|
||||
from bumper.models import RETURN_API_SUCCESS, EcoVacsHomeProducts
|
||||
|
||||
|
||||
class portal_api_pim(plugins.ConfServerApp):
|
||||
|
|
@ -56,7 +56,7 @@ class portal_api_pim(plugins.ConfServerApp):
|
|||
async def handle_getProductIotMap(self, request):
|
||||
try:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": EcoVacsHomeProducts,
|
||||
}
|
||||
return web.json_response(body)
|
||||
|
|
@ -70,7 +70,7 @@ class portal_api_pim(plugins.ConfServerApp):
|
|||
|
||||
return web.FileResponse(
|
||||
os.path.join(
|
||||
bumper.bumper_dir, "bumper", "web", "images", "robotvac_image.jpg"
|
||||
bumper_dir, "bumper", "web", "images", "robotvac_image.jpg"
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ import logging
|
|||
|
||||
from aiohttp import web
|
||||
|
||||
import bumper
|
||||
from bumper import plugins
|
||||
from bumper import bumper_announce_ip, plugins
|
||||
from bumper.db import bot_remove, bot_set_nick, check_authcode, db_get, loginByItToken
|
||||
|
||||
|
||||
class portal_api_users(plugins.ConfServerApp):
|
||||
|
|
@ -38,7 +38,7 @@ class portal_api_users(plugins.ConfServerApp):
|
|||
if todo == "FindBest":
|
||||
service = postbody["service"]
|
||||
if service == "EcoMsgNew":
|
||||
srvip = bumper.bumper_announce_ip
|
||||
srvip = bumper_announce_ip
|
||||
srvport = 5223
|
||||
logging.info(
|
||||
"Announcing EcoMsgNew Server to bot as: {}:{}".format(
|
||||
|
|
@ -65,7 +65,7 @@ class portal_api_users(plugins.ConfServerApp):
|
|||
|
||||
elif todo == "loginByItToken":
|
||||
if "userId" in postbody:
|
||||
if bumper.check_authcode(postbody["userId"], postbody["token"]):
|
||||
if check_authcode(postbody["userId"], postbody["token"]):
|
||||
body = {
|
||||
"resource": postbody["resource"],
|
||||
"result": "ok",
|
||||
|
|
@ -74,7 +74,7 @@ class portal_api_users(plugins.ConfServerApp):
|
|||
"userId": postbody["userId"],
|
||||
}
|
||||
else: # EcoVacs Home LoginByITToken
|
||||
loginToken = bumper.loginByItToken(postbody["token"])
|
||||
loginToken = loginByItToken(postbody["token"])
|
||||
if not loginToken == {}:
|
||||
body = {
|
||||
"resource": postbody["resource"],
|
||||
|
|
@ -88,21 +88,21 @@ class portal_api_users(plugins.ConfServerApp):
|
|||
|
||||
elif todo == "GetDeviceList":
|
||||
body = {
|
||||
"devices": bumper.db_get().table("bots").all(),
|
||||
"devices": db_get().table("bots").all(),
|
||||
"result": "ok",
|
||||
"todo": "result",
|
||||
}
|
||||
|
||||
elif todo == "SetDeviceNick":
|
||||
bumper.bot_set_nick(postbody["did"], postbody["nick"])
|
||||
bot_set_nick(postbody["did"], postbody["nick"])
|
||||
body = {"result": "ok", "todo": "result"}
|
||||
|
||||
elif todo == "AddOneDevice":
|
||||
bumper.bot_set_nick(postbody["did"], postbody["nick"])
|
||||
bot_set_nick(postbody["did"], postbody["nick"])
|
||||
body = {"result": "ok", "todo": "result"}
|
||||
|
||||
elif todo == "DeleteOneDevice":
|
||||
bumper.bot_remove(postbody["did"])
|
||||
bot_remove(postbody["did"])
|
||||
body = {"result": "ok", "todo": "result"}
|
||||
|
||||
return web.json_response(body)
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ import os
|
|||
|
||||
from aiohttp import web
|
||||
|
||||
import bumper
|
||||
from bumper import plugins
|
||||
from bumper import bumper_dir, plugins
|
||||
|
||||
|
||||
class upload_global(plugins.ConfServerApp):
|
||||
|
|
@ -28,7 +27,7 @@ class upload_global(plugins.ConfServerApp):
|
|||
|
||||
return web.FileResponse(
|
||||
os.path.join(
|
||||
bumper.bumper_dir, "bumper", "web", "images", "robotvac_image.jpg"
|
||||
bumper_dir, "bumper", "web", "images", "robotvac_image.jpg"
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import logging
|
|||
|
||||
from aiohttp import web
|
||||
|
||||
import bumper
|
||||
from bumper import plugins
|
||||
from bumper.models import RETURN_API_SUCCESS
|
||||
from bumper.util import get_current_time_as_millis
|
||||
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ class v1_private_ad(plugins.ConfServerApp):
|
|||
async def handle_getAdByPositionType(self, request): # EcoVacs Home
|
||||
try:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": None,
|
||||
"msg": "操作成功",
|
||||
"success": True,
|
||||
|
|
@ -46,7 +46,7 @@ class v1_private_ad(plugins.ConfServerApp):
|
|||
async def handle_getBootScreen(self, request): # EcoVacs Home
|
||||
try:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": None,
|
||||
"msg": "操作成功",
|
||||
"success": True,
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ from datetime import datetime, timedelta
|
|||
|
||||
from aiohttp import web
|
||||
|
||||
import bumper
|
||||
from bumper import plugins
|
||||
from bumper.models import RETURN_API_SUCCESS
|
||||
from bumper.util import convert_to_millis, get_current_time_as_millis
|
||||
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ class v1_private_campaign(plugins.ConfServerApp):
|
|||
)
|
||||
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": {
|
||||
"clickSchemeUrl": None,
|
||||
"clickWebUrl": None,
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import logging
|
|||
|
||||
from aiohttp import web
|
||||
|
||||
import bumper
|
||||
from bumper import plugins
|
||||
from bumper.models import RETURN_API_SUCCESS
|
||||
from bumper.util import get_current_time_as_millis
|
||||
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ class v1_private_common(plugins.ConfServerApp):
|
|||
async def handle_checkVersion(self, request):
|
||||
try:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": {
|
||||
"c": None,
|
||||
"img": None,
|
||||
|
|
@ -89,7 +89,7 @@ class v1_private_common(plugins.ConfServerApp):
|
|||
async def handle_checkAPPVersion(self, request): # EcoVacs Home
|
||||
try:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": {
|
||||
"c": None,
|
||||
"downPageUrl": None,
|
||||
|
|
@ -114,7 +114,7 @@ class v1_private_common(plugins.ConfServerApp):
|
|||
async def handle_uploadDeviceInfo(self, request): # EcoVacs Home
|
||||
try:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": None,
|
||||
"msg": "操作成功",
|
||||
"success": True,
|
||||
|
|
@ -129,7 +129,7 @@ class v1_private_common(plugins.ConfServerApp):
|
|||
async def handle_getSystemReminder(self, request): # EcoVacs Home
|
||||
try:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": {
|
||||
"iosGradeTime": {"iodGradeFlag": "N"},
|
||||
"openNotification": {
|
||||
|
|
@ -155,7 +155,7 @@ class v1_private_common(plugins.ConfServerApp):
|
|||
data.append({"key": key, "value": "Y"})
|
||||
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": data,
|
||||
"msg": "操作成功",
|
||||
"success": True,
|
||||
|
|
@ -170,7 +170,7 @@ class v1_private_common(plugins.ConfServerApp):
|
|||
async def handle_getAreas(self, request):
|
||||
try:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": AREA_LIST,
|
||||
"msg": "操作成功",
|
||||
"success": True,
|
||||
|
|
@ -185,7 +185,7 @@ class v1_private_common(plugins.ConfServerApp):
|
|||
async def handle_getAgreementURLBatch(self, request): # EcoVacs Home
|
||||
try:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": [
|
||||
{
|
||||
"acceptTime": None,
|
||||
|
|
@ -218,7 +218,7 @@ class v1_private_common(plugins.ConfServerApp):
|
|||
try:
|
||||
time = get_current_time_as_millis()
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": {"timestamp": time},
|
||||
"msg": "操作成功",
|
||||
"success": True,
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import logging
|
|||
|
||||
from aiohttp import web
|
||||
|
||||
import bumper
|
||||
from bumper import plugins
|
||||
from bumper.models import RETURN_API_SUCCESS
|
||||
from bumper.util import get_current_time_as_millis
|
||||
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ class v1_private_message(plugins.ConfServerApp):
|
|||
async def handle_hasUnreadMessage(self, request): # EcoVacs Home
|
||||
try:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": "N",
|
||||
"msg": "操作成功",
|
||||
"success": True,
|
||||
|
|
@ -46,7 +46,7 @@ class v1_private_message(plugins.ConfServerApp):
|
|||
async def handle_getMsgList(self, request): # EcoVacs Home
|
||||
try:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": {"hasNextPage": 0, "items": []},
|
||||
"msg": "操作成功",
|
||||
"success": True,
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import logging
|
|||
|
||||
from aiohttp import web
|
||||
|
||||
import bumper
|
||||
from bumper import plugins
|
||||
from bumper.models import RETURN_API_SUCCESS
|
||||
from bumper.util import get_current_time_as_millis
|
||||
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ class v1_private_shop(plugins.ConfServerApp):
|
|||
async def handle_getCnWapShopConfig(self, request): # EcoVacs Home
|
||||
try:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": {
|
||||
"myShopShowFlag": "N",
|
||||
"myShopUrl": "",
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import logging
|
|||
|
||||
from aiohttp import web
|
||||
|
||||
import bumper
|
||||
from bumper import plugins
|
||||
from bumper.models import RETURN_API_SUCCESS
|
||||
from bumper.rest import auth_util
|
||||
from bumper.util import get_current_time_as_millis
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ class v1_private_user(plugins.ConfServerApp):
|
|||
apptype = request.match_info.get("apptype", "")
|
||||
if "global_" in apptype:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": [
|
||||
{
|
||||
"force": "N",
|
||||
|
|
@ -116,7 +116,7 @@ class v1_private_user(plugins.ConfServerApp):
|
|||
}
|
||||
else:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": [],
|
||||
"msg": "操作成功",
|
||||
"time": get_current_time_as_millis(),
|
||||
|
|
@ -199,7 +199,7 @@ class v1_private_user(plugins.ConfServerApp):
|
|||
async def handle_changeArea(self, request):
|
||||
try:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": {"isNeedReLogin": "N"},
|
||||
"msg": "操作成功",
|
||||
"success": True,
|
||||
|
|
@ -214,7 +214,7 @@ class v1_private_user(plugins.ConfServerApp):
|
|||
async def handle_acceptAgreementBatch(self, request):
|
||||
try:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": None,
|
||||
"msg": "操作成功",
|
||||
"success": True,
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import logging
|
|||
|
||||
from aiohttp import web
|
||||
|
||||
import bumper
|
||||
from bumper import plugins
|
||||
from bumper.models import RETURN_API_SUCCESS
|
||||
from bumper.util import get_current_time_as_millis
|
||||
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ class v1_private_userSetting(plugins.ConfServerApp):
|
|||
try:
|
||||
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": {
|
||||
"acceptSuggestion": "Y",
|
||||
"itemList": [
|
||||
|
|
|
|||
|
|
@ -4,15 +4,29 @@ import uuid
|
|||
|
||||
from aiohttp import web
|
||||
|
||||
import bumper
|
||||
from bumper import (
|
||||
from bumper import db, use_auth
|
||||
from bumper.db import (
|
||||
db_get,
|
||||
user_add,
|
||||
user_add_authcode,
|
||||
user_add_bot,
|
||||
user_add_device,
|
||||
user_add_token,
|
||||
user_by_deviceid,
|
||||
user_get,
|
||||
user_get_token,
|
||||
user_revoke_expired_tokens,
|
||||
user_revoke_token,
|
||||
)
|
||||
from bumper.models import (
|
||||
API_ERRORS,
|
||||
ERR_TOKEN_INVALID,
|
||||
ERR_USER_NOT_ACTIVATED,
|
||||
RETURN_API_SUCCESS,
|
||||
EcoVacs_Login,
|
||||
EcoVacsHome_Login,
|
||||
get_logger,
|
||||
)
|
||||
from bumper.util import get_current_time_as_millis
|
||||
from bumper.util import get_current_time_as_millis, get_logger
|
||||
|
||||
_logger = get_logger("confserver")
|
||||
|
||||
|
|
@ -20,7 +34,7 @@ _logger = get_logger("confserver")
|
|||
def generate_token(user):
|
||||
try:
|
||||
tmpaccesstoken = uuid.uuid4().hex
|
||||
bumper.user_add_token(user["userid"], tmpaccesstoken)
|
||||
user_add_token(user["userid"], tmpaccesstoken)
|
||||
return tmpaccesstoken
|
||||
|
||||
except Exception as e:
|
||||
|
|
@ -30,7 +44,7 @@ def generate_token(user):
|
|||
def generate_authcode(user, countrycode, token):
|
||||
try:
|
||||
tmpauthcode = f"{countrycode}_{uuid.uuid4().hex}"
|
||||
bumper.user_add_authcode(user["userid"], token, tmpauthcode)
|
||||
user_add_authcode(user["userid"], token, tmpauthcode)
|
||||
return tmpauthcode
|
||||
|
||||
except Exception as e:
|
||||
|
|
@ -43,11 +57,11 @@ async def login(request):
|
|||
countrycode = request.match_info.get("country", "us")
|
||||
apptype = request.match_info.get("apptype", "")
|
||||
_logger.info(f"client with devid {user_devid} attempting login")
|
||||
if bumper.use_auth:
|
||||
if use_auth:
|
||||
if (
|
||||
not user_devid == ""
|
||||
): # Performing basic "auth" using devid, super insecure
|
||||
user = bumper.user_by_deviceid(user_devid)
|
||||
user = user_by_deviceid(user_devid)
|
||||
if "checkLogin" in request.path:
|
||||
check_token(
|
||||
apptype, countrycode, user, request.query["accessToken"]
|
||||
|
|
@ -63,7 +77,7 @@ async def login(request):
|
|||
login_details = EcoVacs_Login()
|
||||
|
||||
# Deactivate old tokens and authcodes
|
||||
bumper.user_revoke_expired_tokens(user["userid"])
|
||||
user_revoke_expired_tokens(user["userid"])
|
||||
|
||||
login_details.accessToken = generate_token(user)
|
||||
login_details.uid = "fuid_{}".format(user["userid"])
|
||||
|
|
@ -88,7 +102,7 @@ async def login(request):
|
|||
return web.json_response(body)
|
||||
|
||||
body = {
|
||||
"code": bumper.ERR_USER_NOT_ACTIVATED,
|
||||
"code": ERR_USER_NOT_ACTIVATED,
|
||||
"data": None,
|
||||
"msg": "当前密码错误",
|
||||
"time": get_current_time_as_millis(),
|
||||
|
|
@ -113,13 +127,11 @@ async def get_authcode(request):
|
|||
user_devid = request.query["deviceId"] # Ecovacs Home
|
||||
|
||||
if not user_devid == "":
|
||||
user = bumper.user_by_deviceid(user_devid)
|
||||
user = user_by_deviceid(user_devid)
|
||||
token = ""
|
||||
if user:
|
||||
if "accessToken" in request.query:
|
||||
token = bumper.user_get_token(
|
||||
user["userid"], request.query["accessToken"]
|
||||
)
|
||||
token = user_get_token(user["userid"], request.query["accessToken"])
|
||||
if token:
|
||||
authcode = ""
|
||||
if not "authcode" in token:
|
||||
|
|
@ -132,7 +144,7 @@ async def get_authcode(request):
|
|||
authcode = token["authcode"]
|
||||
if "global" in apptype:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": {
|
||||
"authCode": authcode,
|
||||
"ecovacsUid": request.query["uid"],
|
||||
|
|
@ -143,7 +155,7 @@ async def get_authcode(request):
|
|||
}
|
||||
else:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": {
|
||||
"authCode": authcode,
|
||||
"ecovacsUid": request.query["uid"],
|
||||
|
|
@ -154,7 +166,7 @@ async def get_authcode(request):
|
|||
return web.json_response(body)
|
||||
|
||||
body = {
|
||||
"code": bumper.ERR_TOKEN_INVALID,
|
||||
"code": ERR_TOKEN_INVALID,
|
||||
"data": None,
|
||||
"msg": "当前密码错误",
|
||||
"time": get_current_time_as_millis(),
|
||||
|
|
@ -168,7 +180,7 @@ async def get_authcode(request):
|
|||
|
||||
def check_token(apptype, countrycode, user, token):
|
||||
try:
|
||||
if bumper.check_token(user["userid"], token):
|
||||
if db.check_token(user["userid"], token):
|
||||
|
||||
if "global_" in apptype: # EcoVacs Home
|
||||
login_details = EcoVacsHome_Login()
|
||||
|
|
@ -185,7 +197,7 @@ def check_token(apptype, countrycode, user, token):
|
|||
login_details.email = "null@null.com"
|
||||
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": json.loads(login_details.toJSON()),
|
||||
# {
|
||||
# "accessToken": self.generate_token(tmpuser), # Generate a token
|
||||
|
|
@ -201,7 +213,7 @@ def check_token(apptype, countrycode, user, token):
|
|||
|
||||
else:
|
||||
body = {
|
||||
"code": bumper.ERR_TOKEN_INVALID,
|
||||
"code": ERR_TOKEN_INVALID,
|
||||
"data": None,
|
||||
"msg": "当前密码错误",
|
||||
"time": get_current_time_as_millis(),
|
||||
|
|
@ -216,8 +228,8 @@ def _auth_any(devid, apptype, country, request):
|
|||
try:
|
||||
user_devid = devid
|
||||
countrycode = country
|
||||
user = bumper.user_by_deviceid(user_devid)
|
||||
bots = bumper.db_get().table("bots").all()
|
||||
user = user_by_deviceid(user_devid)
|
||||
bots = db_get().table("bots").all()
|
||||
|
||||
if user: # Default to user 0
|
||||
tmpuser = user
|
||||
|
|
@ -234,10 +246,10 @@ def _auth_any(devid, apptype, country, request):
|
|||
login_details.username = "fusername_{}".format(tmpuser["userid"])
|
||||
login_details.country = countrycode
|
||||
login_details.email = "null@null.com"
|
||||
bumper.user_add_device(tmpuser["userid"], user_devid)
|
||||
user_add_device(tmpuser["userid"], user_devid)
|
||||
else:
|
||||
bumper.user_add("tmpuser") # Add a new user
|
||||
tmpuser = bumper.user_get("tmpuser")
|
||||
user_add("tmpuser") # Add a new user
|
||||
tmpuser = user_get("tmpuser")
|
||||
if "global_" in apptype: # EcoVacs Home
|
||||
login_details = EcoVacsHome_Login()
|
||||
login_details.ucUid = "fuid_{}".format(tmpuser["userid"])
|
||||
|
|
@ -251,11 +263,11 @@ def _auth_any(devid, apptype, country, request):
|
|||
login_details.username = "fusername_{}".format(tmpuser["userid"])
|
||||
login_details.country = countrycode
|
||||
login_details.email = "null@null.com"
|
||||
bumper.user_add_device(tmpuser["userid"], user_devid)
|
||||
user_add_device(tmpuser["userid"], user_devid)
|
||||
|
||||
for bot in bots: # Add all bots to the user
|
||||
if "did" in bot:
|
||||
bumper.user_add_bot(tmpuser["userid"], bot["did"])
|
||||
user_add_bot(tmpuser["userid"], bot["did"])
|
||||
else:
|
||||
_logger.error(f"No DID for bot: {bot}")
|
||||
|
||||
|
|
@ -268,10 +280,10 @@ def _auth_any(devid, apptype, country, request):
|
|||
return isGood
|
||||
|
||||
# Deactivate old tokens and authcodes
|
||||
bumper.user_revoke_expired_tokens(tmpuser["userid"])
|
||||
user_revoke_expired_tokens(tmpuser["userid"])
|
||||
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": json.loads(login_details.toJSON()),
|
||||
# {
|
||||
# "accessToken": self.generate_token(tmpuser), # Generate a token
|
||||
|
|
@ -295,7 +307,7 @@ def get_user_account_info(request):
|
|||
user_devid = request.match_info.get("devid", "")
|
||||
countrycode = request.match_info.get("country", "us")
|
||||
apptype = request.match_info.get("apptype", "")
|
||||
user = bumper.user_by_deviceid(user_devid)
|
||||
user = user_by_deviceid(user_devid)
|
||||
|
||||
if "global_" in apptype: # EcoVacs Home
|
||||
login_details = EcoVacsHome_Login()
|
||||
|
|
@ -311,7 +323,7 @@ def get_user_account_info(request):
|
|||
login_details.email = "null@null.com"
|
||||
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": {
|
||||
"email": login_details.email,
|
||||
"hasMobile": "N",
|
||||
|
|
@ -363,16 +375,14 @@ async def logout(request):
|
|||
try:
|
||||
user_devid = request.match_info.get("devid", "")
|
||||
if not user_devid == "":
|
||||
user = bumper.user_by_deviceid(user_devid)
|
||||
user = user_by_deviceid(user_devid)
|
||||
if user:
|
||||
if bumper.check_token(user["userid"], request.query["accessToken"]):
|
||||
if db.check_token(user["userid"], request.query["accessToken"]):
|
||||
# Deactivate old tokens and authcodes
|
||||
bumper.user_revoke_token(
|
||||
user["userid"], request.query["accessToken"]
|
||||
)
|
||||
user_revoke_token(user["userid"], request.query["accessToken"])
|
||||
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": None,
|
||||
"msg": "操作成功",
|
||||
"time": get_current_time_as_millis(),
|
||||
|
|
|
|||
|
|
@ -6,10 +6,18 @@ import uuid
|
|||
import xml.etree.ElementTree as ET
|
||||
|
||||
import bumper
|
||||
from bumper import get_logger
|
||||
from bumper.db import (
|
||||
bot_add,
|
||||
bot_get,
|
||||
bot_set_xmpp,
|
||||
check_authcode,
|
||||
client_add,
|
||||
client_get,
|
||||
client_set_xmpp,
|
||||
)
|
||||
|
||||
xmppserverlog = get_logger("xmppserver")
|
||||
boterrorlog = get_logger("boterror")
|
||||
xmppserverlog = bumper.get_logger("xmppserver")
|
||||
boterrorlog = bumper.get_logger("boterror")
|
||||
|
||||
|
||||
class XMPPServer:
|
||||
|
|
@ -125,13 +133,13 @@ class XMPPAsyncClient:
|
|||
def _disconnect(self):
|
||||
try:
|
||||
|
||||
bot = bumper.bot_get(self.uid)
|
||||
bot = bot_get(self.uid)
|
||||
if bot:
|
||||
bumper.bot_set_xmpp(bot["did"], False)
|
||||
bot_set_xmpp(bot["did"], False)
|
||||
|
||||
client = bumper.client_get(self.clientresource)
|
||||
client = client_get(self.clientresource)
|
||||
if client:
|
||||
bumper.client_set_xmpp(client["resource"], False)
|
||||
client_set_xmpp(client["resource"], False)
|
||||
|
||||
self.transport.close()
|
||||
|
||||
|
|
@ -508,7 +516,7 @@ class XMPPAsyncClient:
|
|||
authcode = saslauth[2]
|
||||
|
||||
if self.devclass: # if there is a devclass it is a bot
|
||||
bumper.bot_add(self.uid, self.uid, self.devclass, "atom", "eco-legacy")
|
||||
bot_add(self.uid, self.uid, self.devclass, "atom", "eco-legacy")
|
||||
self.type = self.BOT
|
||||
xmppserverlog.info(f"bot authenticated SN: {self.uid}")
|
||||
# Send response
|
||||
|
|
@ -521,14 +529,14 @@ class XMPPAsyncClient:
|
|||
|
||||
else:
|
||||
auth = False
|
||||
if bumper.check_authcode(self.uid, authcode):
|
||||
if check_authcode(self.uid, authcode):
|
||||
auth = True
|
||||
elif bumper.use_auth == False:
|
||||
elif not bumper.use_auth:
|
||||
auth = True
|
||||
|
||||
if auth:
|
||||
self.type = self.CONTROLLER
|
||||
bumper.client_add(self.uid, "bumper", self.clientresource)
|
||||
client_add(self.uid, "bumper", self.clientresource)
|
||||
xmppserverlog.info(f"client authenticated {self.uid}")
|
||||
|
||||
# Client authenticated, move to next state
|
||||
|
|
@ -551,13 +559,13 @@ class XMPPAsyncClient:
|
|||
def _handle_bind(self, xml):
|
||||
try:
|
||||
|
||||
bot = bumper.bot_get(self.uid)
|
||||
bot = bot_get(self.uid)
|
||||
if bot:
|
||||
bumper.bot_set_xmpp(bot["did"], True)
|
||||
bot_set_xmpp(bot["did"], True)
|
||||
|
||||
client = bumper.client_get(self.clientresource)
|
||||
client = client_get(self.clientresource)
|
||||
if client:
|
||||
bumper.client_set_xmpp(client["resource"], True)
|
||||
client_set_xmpp(client["resource"], True)
|
||||
|
||||
clientbindxml = list(xml)
|
||||
clientresourcexml = list(clientbindxml[0])
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ env =
|
|||
D:BUMPER_CERT=tests/test_certs/bumper.crt
|
||||
D:BUMPER_KEY=tests/test_certs/bumper.key
|
||||
WEB_SERVER_HTTPS_PORT=8443
|
||||
DB_FILE=tests/tmp.db
|
||||
|
||||
asyncio_mode = auto
|
||||
timeout = 10
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ import pytest
|
|||
from amqtt.client import MQTTClient
|
||||
|
||||
import bumper
|
||||
from bumper import WebserverBinding
|
||||
from bumper import MQTTServer, WebserverBinding
|
||||
from tests import CONF_SERVER_PORT, HOST, MQTT_PORT
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def mqtt_server():
|
||||
mqtt_server = bumper.MQTTServer(HOST, MQTT_PORT, password_file="tests/passwd")
|
||||
mqtt_server = MQTTServer(HOST, MQTT_PORT, password_file="tests/passwd")
|
||||
await mqtt_server.start()
|
||||
bumper.mqtt_server = mqtt_server
|
||||
while not mqtt_server.state == "started":
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import asyncio
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
from unittest import mock
|
||||
|
|
@ -7,12 +6,13 @@ from unittest import mock
|
|||
import pytest
|
||||
|
||||
import bumper
|
||||
from bumper import WebserverBinding
|
||||
from bumper import ConfServer, MQTTHelperBot, WebserverBinding, XMPPServer, db
|
||||
from bumper.models import ERR_TOKEN_INVALID, RETURN_API_SUCCESS
|
||||
from tests import CONF_SERVER_PORT, HOST, MQTT_PORT
|
||||
|
||||
|
||||
def create_confserver():
|
||||
return bumper.ConfServer(WebserverBinding(HOST, CONF_SERVER_PORT, False))
|
||||
return ConfServer(WebserverBinding(HOST, CONF_SERVER_PORT, False))
|
||||
|
||||
|
||||
def async_return(result):
|
||||
|
|
@ -27,28 +27,27 @@ def remove_existing_db():
|
|||
|
||||
|
||||
async def test_confserver_ssl():
|
||||
conf_server = bumper.ConfServer(WebserverBinding(HOST, CONF_SERVER_PORT, True))
|
||||
conf_server = ConfServer(WebserverBinding(HOST, CONF_SERVER_PORT, True))
|
||||
await conf_server.start()
|
||||
|
||||
|
||||
async def test_confserver_no_ssl():
|
||||
conf_server = bumper.ConfServer(WebserverBinding(HOST, 11112, False))
|
||||
conf_server = ConfServer(WebserverBinding(HOST, 11112, False))
|
||||
await conf_server.start()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mqtt_server")
|
||||
async def test_base(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
# Start XMPP
|
||||
xmpp_address = (HOST, 5223)
|
||||
xmpp_server = bumper.XMPPServer(xmpp_address)
|
||||
xmpp_server = XMPPServer(xmpp_address)
|
||||
bumper.xmpp_server = xmpp_server
|
||||
await xmpp_server.start_async_server()
|
||||
|
||||
# Start Helperbot
|
||||
mqtt_helperbot = bumper.MQTTHelperBot(HOST, MQTT_PORT)
|
||||
mqtt_helperbot = MQTTHelperBot(HOST, MQTT_PORT)
|
||||
bumper.mqtt_helperbot = mqtt_helperbot
|
||||
await mqtt_helperbot.start()
|
||||
|
||||
|
|
@ -63,16 +62,15 @@ async def test_base(conf_server_client):
|
|||
@pytest.mark.usefixtures("mqtt_server")
|
||||
async def test_restartService(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
# Start XMPP
|
||||
xmpp_address = (HOST, 5223)
|
||||
xmpp_server = bumper.XMPPServer(xmpp_address)
|
||||
xmpp_server = XMPPServer(xmpp_address)
|
||||
bumper.xmpp_server = xmpp_server
|
||||
await xmpp_server.start_async_server()
|
||||
|
||||
# Start Helperbot
|
||||
mqtt_helperbot = bumper.MQTTHelperBot(HOST, MQTT_PORT)
|
||||
mqtt_helperbot = MQTTHelperBot(HOST, MQTT_PORT)
|
||||
bumper.mqtt_helperbot = mqtt_helperbot
|
||||
await mqtt_helperbot.start()
|
||||
|
||||
|
|
@ -102,7 +100,6 @@ async def test_RemoveClient(conf_server_client):
|
|||
|
||||
async def test_login(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
# Test without user
|
||||
resp = await conf_server_client.get(
|
||||
|
|
@ -111,13 +108,12 @@ async def test_login(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
assert "accessToken" in jsonresp["data"]
|
||||
assert "uid" in jsonresp["data"]
|
||||
assert "username" in jsonresp["data"]
|
||||
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
# Test global_e without user
|
||||
resp = await conf_server_client.get(
|
||||
|
|
@ -126,33 +122,33 @@ async def test_login(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
assert "accessToken" in jsonresp["data"]
|
||||
assert "uid" in jsonresp["data"]
|
||||
assert "username" in jsonresp["data"]
|
||||
|
||||
# Add a user to db and test with existing users
|
||||
bumper.user_add("testuser")
|
||||
db.user_add("testuser")
|
||||
resp = await conf_server_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 jsonresp["code"] == RETURN_API_SUCCESS
|
||||
assert "accessToken" in jsonresp["data"]
|
||||
assert "uid" in jsonresp["data"]
|
||||
assert "username" in jsonresp["data"]
|
||||
|
||||
# Add a bot to db that will be added to user
|
||||
bumper.bot_add("sn_123", "did_123", "dev_123", "res_123", "com_123")
|
||||
db.bot_add("sn_123", "did_123", "dev_123", "res_123", "com_123")
|
||||
resp = await conf_server_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 jsonresp["code"] == RETURN_API_SUCCESS
|
||||
assert "accessToken" in jsonresp["data"]
|
||||
assert "uid" in jsonresp["data"]
|
||||
assert "username" in jsonresp["data"]
|
||||
|
|
@ -165,7 +161,7 @@ async def test_login(conf_server_client):
|
|||
"name": "sn_1234",
|
||||
"resource": "res_1234",
|
||||
}
|
||||
bumper.bot_full_upsert(newbot)
|
||||
db.bot_full_upsert(newbot)
|
||||
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/ios/1/0/0/user/login"
|
||||
|
|
@ -173,7 +169,7 @@ async def test_login(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
assert "accessToken" in jsonresp["data"]
|
||||
assert "uid" in jsonresp["data"]
|
||||
assert "username" in jsonresp["data"]
|
||||
|
|
@ -181,12 +177,11 @@ async def test_login(conf_server_client):
|
|||
|
||||
async def test_logout(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
# Add a token to user and test
|
||||
bumper.user_add("testuser")
|
||||
bumper.user_add_device("testuser", "dev_1234")
|
||||
bumper.user_add_token("testuser", "token_1234")
|
||||
db.user_add("testuser")
|
||||
db.user_add_device("testuser", "dev_1234")
|
||||
db.user_add_token("testuser", "token_1234")
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/ios/1/0/0/user/logout?accessToken={}".format(
|
||||
"token_1234"
|
||||
|
|
@ -196,12 +191,11 @@ async def test_logout(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
|
||||
|
||||
async def test_checkLogin(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
# Test without token
|
||||
resp = await conf_server_client.get(
|
||||
|
|
@ -212,14 +206,14 @@ async def test_checkLogin(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
assert "accessToken" in jsonresp["data"]
|
||||
assert jsonresp["data"]["accessToken"] != "token_1234"
|
||||
assert "uid" in jsonresp["data"]
|
||||
assert "username" in jsonresp["data"]
|
||||
|
||||
# Add a user to db and test with existing users
|
||||
bumper.user_add("testuser")
|
||||
db.user_add("testuser")
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/ios/1/0/0/user/checkLogin?accessToken={}".format(
|
||||
None
|
||||
|
|
@ -228,14 +222,14 @@ async def test_checkLogin(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
assert "accessToken" in jsonresp["data"]
|
||||
assert jsonresp["data"]["accessToken"] != "token_1234"
|
||||
assert "uid" in jsonresp["data"]
|
||||
assert "username" in jsonresp["data"]
|
||||
|
||||
# Test again using global_e app
|
||||
bumper.user_add("testuser")
|
||||
db.user_add("testuser")
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/global_e/1/0/0/user/checkLogin?accessToken={}".format(
|
||||
None
|
||||
|
|
@ -244,19 +238,19 @@ async def test_checkLogin(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
assert "accessToken" in jsonresp["data"]
|
||||
assert jsonresp["data"]["accessToken"] != "token_1234"
|
||||
assert "uid" in jsonresp["data"]
|
||||
assert "username" in jsonresp["data"]
|
||||
|
||||
# Remove dev from tmpuser
|
||||
bumper.user_remove_device("tmpuser", "dev_1234")
|
||||
db.user_remove_device("tmpuser", "dev_1234")
|
||||
|
||||
# Add a token to user and test
|
||||
bumper.user_add("testuser")
|
||||
bumper.user_add_device("testuser", "dev_1234")
|
||||
bumper.user_add_token("testuser", "token_1234")
|
||||
db.user_add("testuser")
|
||||
db.user_add_device("testuser", "dev_1234")
|
||||
db.user_add_token("testuser", "token_1234")
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/ios/1/0/0/user/checkLogin?accessToken={}".format(
|
||||
"token_1234"
|
||||
|
|
@ -265,14 +259,14 @@ async def test_checkLogin(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
assert "accessToken" in jsonresp["data"]
|
||||
assert jsonresp["data"]["accessToken"] == "token_1234"
|
||||
assert "uid" in jsonresp["data"]
|
||||
assert "username" in jsonresp["data"]
|
||||
|
||||
# Test again using global_e app
|
||||
bumper.user_add("testuser")
|
||||
db.user_add("testuser")
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/global_e/1/0/0/user/checkLogin?accessToken={}".format(
|
||||
"token_1234"
|
||||
|
|
@ -281,7 +275,7 @@ async def test_checkLogin(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
assert "accessToken" in jsonresp["data"]
|
||||
assert jsonresp["data"]["accessToken"] == "token_1234"
|
||||
assert "uid" in jsonresp["data"]
|
||||
|
|
@ -290,7 +284,6 @@ async def test_checkLogin(conf_server_client):
|
|||
|
||||
async def test_getAuthCode(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
# Test without user or token
|
||||
resp = await conf_server_client.get(
|
||||
|
|
@ -301,7 +294,7 @@ async def test_getAuthCode(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.ERR_TOKEN_INVALID
|
||||
assert jsonresp["code"] == ERR_TOKEN_INVALID
|
||||
|
||||
# Test as global_e
|
||||
resp = await conf_server_client.get(
|
||||
|
|
@ -310,12 +303,12 @@ async def test_getAuthCode(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.ERR_TOKEN_INVALID
|
||||
assert jsonresp["code"] == ERR_TOKEN_INVALID
|
||||
|
||||
# Add a token to user and test
|
||||
bumper.user_add("testuser")
|
||||
bumper.user_add_device("testuser", "dev_1234")
|
||||
bumper.user_add_token("testuser", "token_1234")
|
||||
db.user_add("testuser")
|
||||
db.user_add_device("testuser", "dev_1234")
|
||||
db.user_add_token("testuser", "token_1234")
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/ios/1/0/0/user/getAuthCode?uid={}&accessToken={}".format(
|
||||
"testuser", "token_1234"
|
||||
|
|
@ -324,7 +317,7 @@ async def test_getAuthCode(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
assert "authCode" in jsonresp["data"]
|
||||
assert "ecovacsUid" in jsonresp["data"]
|
||||
|
||||
|
|
@ -337,14 +330,13 @@ async def test_getAuthCode(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
assert "authCode" in jsonresp["data"]
|
||||
assert "ecovacsUid" in jsonresp["data"]
|
||||
|
||||
|
||||
async def test_checkAgreement(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/ios/1/0/0/user/checkAgreement"
|
||||
|
|
@ -352,7 +344,7 @@ async def test_checkAgreement(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
|
||||
# Test as global_e
|
||||
resp = await conf_server_client.get(
|
||||
|
|
@ -361,12 +353,11 @@ async def test_checkAgreement(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
|
||||
|
||||
async def test_homePageAlert(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/ios/1/0/0/campaign/homePageAlert"
|
||||
|
|
@ -374,12 +365,11 @@ async def test_homePageAlert(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
|
||||
|
||||
async def test_checkVersion(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/ios/1/0/0/common/checkVersion"
|
||||
|
|
@ -387,12 +377,11 @@ async def test_checkVersion(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
|
||||
|
||||
async def test_checkAppVersion(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/global_e/1/0/0/common/checkAPPVersion"
|
||||
|
|
@ -400,24 +389,22 @@ async def test_checkAppVersion(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
|
||||
|
||||
async def test_uploadDeviceInfo(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/global_e/1/0/0/common/uploadDeviceInfo"
|
||||
)
|
||||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
|
||||
|
||||
async def test_getAdByPositionType(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/global_e/1/0/0/ad/getAdByPositionType"
|
||||
|
|
@ -425,12 +412,11 @@ async def test_getAdByPositionType(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
|
||||
|
||||
async def test_getBootScreen(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/global_e/1/0/0/ad/getBootScreen"
|
||||
|
|
@ -438,12 +424,11 @@ async def test_getBootScreen(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
|
||||
|
||||
async def test_hasUnreadMsg(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/global_e/1/0/0/message/hasUnreadMsg"
|
||||
|
|
@ -451,12 +436,11 @@ async def test_hasUnreadMsg(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
|
||||
|
||||
async def test_getMsgList(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/global_e/1/0/0/message/getMsgList"
|
||||
|
|
@ -464,12 +448,11 @@ async def test_getMsgList(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
|
||||
|
||||
async def test_getSystemReminder(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/global_e/1/0/0/common/getSystemReminder"
|
||||
|
|
@ -477,12 +460,11 @@ async def test_getSystemReminder(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
|
||||
|
||||
async def test_getCnWapShopConfig(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/global_e/1/0/0/shop/getCnWapShopConfig"
|
||||
|
|
@ -490,12 +472,11 @@ async def test_getCnWapShopConfig(conf_server_client):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
|
||||
|
||||
async def test_neng_hasUnreadMessage(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
postbody = {
|
||||
"auth": {
|
||||
|
|
@ -518,13 +499,12 @@ async def test_neng_hasUnreadMessage(conf_server_client):
|
|||
|
||||
async def test_getProductIotMap(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
resp = await conf_server_client.post("/api/pim/product/getProductIotMap")
|
||||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert jsonresp["code"] == RETURN_API_SUCCESS
|
||||
|
||||
# Test getPimFile
|
||||
resp = await conf_server_client.get("/api/pim/file/get/123")
|
||||
|
|
@ -533,7 +513,6 @@ async def test_getProductIotMap(conf_server_client):
|
|||
|
||||
async def test_getUsersAPI(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
resp = await conf_server_client.get("/api/users/user.do")
|
||||
assert resp.status == 200
|
||||
|
|
@ -544,13 +523,12 @@ async def test_getUsersAPI(conf_server_client):
|
|||
|
||||
async def test_getUserAccountInfo(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
bumper.user_add("testuser")
|
||||
bumper.user_add_device("testuser", "dev_1234")
|
||||
bumper.user_add_token("testuser", "token_1234")
|
||||
bumper.user_add_authcode("testuser", "token_1234", "auth_1234")
|
||||
bumper.user_add_bot("testuser", "did_1234")
|
||||
bumper.bot_add("sn_1234", "did_1234", "class_1234", "res_1234", "com_1234")
|
||||
db.user_add("testuser")
|
||||
db.user_add_device("testuser", "dev_1234")
|
||||
db.user_add_token("testuser", "token_1234")
|
||||
db.user_add_authcode("testuser", "token_1234", "auth_1234")
|
||||
db.user_add_bot("testuser", "did_1234")
|
||||
db.bot_add("sn_1234", "did_1234", "class_1234", "res_1234", "com_1234")
|
||||
|
||||
resp = await conf_server_client.get(
|
||||
"/v1/private/us/en/dev_1234/global_e/1/0/0/user/getUserAccountInfo"
|
||||
|
|
@ -565,7 +543,6 @@ async def test_getUserAccountInfo(conf_server_client):
|
|||
|
||||
async def test_postUsersAPI(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
# Test FindBest
|
||||
postbody = {"todo": "FindBest", "service": "EcoMsgNew"}
|
||||
|
|
@ -584,12 +561,12 @@ async def test_postUsersAPI(conf_server_client):
|
|||
assert jsonresp["result"] == "ok"
|
||||
|
||||
# Test loginByItToken - Uses the authcode
|
||||
bumper.user_add("testuser")
|
||||
bumper.user_add_device("testuser", "dev_1234")
|
||||
bumper.user_add_token("testuser", "token_1234")
|
||||
bumper.user_add_authcode("testuser", "token_1234", "auth_1234")
|
||||
bumper.user_add_bot("testuser", "did_1234")
|
||||
bumper.bot_add("sn_1234", "did_1234", "class_1234", "res_1234", "com_1234")
|
||||
db.user_add("testuser")
|
||||
db.user_add_device("testuser", "dev_1234")
|
||||
db.user_add_token("testuser", "token_1234")
|
||||
db.user_add_authcode("testuser", "token_1234", "auth_1234")
|
||||
db.user_add_bot("testuser", "did_1234")
|
||||
db.bot_add("sn_1234", "did_1234", "class_1234", "res_1234", "com_1234")
|
||||
# Test
|
||||
postbody = {
|
||||
"country": "US",
|
||||
|
|
@ -715,7 +692,6 @@ async def test_postUsersAPI(conf_server_client):
|
|||
|
||||
async def test_appsvr_api(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
# Test GetGlobalDeviceList
|
||||
postbody = {
|
||||
|
|
@ -741,7 +717,7 @@ async def test_appsvr_api(conf_server_client):
|
|||
jsonresp = json.loads(text)
|
||||
assert jsonresp["ret"] == "ok"
|
||||
|
||||
bumper.bot_add("sn_1234", "did_1234", "ls1ok3", "res_1234", "eco-ng")
|
||||
db.bot_add("sn_1234", "did_1234", "ls1ok3", "res_1234", "eco-ng")
|
||||
|
||||
# Test again with bot added
|
||||
resp = await conf_server_client.post("/api/appsvr/app.do", json=postbody)
|
||||
|
|
@ -753,11 +729,10 @@ async def test_appsvr_api(conf_server_client):
|
|||
|
||||
async def test_lg_logs(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
bumper.bot_add("sn_1234", "did_1234", "ls1ok3", "res_1234", "eco-ng")
|
||||
bumper.bot_set_mqtt("did_1234", True)
|
||||
db.bot_add("sn_1234", "did_1234", "ls1ok3", "res_1234", "eco-ng")
|
||||
db.bot_set_mqtt("did_1234", True)
|
||||
confserver = create_confserver()
|
||||
bumper.mqtt_helperbot = bumper.mqttserver.MQTTHelperBot(HOST, MQTT_PORT)
|
||||
bumper.mqtt_helperbot = MQTTHelperBot(HOST, MQTT_PORT)
|
||||
|
||||
# Test return get status
|
||||
command_getstatus_resp = {
|
||||
|
|
@ -791,7 +766,6 @@ async def test_lg_logs(conf_server_client):
|
|||
|
||||
async def test_postLookup(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
# Test FindBest
|
||||
postbody = {"todo": "FindBest", "service": "EcoMsgNew"}
|
||||
|
|
@ -812,9 +786,8 @@ async def test_postLookup(conf_server_client):
|
|||
|
||||
async def test_devmgr(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
confserver = create_confserver()
|
||||
bumper.mqtt_helperbot = bumper.mqttserver.MQTTHelperBot(HOST, MQTT_PORT)
|
||||
bumper.mqtt_helperbot = MQTTHelperBot(HOST, MQTT_PORT)
|
||||
|
||||
# Test PollSCResult
|
||||
postbody = {"td": "PollSCResult"}
|
||||
|
|
@ -834,8 +807,8 @@ async def test_devmgr(conf_server_client):
|
|||
assert test_resp["unRead"] == False
|
||||
|
||||
# Test BotCommand
|
||||
bumper.bot_add("sn_1234", "did_1234", "dev_1234", "res_1234", "eco-ng")
|
||||
bumper.bot_set_mqtt("did_1234", True)
|
||||
db.bot_add("sn_1234", "did_1234", "dev_1234", "res_1234", "eco-ng")
|
||||
db.bot_set_mqtt("did_1234", True)
|
||||
postbody = {"toId": "did_1234"}
|
||||
|
||||
# Test return get status
|
||||
|
|
@ -867,9 +840,8 @@ async def test_devmgr(conf_server_client):
|
|||
|
||||
async def test_dim_devmanager(conf_server_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
confserver = create_confserver()
|
||||
bumper.mqtt_helperbot = bumper.mqttserver.MQTTHelperBot(HOST, MQTT_PORT)
|
||||
bumper.mqtt_helperbot = MQTTHelperBot(HOST, MQTT_PORT)
|
||||
|
||||
# Test PollSCResult
|
||||
postbody = {"td": "PollSCResult"}
|
||||
|
|
@ -889,8 +861,8 @@ async def test_dim_devmanager(conf_server_client):
|
|||
assert test_resp["unRead"] == False
|
||||
|
||||
# Test BotCommand
|
||||
bumper.bot_add("sn_1234", "did_1234", "dev_1234", "res_1234", "eco-ng")
|
||||
bumper.bot_set_mqtt("did_1234", True)
|
||||
db.bot_add("sn_1234", "did_1234", "dev_1234", "res_1234", "eco-ng")
|
||||
db.bot_set_mqtt("did_1234", True)
|
||||
postbody = {"toId": "did_1234"}
|
||||
|
||||
# Test return get status
|
||||
|
|
@ -921,7 +893,7 @@ async def test_dim_devmanager(conf_server_client):
|
|||
assert test_resp["errno"] == "timeout"
|
||||
|
||||
# Set bot not on mqtt
|
||||
bumper.bot_set_mqtt("did_1234", False)
|
||||
db.bot_set_mqtt("did_1234", False)
|
||||
bumper.mqtt_helperbot.send_command = mock.MagicMock(
|
||||
return_value=async_return(command_getstatus_resp)
|
||||
)
|
||||
|
|
|
|||
139
tests/test_db.py
139
tests/test_db.py
|
|
@ -1,77 +1,92 @@
|
|||
import os
|
||||
from datetime import datetime, timedelta
|
||||
from unittest import mock
|
||||
|
||||
from tinydb import TinyDB
|
||||
|
||||
import bumper
|
||||
from bumper import data_dir, db
|
||||
|
||||
|
||||
def test_db_path():
|
||||
bumper.db = None
|
||||
assert bumper.db_file() == os.path.join(bumper.data_dir, "bumper.db")
|
||||
env = os.environ.copy()
|
||||
env.pop("DB_FILE")
|
||||
with mock.patch.dict(os.environ, env, clear=True):
|
||||
assert db.db_file() == os.path.join(data_dir, "bumper.db")
|
||||
|
||||
|
||||
def test_user_db():
|
||||
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
bumper.user_add("testuser") # Add testuser
|
||||
db.user_add("testuser") # Add testuser
|
||||
|
||||
assert (
|
||||
bumper.user_get("testuser")["userid"] == "testuser"
|
||||
db.user_get("testuser")["userid"] == "testuser"
|
||||
) # Test that testuser was created and returned
|
||||
|
||||
bumper.user_add_device("testuser", "dev_1234") # Add device to testuser
|
||||
db.user_add_device("testuser", "dev_1234") # Add device to testuser
|
||||
|
||||
assert (
|
||||
bumper.user_by_deviceid("dev_1234")["userid"] == "testuser"
|
||||
db.user_by_deviceid("dev_1234")["userid"] == "testuser"
|
||||
) # Test that testuser was found by deviceid
|
||||
|
||||
bumper.user_remove_device("testuser", "dev_1234") # Remove device from testuser
|
||||
db.user_remove_device("testuser", "dev_1234") # Remove device from testuser
|
||||
|
||||
assert "dev_1234" not in bumper.user_get("testuser")["devices"]
|
||||
assert "dev_1234" not in db.user_get("testuser")["devices"]
|
||||
# Test that dev_1234 was not found in testuser devices
|
||||
|
||||
bumper.user_add_bot("testuser", "bot_1234") # Add bot did to testuser
|
||||
db.user_add_bot("testuser", "bot_1234") # Add bot did to testuser
|
||||
|
||||
assert "bot_1234" in bumper.user_get("testuser")["bots"]
|
||||
assert "bot_1234" in db.user_get("testuser")["bots"]
|
||||
# Test that bot was found in testuser's bot list
|
||||
|
||||
bumper.user_remove_bot("testuser", "bot_1234") # Remove bot did from testuser
|
||||
db.user_remove_bot("testuser", "bot_1234") # Remove bot did from testuser
|
||||
|
||||
assert "bot_1234" not in bumper.user_get("testuser")["bots"]
|
||||
assert "bot_1234" not in db.user_get("testuser")["bots"]
|
||||
# Test that bot was not found in testuser's bot list
|
||||
|
||||
bumper.user_add_token("testuser", "token_1234") # Add token to testuser
|
||||
db.user_add_token("testuser", "token_1234") # Add token to testuser
|
||||
|
||||
assert bumper.check_token("testuser", "token_1234")
|
||||
assert db.check_token("testuser", "token_1234")
|
||||
# Test that token was found for testuser
|
||||
|
||||
assert bumper.user_get_token("testuser", "token_1234")
|
||||
assert db.user_get_token("testuser", "token_1234")
|
||||
# Test that token was returned for testuser
|
||||
|
||||
bumper.user_add_authcode(
|
||||
db.user_add_authcode(
|
||||
"testuser", "token_1234", "auth_1234"
|
||||
) # Add authcode to token_1234 for testuser
|
||||
assert bumper.check_authcode("testuser", "auth_1234")
|
||||
assert db.check_authcode("testuser", "auth_1234")
|
||||
# Test that authcode was found for testuser
|
||||
|
||||
bumper.user_revoke_authcode(
|
||||
db.user_revoke_authcode(
|
||||
"testuser", "token_1234", "auth_1234"
|
||||
) # Remove authcode from testuser
|
||||
assert bumper.check_authcode("testuser", "auth_1234") == False
|
||||
assert db.check_authcode("testuser", "auth_1234") == False
|
||||
# Test that authcode was not found for testuser
|
||||
bumper.user_revoke_token("testuser", "token_1234") # Remove token from testuser
|
||||
db.user_revoke_token("testuser", "token_1234") # Remove token from testuser
|
||||
assert (
|
||||
bumper.check_token("testuser", "token_1234") == False
|
||||
db.check_token("testuser", "token_1234") == False
|
||||
) # Test that token was not found for testuser
|
||||
bumper.user_add_token("testuser", "token_1234") # Add token_1234
|
||||
bumper.user_add_token("testuser", "token_4321") # Add token_4321
|
||||
assert len(bumper.user_get_tokens("testuser")) == 2 # Test 2 tokens are available
|
||||
bumper.user_revoke_all_tokens("testuser") # Revoke all tokens
|
||||
assert len(bumper.user_get_tokens("testuser")) == 0 # Test 0 tokens are available
|
||||
db.user_add_token("testuser", "token_1234") # Add token_1234
|
||||
db.user_add_token("testuser", "token_4321") # Add token_4321
|
||||
assert len(db.user_get_tokens("testuser")) == 2 # Test 2 tokens are available
|
||||
db.user_revoke_all_tokens("testuser") # Revoke all tokens
|
||||
assert len(db.user_get_tokens("testuser")) == 0 # Test 0 tokens are available
|
||||
|
||||
db = TinyDB("tests/tmp.db")
|
||||
tokens = db.table("tokens")
|
||||
db_test = TinyDB("tests/tmp.db")
|
||||
tokens = db_test.table("tokens")
|
||||
tokens.insert(
|
||||
{
|
||||
"userid": "testuser",
|
||||
"token": "token_123456",
|
||||
"expiration": f"{datetime.now() + timedelta(seconds=-10)}",
|
||||
}
|
||||
) # Add expired token
|
||||
db_test.close()
|
||||
assert len(db.user_get_tokens("testuser")) == 1 # Test 1 tokens are available
|
||||
db.user_revoke_expired_tokens("testuser") # Revoke expired tokens
|
||||
assert len(db.user_get_tokens("testuser")) == 0 # Test 0 tokens are available
|
||||
|
||||
db_test = TinyDB("tests/tmp.db")
|
||||
tokens = db_test.table("tokens")
|
||||
tokens.insert(
|
||||
{
|
||||
"userid": "testuser",
|
||||
|
|
@ -79,67 +94,51 @@ def test_user_db():
|
|||
"expiration": f"{datetime.now() + timedelta(seconds=-10)}",
|
||||
}
|
||||
) # Add expired token
|
||||
db.close()
|
||||
assert len(bumper.user_get_tokens("testuser")) == 1 # Test 1 tokens are available
|
||||
bumper.user_revoke_expired_tokens("testuser") # Revoke expired tokens
|
||||
assert len(bumper.user_get_tokens("testuser")) == 0 # Test 0 tokens are available
|
||||
|
||||
db = TinyDB("tests/tmp.db")
|
||||
tokens = db.table("tokens")
|
||||
tokens.insert(
|
||||
{
|
||||
"userid": "testuser",
|
||||
"token": "token_1234",
|
||||
"expiration": f"{datetime.now() + timedelta(seconds=-10)}",
|
||||
}
|
||||
) # Add expired token
|
||||
db.close()
|
||||
assert len(bumper.user_get_tokens("testuser")) == 1 # Test 1 tokens are available
|
||||
bumper.revoke_expired_tokens() # Revoke expired tokens
|
||||
assert len(bumper.user_get_tokens("testuser")) == 0 # Test 0 tokens are available
|
||||
db_test.close()
|
||||
assert len(db.user_get_tokens("testuser")) == 1 # Test 1 tokens are available
|
||||
db.revoke_expired_tokens() # Revoke expired tokens
|
||||
assert len(db.user_get_tokens("testuser")) == 0 # Test 0 tokens are available
|
||||
|
||||
|
||||
def test_bot_db():
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
bumper.bot_add("sn_123", "did_123", "dev_123", "res_123", "co_123")
|
||||
assert bumper.bot_get("did_123") # Test that bot was added to db
|
||||
db.bot_add("sn_123", "did_123", "dev_123", "res_123", "co_123")
|
||||
assert db.bot_get("did_123") # Test that bot was added to db
|
||||
|
||||
bumper.bot_set_nick("did_123", "nick_123")
|
||||
db.bot_set_nick("did_123", "nick_123")
|
||||
assert (
|
||||
bumper.bot_get("did_123")["nick"] == "nick_123"
|
||||
db.bot_get("did_123")["nick"] == "nick_123"
|
||||
) # Test that nick was added to bot
|
||||
|
||||
bumper.bot_set_mqtt("did_123", True)
|
||||
assert bumper.bot_get("did_123")[
|
||||
db.bot_set_mqtt("did_123", True)
|
||||
assert db.bot_get("did_123")[
|
||||
"mqtt_connection"
|
||||
] # Test that mqtt was set True for bot
|
||||
|
||||
bumper.bot_set_xmpp("did_123", True)
|
||||
assert bumper.bot_get("did_123")[
|
||||
db.bot_set_xmpp("did_123", True)
|
||||
assert db.bot_get("did_123")[
|
||||
"xmpp_connection"
|
||||
] # Test that xmpp was set True for bot
|
||||
|
||||
bumper.bot_remove("did_123")
|
||||
assert bumper.bot_get("did_123") == None # Test that bot is no longer in db
|
||||
db.bot_remove("did_123")
|
||||
assert db.bot_get("did_123") == None # Test that bot is no longer in db
|
||||
|
||||
|
||||
def test_client_db():
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
bumper.client_add("user_123", "realm_123", "resource_123")
|
||||
assert bumper.client_get("resource_123") # Test client was added
|
||||
db.client_add("user_123", "realm_123", "resource_123")
|
||||
assert db.client_get("resource_123") # Test client was added
|
||||
|
||||
bumper.client_set_mqtt("resource_123", True)
|
||||
assert bumper.client_get("resource_123")[
|
||||
db.client_set_mqtt("resource_123", True)
|
||||
assert db.client_get("resource_123")[
|
||||
"mqtt_connection"
|
||||
] # Test that mqtt was set True for client
|
||||
|
||||
bumper.client_set_xmpp("resource_123", False)
|
||||
db.client_set_xmpp("resource_123", False)
|
||||
assert (
|
||||
bumper.client_get("resource_123")["xmpp_connection"] == False
|
||||
db.client_get("resource_123")["xmpp_connection"] == False
|
||||
) # Test that xmpp was set False for client
|
||||
assert (
|
||||
len(bumper.get_disconnected_xmpp_clients()) > 0
|
||||
len(db.get_disconnected_xmpp_clients()) > 0
|
||||
) # Test len of connected xmpp clients is 1
|
||||
|
||||
bumper.client_remove("resource_123")
|
||||
assert bumper.client_get("resource_123") == None
|
||||
db.client_remove("resource_123")
|
||||
assert db.client_get("resource_123") == None
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@ import os
|
|||
from testfixtures import LogCapture
|
||||
|
||||
import bumper
|
||||
from bumper import strtobool
|
||||
|
||||
|
||||
def test_strtobool():
|
||||
assert bumper.strtobool("t") == True
|
||||
assert bumper.strtobool("f") == False
|
||||
assert bumper.strtobool(0) == False
|
||||
assert strtobool("t") == True
|
||||
assert strtobool("f") == False
|
||||
assert strtobool(0) == False
|
||||
|
||||
|
||||
async def test_start_stop():
|
||||
|
|
@ -17,18 +18,16 @@ async def test_start_stop():
|
|||
if os.path.exists("tests/tmp.db"):
|
||||
os.remove("tests/tmp.db") # Remove existing db
|
||||
|
||||
b = bumper
|
||||
b.db = "tests/tmp.db" # Set db location for testing
|
||||
asyncio.create_task(b.start())
|
||||
asyncio.create_task(bumper.start())
|
||||
await asyncio.sleep(0.1)
|
||||
l.check_present(("bumper", "INFO", "Starting Bumper"))
|
||||
l.clear()
|
||||
|
||||
await b.shutdown()
|
||||
await bumper.shutdown()
|
||||
l.check_present(
|
||||
("bumper", "INFO", "Shutting down"), ("bumper", "INFO", "Shutdown complete")
|
||||
)
|
||||
assert b.shutting_down == True
|
||||
assert bumper.shutting_down == True
|
||||
|
||||
|
||||
async def test_start_stop_debug():
|
||||
|
|
@ -36,21 +35,19 @@ async def test_start_stop_debug():
|
|||
if os.path.exists("tests/tmp.db"):
|
||||
os.remove("tests/tmp.db") # Remove existing db
|
||||
|
||||
b = bumper
|
||||
b.db = "tests/tmp.db" # Set db location for testing
|
||||
b.bumper_listen = "0.0.0.0"
|
||||
b.bumper_debug = True
|
||||
asyncio.create_task(b.start())
|
||||
bumper.bumper_listen = "0.0.0.0"
|
||||
bumper.bumper_debug = True
|
||||
asyncio.create_task(bumper.start())
|
||||
|
||||
await asyncio.sleep(0.1)
|
||||
while b.mqtt_server.state == "starting":
|
||||
while bumper.mqtt_server.state == "starting":
|
||||
await asyncio.sleep(0.1)
|
||||
l.check_present(("bumper", "INFO", "Starting Bumper"))
|
||||
l.clear()
|
||||
|
||||
asyncio.create_task(b.shutdown())
|
||||
asyncio.create_task(bumper.shutdown())
|
||||
await asyncio.sleep(0.1)
|
||||
l.check_present(
|
||||
("bumper", "INFO", "Shutting down"), ("bumper", "INFO", "Shutdown complete")
|
||||
)
|
||||
assert b.shutting_down == True
|
||||
assert bumper.shutting_down == True
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from bumper import OAuth
|
||||
from bumper.models import OAuth
|
||||
|
||||
|
||||
def test_oauth():
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from amqtt.mqtt.constants import QOS_0
|
|||
from testfixtures import LogCapture
|
||||
|
||||
import bumper
|
||||
from bumper import MQTTHelperBot, MQTTServer, ca_cert, db
|
||||
from tests import HOST, MQTT_PORT
|
||||
|
||||
|
||||
|
|
@ -16,7 +17,7 @@ async def test_helperbot_message(mqtt_client: MQTTClient):
|
|||
with LogCapture() as l:
|
||||
|
||||
# Test broadcast message
|
||||
mqtt_helperbot = bumper.MQTTHelperBot(HOST, MQTT_PORT)
|
||||
mqtt_helperbot = MQTTHelperBot(HOST, MQTT_PORT)
|
||||
await mqtt_helperbot.start()
|
||||
assert mqtt_helperbot.is_connected
|
||||
msg_payload = "<ctl ts='1547822804960' td='DustCaseST' st='0'/>"
|
||||
|
|
@ -36,7 +37,7 @@ async def test_helperbot_message(mqtt_client: MQTTClient):
|
|||
await mqtt_helperbot.disconnect()
|
||||
|
||||
# Send command to bot
|
||||
mqtt_helperbot = bumper.MQTTHelperBot(HOST, MQTT_PORT)
|
||||
mqtt_helperbot = MQTTHelperBot(HOST, MQTT_PORT)
|
||||
await mqtt_helperbot.start()
|
||||
assert mqtt_helperbot.is_connected
|
||||
msg_payload = "{}"
|
||||
|
|
@ -56,7 +57,7 @@ async def test_helperbot_message(mqtt_client: MQTTClient):
|
|||
await mqtt_helperbot.disconnect()
|
||||
|
||||
# Received response to command
|
||||
mqtt_helperbot = bumper.MQTTHelperBot(HOST, MQTT_PORT)
|
||||
mqtt_helperbot = MQTTHelperBot(HOST, MQTT_PORT)
|
||||
await mqtt_helperbot.start()
|
||||
assert mqtt_helperbot.is_connected
|
||||
msg_payload = '{"ret":"ok","ver":"0.13.5"}'
|
||||
|
|
@ -76,7 +77,7 @@ async def test_helperbot_message(mqtt_client: MQTTClient):
|
|||
await mqtt_helperbot.disconnect()
|
||||
|
||||
# Received unknown message
|
||||
mqtt_helperbot = bumper.MQTTHelperBot(HOST, MQTT_PORT)
|
||||
mqtt_helperbot = MQTTHelperBot(HOST, MQTT_PORT)
|
||||
await mqtt_helperbot.start()
|
||||
assert mqtt_helperbot.is_connected
|
||||
msg_payload = "test"
|
||||
|
|
@ -96,7 +97,7 @@ async def test_helperbot_message(mqtt_client: MQTTClient):
|
|||
await mqtt_helperbot.disconnect()
|
||||
|
||||
# Received error message
|
||||
mqtt_helperbot = bumper.MQTTHelperBot(HOST, MQTT_PORT)
|
||||
mqtt_helperbot = MQTTHelperBot(HOST, MQTT_PORT)
|
||||
await mqtt_helperbot.start()
|
||||
assert mqtt_helperbot.is_connected
|
||||
msg_payload = "<ctl ts='1560904925396' td='errors' old='' new='110'/>"
|
||||
|
|
@ -120,7 +121,7 @@ async def test_helperbot_message(mqtt_client: MQTTClient):
|
|||
async def test_helperbot_expire_message(mqtt_client: MQTTClient):
|
||||
timeout = 0.1
|
||||
# Test broadcast message
|
||||
mqtt_helperbot = bumper.MQTTHelperBot(HOST, MQTT_PORT, timeout)
|
||||
mqtt_helperbot = MQTTHelperBot(HOST, MQTT_PORT, timeout)
|
||||
bumper.mqtt_helperbot = mqtt_helperbot
|
||||
await mqtt_helperbot.start()
|
||||
assert mqtt_helperbot.is_connected
|
||||
|
|
@ -156,7 +157,7 @@ async def test_helperbot_expire_message(mqtt_client: MQTTClient):
|
|||
@pytest.mark.usefixtures("mqtt_server")
|
||||
async def test_helperbot_sendcommand(mqtt_client: MQTTClient):
|
||||
timeout = 0.1
|
||||
mqtt_helperbot = bumper.MQTTHelperBot(HOST, MQTT_PORT, timeout)
|
||||
mqtt_helperbot = MQTTHelperBot(HOST, MQTT_PORT, timeout)
|
||||
bumper.mqtt_helperbot = mqtt_helperbot
|
||||
await mqtt_helperbot.start()
|
||||
assert mqtt_helperbot.is_connected
|
||||
|
|
@ -293,9 +294,7 @@ async def test_mqttserver():
|
|||
if os.path.exists("tests/tmp.db"):
|
||||
os.remove("tests/tmp.db") # Remove existing db
|
||||
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
mqtt_server = bumper.MQTTServer(
|
||||
mqtt_server = MQTTServer(
|
||||
HOST, MQTT_PORT, password_file="tests/passwd", allow_anonymous=True
|
||||
)
|
||||
|
||||
|
|
@ -303,14 +302,14 @@ async def test_mqttserver():
|
|||
|
||||
try:
|
||||
# Test helperbot connect
|
||||
mqtt_helperbot = bumper.MQTTHelperBot(HOST, MQTT_PORT)
|
||||
mqtt_helperbot = MQTTHelperBot(HOST, MQTT_PORT)
|
||||
await mqtt_helperbot.start()
|
||||
assert mqtt_helperbot.is_connected
|
||||
await mqtt_helperbot.disconnect()
|
||||
|
||||
# Test client connect
|
||||
bumper.user_add("user_123") # Add user to db
|
||||
bumper.client_add("user_123", "ecouser.net", "resource_123") # Add client to db
|
||||
db.user_add("user_123") # Add user to db
|
||||
db.client_add("user_123", "ecouser.net", "resource_123") # Add client to db
|
||||
|
||||
client = MQTTClient(
|
||||
client_id="user_123@ecouser.net/resource_123",
|
||||
|
|
@ -319,7 +318,7 @@ async def test_mqttserver():
|
|||
|
||||
await client.connect(
|
||||
f"mqtts://{HOST}:{MQTT_PORT}/",
|
||||
cafile=bumper.ca_cert,
|
||||
cafile=ca_cert,
|
||||
)
|
||||
assert client._connected_state._value == True # Check client is connected
|
||||
await client.disconnect()
|
||||
|
|
@ -332,7 +331,7 @@ async def test_mqttserver():
|
|||
|
||||
await client.connect(
|
||||
f"mqtts://{HOST}:{MQTT_PORT}/",
|
||||
cafile=bumper.ca_cert,
|
||||
cafile=ca_cert,
|
||||
)
|
||||
assert client._connected_state._value == True # Check fake_bot is connected
|
||||
await client.disconnect()
|
||||
|
|
@ -350,7 +349,7 @@ async def test_mqttserver():
|
|||
# good user/pass
|
||||
await client.connect(
|
||||
f"mqtts://test-client:abc123!@{HOST}:{MQTT_PORT}/",
|
||||
cafile=bumper.ca_cert,
|
||||
cafile=ca_cert,
|
||||
cleansession=True,
|
||||
)
|
||||
|
||||
|
|
@ -363,7 +362,7 @@ async def test_mqttserver():
|
|||
|
||||
await client.connect(
|
||||
f"mqtts://test-client:notvalid!@{HOST}:{MQTT_PORT}/",
|
||||
cafile=bumper.ca_cert,
|
||||
cafile=ca_cert,
|
||||
cleansession=True,
|
||||
)
|
||||
|
||||
|
|
@ -380,7 +379,7 @@ async def test_mqttserver():
|
|||
# no username in file
|
||||
await client.connect(
|
||||
f"mqtts://test-client-noexist:notvalid!@{HOST}:{MQTT_PORT}/",
|
||||
cafile=bumper.ca_cert,
|
||||
cafile=ca_cert,
|
||||
cleansession=True,
|
||||
)
|
||||
|
||||
|
|
@ -399,9 +398,7 @@ async def test_mqttserver():
|
|||
async def test_nofileauth_mqttserver():
|
||||
with LogCapture() as l:
|
||||
|
||||
mqtt_server = bumper.MQTTServer(
|
||||
HOST, MQTT_PORT, password_file="tests/passwd-notfound"
|
||||
)
|
||||
mqtt_server = MQTTServer(HOST, MQTT_PORT, password_file="tests/passwd-notfound")
|
||||
await mqtt_server.start()
|
||||
await mqtt_server.shutdown()
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ from unittest import mock
|
|||
from testfixtures import LogCapture
|
||||
|
||||
import bumper
|
||||
from bumper import XMPPServer
|
||||
from bumper.xmppserver import XMPPAsyncClient
|
||||
|
||||
|
||||
def return_send_data(data):
|
||||
|
|
@ -16,7 +18,7 @@ def mock_transport_extra_info():
|
|||
|
||||
async def test_xmpp_server():
|
||||
xmpp_address = ("127.0.0.1", 5223)
|
||||
xmpp_server = bumper.XMPPServer(xmpp_address)
|
||||
xmpp_server = XMPPServer(xmpp_address)
|
||||
await xmpp_server.start_async_server()
|
||||
|
||||
with LogCapture("xmppserver") as l:
|
||||
|
|
@ -55,7 +57,7 @@ async def test_client_connect_no_starttls():
|
|||
test_transport = mock.Mock()
|
||||
test_transport.get_extra_info = mock.Mock(return_value=mock_transport_extra_info())
|
||||
test_transport.write = mock.Mock(return_value=return_send_data)
|
||||
xmppclient = bumper.xmppserver.XMPPAsyncClient(test_transport)
|
||||
xmppclient = XMPPAsyncClient(test_transport)
|
||||
xmppclient.state = xmppclient.CONNECT # Set client state to CONNECT
|
||||
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
|
||||
|
||||
|
|
@ -94,7 +96,7 @@ async def test_client_end_stream():
|
|||
test_transport = mock.Mock()
|
||||
test_transport.get_extra_info = mock.Mock(return_value=mock_transport_extra_info())
|
||||
test_transport.write = mock.Mock(return_value=return_send_data)
|
||||
xmppclient = bumper.xmppserver.XMPPAsyncClient(test_transport)
|
||||
xmppclient = XMPPAsyncClient(test_transport)
|
||||
xmppclient.state = xmppclient.CONNECT # Set client state to CONNECT
|
||||
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
|
||||
|
||||
|
|
@ -126,7 +128,7 @@ async def test_client_connect_starttls_called():
|
|||
test_transport = mock.Mock()
|
||||
test_transport.get_extra_info = mock.Mock(return_value=mock_transport_extra_info())
|
||||
test_transport.write = mock.Mock(return_value=return_send_data)
|
||||
xmppclient = bumper.xmppserver.XMPPAsyncClient(test_transport)
|
||||
xmppclient = XMPPAsyncClient(test_transport)
|
||||
xmppclient.state = xmppclient.CONNECT # Set client state to CONNECT
|
||||
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
|
||||
|
||||
|
|
@ -195,7 +197,7 @@ async def test_client_init():
|
|||
test_transport = mock.Mock()
|
||||
test_transport.get_extra_info = mock.Mock(return_value=mock_transport_extra_info())
|
||||
test_transport.write = mock.Mock(return_value=return_send_data)
|
||||
xmppclient = bumper.xmppserver.XMPPAsyncClient(test_transport)
|
||||
xmppclient = XMPPAsyncClient(test_transport)
|
||||
xmppclient.state = xmppclient.INIT # Set client state to INIT
|
||||
xmppclient.uid = "fuid_tmpuser"
|
||||
xmppclient.resource = "IOSF53D07BA"
|
||||
|
|
@ -263,7 +265,7 @@ async def test_bot_connect():
|
|||
test_transport = mock.Mock()
|
||||
test_transport.get_extra_info = mock.Mock(return_value=mock_transport_extra_info())
|
||||
test_transport.write = mock.Mock(return_value=return_send_data)
|
||||
xmppclient = bumper.xmppserver.XMPPAsyncClient(test_transport)
|
||||
xmppclient = XMPPAsyncClient(test_transport)
|
||||
xmppclient.state = xmppclient.CONNECT # Set client state to CONNECT
|
||||
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
|
||||
|
||||
|
|
@ -303,7 +305,7 @@ async def test_bot_init():
|
|||
test_transport = mock.Mock()
|
||||
test_transport.get_extra_info = mock.Mock(return_value=mock_transport_extra_info())
|
||||
test_transport.write = mock.Mock(return_value=return_send_data)
|
||||
xmppclient = bumper.xmppserver.XMPPAsyncClient(test_transport)
|
||||
xmppclient = XMPPAsyncClient(test_transport)
|
||||
xmppclient.state = xmppclient.INIT # Set client state to INIT
|
||||
xmppclient.uid = "E0000000000000001234"
|
||||
xmppclient.devclass = "159"
|
||||
|
|
@ -369,7 +371,7 @@ async def test_ping_server():
|
|||
test_transport = mock.Mock()
|
||||
test_transport.get_extra_info = mock.Mock(return_value=mock_transport_extra_info())
|
||||
test_transport.write = mock.Mock(return_value=return_send_data)
|
||||
xmppclient = bumper.xmppserver.XMPPAsyncClient(test_transport)
|
||||
xmppclient = XMPPAsyncClient(test_transport)
|
||||
xmppclient.state = xmppclient.READY # Set client state to READY
|
||||
xmppclient.uid = "E0000000000000001234"
|
||||
xmppclient.devclass = "159"
|
||||
|
|
@ -389,14 +391,14 @@ async def test_ping_client_to_client():
|
|||
test_transport = mock.Mock()
|
||||
test_transport.get_extra_info = mock.Mock(return_value=mock_transport_extra_info())
|
||||
test_transport.write = mock.Mock(return_value=return_send_data)
|
||||
xmppclient = bumper.xmppserver.XMPPAsyncClient(test_transport)
|
||||
xmppclient = XMPPAsyncClient(test_transport)
|
||||
xmppclient.state = xmppclient.READY # Set client state to READY
|
||||
xmppclient.uid = "E0000000000000001234"
|
||||
xmppclient.devclass = "159"
|
||||
xmppclient.bumper_jid = "E0000000000000001234@159.ecorobot.net/atom"
|
||||
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
|
||||
|
||||
xmppclient2 = bumper.xmppserver.XMPPAsyncClient(test_transport)
|
||||
xmppclient2 = XMPPAsyncClient(test_transport)
|
||||
xmppclient2.state = xmppclient.READY # Set client state to READY
|
||||
xmppclient2.uid = "fuid_tmpuser"
|
||||
xmppclient2.resource = "IOSF53D07BA"
|
||||
|
|
@ -429,7 +431,7 @@ async def test_client_send_iq():
|
|||
test_transport = mock.Mock()
|
||||
test_transport.get_extra_info = mock.Mock(return_value=mock_transport_extra_info())
|
||||
test_transport.write = mock.Mock(return_value=return_send_data)
|
||||
xmppclient = bumper.xmppserver.XMPPAsyncClient(test_transport)
|
||||
xmppclient = XMPPAsyncClient(test_transport)
|
||||
xmppclient.state = xmppclient.READY # Set client state to READY
|
||||
xmppclient.uid = "fuid_tmpuser"
|
||||
xmppclient.resource = "IOSF53D07BA"
|
||||
|
|
@ -438,7 +440,7 @@ async def test_client_send_iq():
|
|||
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
|
||||
bumper.xmppserver.XMPPServer.clients.append(xmppclient)
|
||||
|
||||
xmppclient2 = bumper.xmppserver.XMPPAsyncClient(test_transport)
|
||||
xmppclient2 = XMPPAsyncClient(test_transport)
|
||||
xmppclient2.state = xmppclient.READY # Set client state to READY
|
||||
xmppclient2.uid = "E0000000000000001234"
|
||||
xmppclient2.devclass = "159"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue