forked from wpietri/sucks
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import tempfile | ||
from unittest.mock import Mock, patch | ||
|
||
import requests_mock | ||
from nose.tools import * | ||
|
||
from sucks.cli import * | ||
|
@@ -16,12 +15,14 @@ def test_config_file_name(): | |
|
||
|
||
def test_write_and_read_config(): | ||
with patch('sucks.cli.config_file', Mock(return_value=os.path.join(tempfile.mkdtemp(), 'some_other_dir', 'sucks.conf'))): | ||
with patch('sucks.cli.config_file', | ||
Mock(return_value=os.path.join(tempfile.mkdtemp(), 'some_other_dir', 'sucks.conf'))): | ||
write_config({'a': "ayyy", 'b': 2}) | ||
config2 = read_config() | ||
assert_equals(config2['a'], 'ayyy') | ||
assert_equals(config2['b'], '2') | ||
|
||
|
||
def test_frequency_param_type(): | ||
t = FREQUENCY | ||
assert_equals(t.convert('0', None, None), 0) | ||
|
@@ -59,44 +60,3 @@ def test_should_run(): | |
def test_continent_for_country(): | ||
assert_equal(continent_for_country('us'), 'na') | ||
assert_equal(continent_for_country('fr'), 'eu') | ||
|
||
|
||
|
||
def test_main_api_setup(): | ||
with requests_mock.mock() as m: | ||
r1 = m.get(re.compile('user/login'), | ||
text='{"time": 1511200804243, "data": {"accessToken": "7a375650b0b1efd780029284479c4e41", "uid": "2017102559f0ee63c588d", "username": null, "email": "[email protected]", "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"}') | ||
EcoVacsAPI("long_device_id", "account_id", "password_hash", 'us', 'na') | ||
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 = 'E0000001234567890123' | ||
|
||
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) | ||
vacuum = d[0] | ||
assert_equals(vacuum['did'], device_id) | ||
assert_equals(vacuum['class'], '126') | ||
|
||
|
||
def make_api(): | ||
with requests_mock.mock() as m: | ||
m.get(re.compile('user/login'), | ||
text='{"time": 1511200804243, "data": {"accessToken": "0123456789abcdef0123456789abcdef", "uid": "20170101abcdefabcdefa", "username": null, "email": "[email protected]", "country": "us"}, "code": "0000", "msg": "X"}') | ||
m.get(re.compile('user/getAuthCode'), | ||
text='{"time": 1511200804607, "data": {"authCode": "abcdef01234567890abcdef012345678"}, "code": "0000", "msg": "X"}') | ||
m.post(re.compile('user.do'), | ||
text='{"todo": "result", "token": "base64base64base64base64base64ba", "result": "ok", "userId": "20170101abcdefabcdefa", "resource": "abcdef12"}') | ||
return EcoVacsAPI("long_device_id", "account_id", "password_hash", 'us', 'na') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.