Adding some unit tests for the HTTP Ecovacs API.
This commit is contained in:
@@ -13,6 +13,7 @@ python_version = '3'
|
||||
[dev-packages]
|
||||
|
||||
nose = "*"
|
||||
requests-mock = ">=1.3"
|
||||
|
||||
|
||||
[packages]
|
||||
@@ -20,4 +21,4 @@ nose = "*"
|
||||
sleekxmpp = ">=1.3"
|
||||
click = ">=6"
|
||||
requests = ">=2.18"
|
||||
pycryptodome = ">=3.4"
|
||||
pycryptodome = ">=3.4"
|
||||
@@ -1,5 +1,6 @@
|
||||
from xml.etree import ElementTree
|
||||
|
||||
import requests_mock
|
||||
from nose.tools import *
|
||||
|
||||
from sucks import *
|
||||
@@ -72,3 +73,41 @@ def test_should_run():
|
||||
if should_run(0.9):
|
||||
count += 1
|
||||
assert_almost_equal(count, 9000, delta=200)
|
||||
|
||||
|
||||
def test_main_api_called():
|
||||
with requests_mock.mock() as m:
|
||||
r1 = m.get(re.compile('user/login'),
|
||||
text='{"time": 1511200804243, "data": {"accessToken": "7a375650b0b1efd780029284479c4e41", "uid": "2017102559f0ee63c588d", "username": null, "email": "william-ecovacs@pota.to", "country": "us"}, "code": "0000", "msg": "X"}')
|
||||
r2 = m.get(re.compile('user/getAuthCode'),
|
||||
text='{"time": 1511200804607, "data": {"authCode": "5c28dac1ff580210e11292df57e87bef"}, "code": "0000", "msg": "X"}')
|
||||
r3 = m.post(re.compile('user.do'),
|
||||
text='{"todo": "result", "token": "jt5O7oDR3gPHdVKCeb8Czx8xw8mDXM6s", "result": "ok", "userId": "2017102559f0ee63c588d", "resource": "f8d99c4d"}')
|
||||
api = EcoVacsAPI("long_device_id", "account_id", "password_hash")
|
||||
assert_equals(r1.call_count, 1)
|
||||
assert_equals(r2.call_count, 1)
|
||||
assert_equals(r3.call_count, 1)
|
||||
|
||||
|
||||
def test_device_lookup():
|
||||
api = make_api()
|
||||
with requests_mock.mock() as m:
|
||||
device_id = 'E0000693817603910264'
|
||||
|
||||
r = m.post(re.compile('user.do'),
|
||||
text='{"todo": "result", "devices": [{"did": "%s", "class": "126", "nick": "bob"}], "result": "ok"}' % device_id)
|
||||
d = api.devices()
|
||||
assert_equals(r.call_count, 1)
|
||||
assert_equals(len(d), 1)
|
||||
assert_equals(d[0]['did'], device_id)
|
||||
|
||||
|
||||
def make_api():
|
||||
with requests_mock.mock() as m:
|
||||
m.get(re.compile('user/login'),
|
||||
text='{"time": 1511200804243, "data": {"accessToken": "7a375650b0b1efd780029284479c4e41", "uid": "2017102559f0ee63c588d", "username": null, "email": "william-ecovacs@pota.to", "country": "us"}, "code": "0000", "msg": "X"}')
|
||||
m.get(re.compile('user/getAuthCode'),
|
||||
text='{"time": 1511200804607, "data": {"authCode": "5c28dac1ff580210e11292df57e87bef"}, "code": "0000", "msg": "X"}')
|
||||
m.post(re.compile('user.do'),
|
||||
text='{"todo": "result", "token": "jt5O7oDR3gPHdVKCeb8Czx8xw8mDXM6s", "result": "ok", "userId": "2017102559f0ee63c588d", "resource": "f8d99c4d"}')
|
||||
return EcoVacsAPI("long_device_id", "account_id", "password_hash")
|
||||
|
||||
Reference in New Issue
Block a user