Merge pull request #20 from wpietri/basic-windows-support-#5
Support config files on Windows.
This commit is contained in:
+7
-2
@@ -1,6 +1,7 @@
|
||||
import configparser
|
||||
import itertools
|
||||
import os
|
||||
import platform
|
||||
import random
|
||||
import re
|
||||
|
||||
@@ -39,7 +40,10 @@ FREQUENCY = FrequencyParamType()
|
||||
|
||||
|
||||
def config_file():
|
||||
return os.path.expanduser('~/.config/sucks.conf')
|
||||
if platform.system() == 'Windows':
|
||||
return os.path.join(os.getenv('APPDATA'), 'sucks.conf')
|
||||
else:
|
||||
return os.path.expanduser('~/.config/sucks.conf')
|
||||
|
||||
|
||||
def config_file_exists():
|
||||
@@ -54,9 +58,10 @@ def read_config():
|
||||
|
||||
|
||||
def write_config(config):
|
||||
os.makedirs(os.path.dirname(config_file()), exist_ok=True)
|
||||
with open(config_file(), 'w') as fp:
|
||||
for key in config:
|
||||
fp.write(key + '=' + config[key] + "\n")
|
||||
fp.write(key + '=' + str(config[key]) + "\n")
|
||||
|
||||
|
||||
def current_country():
|
||||
|
||||
@@ -1,9 +1,27 @@
|
||||
import tempfile
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import requests_mock
|
||||
from nose.tools import *
|
||||
|
||||
from sucks.cli import *
|
||||
|
||||
|
||||
def test_config_file_name():
|
||||
if platform.system() == 'Windows':
|
||||
print(config_file())
|
||||
assert_true(re.match(r'[A-Z]:\\.+\\\w+\\AppData(\\Roaming)?\\sucks.conf', config_file()))
|
||||
else:
|
||||
assert_true(re.match(r'/.+/\w+/.config/sucks.conf', config_file()))
|
||||
|
||||
|
||||
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'))):
|
||||
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)
|
||||
|
||||
@@ -1,18 +1,26 @@
|
||||
from re import compile
|
||||
|
||||
import requests_mock
|
||||
from nose.tools import *
|
||||
|
||||
import re
|
||||
|
||||
from sucks import *
|
||||
|
||||
|
||||
def test_md5():
|
||||
assert_equal(EcoVacsAPI.md5("fnord"), "b15e400c8dbd6697f26385216d32a40f")
|
||||
|
||||
|
||||
def test_encrypt():
|
||||
assert_equal(len(EcoVacsAPI.encrypt("fnord")), 172)
|
||||
|
||||
|
||||
def test_main_api_setup():
|
||||
with requests_mock.mock() as m:
|
||||
r1 = m.get(re.compile('user/login'),
|
||||
r1 = m.get(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'),
|
||||
r2 = m.get(compile('user/getAuthCode'),
|
||||
text='{"time": 1511200804607, "data": {"authCode": "5c28dac1ff580210e11292df57e87bef"}, "code": "0000", "msg": "X"}')
|
||||
r3 = m.post(re.compile('user.do'),
|
||||
r3 = m.post(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)
|
||||
@@ -25,7 +33,7 @@ def test_device_lookup():
|
||||
with requests_mock.mock() as m:
|
||||
device_id = 'E0000001234567890123'
|
||||
|
||||
r = m.post(re.compile('user.do'),
|
||||
r = m.post(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)
|
||||
@@ -37,10 +45,10 @@ def test_device_lookup():
|
||||
|
||||
def make_api():
|
||||
with requests_mock.mock() as m:
|
||||
m.get(re.compile('user/login'),
|
||||
m.get(compile('user/login'),
|
||||
text='{"time": 1511200804243, "data": {"accessToken": "0123456789abcdef0123456789abcdef", "uid": "20170101abcdefabcdefa", "username": null, "email": "username@example.com", "country": "us"}, "code": "0000", "msg": "X"}')
|
||||
m.get(re.compile('user/getAuthCode'),
|
||||
m.get(compile('user/getAuthCode'),
|
||||
text='{"time": 1511200804607, "data": {"authCode": "abcdef01234567890abcdef012345678"}, "code": "0000", "msg": "X"}')
|
||||
m.post(re.compile('user.do'),
|
||||
m.post(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')
|
||||
|
||||
Reference in New Issue
Block a user