def test_cli_stream_updatefail(): responses.add(responses.POST, 'https://user-field.aylanetworks.com/users/sign_in.json', json=LOGIN_PAYLOAD, status=200) responses.add(responses.GET, 'https://ads-field.aylanetworks.com/apiv1/devices.json', json=DEVICES_PAYLOAD, status=200) responses.add(responses.GET, 'https://ads-field.aylanetworks.com/apiv1/dsns/c/properties', json=DEVICE_ATTRIBUTES, status=200) responses.add( responses.POST, 'https://ads-field.aylanetworks.com/apiv1/properties/42738119/datapoints', status=201) responses.add(responses.GET, 'https://ads-field.aylanetworks.com/apiv1/dsns/c/properties', json=DEVICE_ATTRIBUTES, status=400) with patch( 'sys.argv', ['cli.py', '*****@*****.**', 'moped', '--timeout', '10', 'stream']): cli()
def test_cli_stream_ctrlc(sleep_mock): sleep_mock.side_effect = SystemExit responses.add(responses.POST, 'https://user-field.aylanetworks.com/users/sign_in.json', json=LOGIN_PAYLOAD, status=200) responses.add(responses.GET, 'https://ads-field.aylanetworks.com/apiv1/devices.json', json=DEVICES_PAYLOAD, status=200) responses.add(responses.GET, 'https://ads-field.aylanetworks.com/apiv1/dsns/c/properties', json=DEVICE_ATTRIBUTES, status=200) responses.add( responses.POST, 'https://ads-field.aylanetworks.com/apiv1/properties/42738119/datapoints', status=201) with patch( 'sys.argv', ['cli.py', '*****@*****.**', 'moped', '--timeout', '10', 'stream']): with pytest.raises(SystemExit): cli()
def test_cli_server_down(): with patch('sys.argv', ['cli.py', '*****@*****.**', 'moped', 'token']): with pytest.raises(SystemExit) as info: cli() # Ensure exit code is 1 == error assert '1' == str(info.value)
def test_cli_token(): responses.add(responses.POST, 'https://user-field.aylanetworks.com/users/sign_in.json', json=LOGIN_PAYLOAD, status=200) with patch('sys.argv', ['cli.py', '*****@*****.**', 'moped', 'token']): cli()
def test_cli_devices_ok(): responses.add(responses.POST, 'https://user-field.aylanetworks.com/users/sign_in.json', json=LOGIN_PAYLOAD, status=200) responses.add(responses.GET, 'https://ads-field.aylanetworks.com/apiv1/devices.json', json=DEVICES_PAYLOAD, status=200) with patch('sys.argv', ['cli.py', '*****@*****.**', 'moped', 'devices']): cli()
def test_cli_login_fail(): responses.add(responses.POST, 'https://user-field.aylanetworks.com/users/sign_in.json', json=LOGIN_PAYLOAD, status=401) with patch('sys.argv', ['cli.py', '*****@*****.**', 'moped', 'token']): with pytest.raises(SystemExit) as info: cli() # Ensure exit code is 1 == error assert '1' == str(info.value)
def test_cli_download_ok(): responses.add(responses.POST, 'https://user-field.aylanetworks.com/users/sign_in.json', json=LOGIN_PAYLOAD, status=200) responses.add(responses.GET, 'https://ads-field.aylanetworks.com/apiv1/devices.json', json=DEVICES_PAYLOAD, status=200) responses.add(responses.GET, 'https://ads-field.aylanetworks.com/apiv1/dsns/c/properties', json=DEVICE_ATTRIBUTES, status=200) responses.add(responses.GET, 'http://de.mo/file', json=DOWNLOAD_DATA, status=200) responses.add( responses.GET, 'https://ayla-device-field-production-1a2039d9.s3.amazonaws.com/X?AWSAccessKeyId=Y&Expires=1234&Signature=Z', status=200) with patch('sys.argv', ['cli.py', '*****@*****.**', 'moped', 'download']): cli()