|
|
@@ -69,6 +69,8 @@ def make_attrs(*args): |
|
|
|
|
|
|
|
return r |
|
|
|
|
|
|
|
_httpxargs = dict(timeout=20) |
|
|
|
|
|
|
|
async def real_main(): |
|
|
|
baseurl = os.environ['BITELAB_URL'] |
|
|
|
authkey = os.environ['BITELAB_AUTH'] |
|
|
@@ -77,7 +79,8 @@ async def real_main(): |
|
|
|
|
|
|
|
try: |
|
|
|
if sys.argv[1] == 'list': |
|
|
|
res = await client.get('board/classes', auth=BiteAuth(authkey)) |
|
|
|
res = await client.get('board/classes', |
|
|
|
auth=BiteAuth(authkey), **_httpxargs) |
|
|
|
|
|
|
|
check_res_code(res) |
|
|
|
|
|
|
@@ -90,7 +93,7 @@ async def real_main(): |
|
|
|
res = await client.post('board/%s/%s' % |
|
|
|
(urllib.parse.quote(sys.argv[2], safe=''), |
|
|
|
sys.argv[1]), |
|
|
|
auth=BiteAuth(authkey)) |
|
|
|
auth=BiteAuth(authkey), **_httpxargs) |
|
|
|
|
|
|
|
check_res_code(res) |
|
|
|
|
|
|
@@ -104,7 +107,8 @@ async def real_main(): |
|
|
|
board_id = sys.argv[-1] |
|
|
|
res = await client.post('board/%s/attrs' % |
|
|
|
urllib.parse.quote(board_id, safe=''), |
|
|
|
auth=BiteAuth(authkey), json=make_attrs(*sys.argv[2:-1])) |
|
|
|
auth=BiteAuth(authkey), |
|
|
|
json=make_attrs(*sys.argv[2:-1]), **_httpxargs) |
|
|
|
|
|
|
|
check_res_code(res) |
|
|
|
|
|
|
@@ -170,7 +174,7 @@ class TestClient(unittest.TestCase): |
|
|
|
|
|
|
|
ac.assert_called_with(base_url='http://someserver/') |
|
|
|
|
|
|
|
acg.assert_called_with('board/classes', auth=BiteAuth('thisisanapikey')) |
|
|
|
acg.assert_called_with('board/classes', auth=BiteAuth('thisisanapikey'), **_httpxargs) |
|
|
|
|
|
|
|
# XXX - add error cases for UI |
|
|
|
|
|
|
@@ -193,7 +197,7 @@ class TestClient(unittest.TestCase): |
|
|
|
|
|
|
|
ac.assert_called_with(base_url='http://someserver/') |
|
|
|
|
|
|
|
acg.assert_called_with('board/classes', auth=BiteAuth('thisisanapikey')) |
|
|
|
acg.assert_called_with('board/classes', auth=BiteAuth('thisisanapikey'), **_httpxargs) |
|
|
|
|
|
|
|
# XXX - add error cases for UI |
|
|
|
|
|
|
@@ -223,7 +227,7 @@ Attributes: |
|
|
|
|
|
|
|
ac.assert_called_with(base_url='http://someserver/') |
|
|
|
|
|
|
|
acp.assert_called_with('board/cora-z7s/reserve', auth=BiteAuth('thisisanapikey')) |
|
|
|
acp.assert_called_with('board/cora-z7s/reserve', auth=BiteAuth('thisisanapikey'), **_httpxargs) |
|
|
|
|
|
|
|
@patch.dict(sys.__dict__, dict(argv=[ '', 'release', 'cora-z7s' ])) |
|
|
|
def test_release(self): |
|
|
@@ -249,7 +253,8 @@ Attributes: |
|
|
|
|
|
|
|
ac.assert_called_with(base_url='http://someserver/') |
|
|
|
|
|
|
|
acp.assert_called_with('board/cora-z7s/release', auth=BiteAuth('thisisanapikey')) |
|
|
|
acp.assert_called_with('board/cora-z7s/release', |
|
|
|
auth=BiteAuth('thisisanapikey'), **_httpxargs) |
|
|
|
|
|
|
|
@patch.dict(sys.__dict__, dict(argv=[ '', 'set', 'power=on', 'cora-z7s' ])) |
|
|
|
def test_set(self): |
|
|
@@ -278,7 +283,8 @@ Attributes: |
|
|
|
ac.assert_called_with(base_url='http://someserver/') |
|
|
|
|
|
|
|
acp.assert_called_with('board/cora-z7s/attrs', |
|
|
|
auth=BiteAuth('thisisanapikey'), json=dict(power=True)) |
|
|
|
auth=BiteAuth('thisisanapikey'), json=dict(power=True), |
|
|
|
**_httpxargs) |
|
|
|
|
|
|
|
def test_make_attrs(self): |
|
|
|
self.assertEqual(make_attrs('power=on'), dict(power=True)) |
|
|
@@ -289,3 +295,7 @@ Attributes: |
|
|
|
self.assertEqual(make_attrs('power=0'), dict(power=False)) |
|
|
|
|
|
|
|
self.assertRaises(ValueError, make_attrs, 'power=bar') |
|
|
|
|
|
|
|
def test_check_res_code(self): |
|
|
|
# XXX - on weird errors, res.json() will fail w/ json.decoder.JSONDecodeError |
|
|
|
pass |