Exemplo n.º 1
0
    def test_device_status_success_response(self):
        responses.add(
            responses.GET,
            TEST_SUPERVISOR_DEVICE_STATUS_URL,
            status=200,
            json={'appState': 'applied'}
        )

        bs = BalenaSupervisor(TEST_SUPERVISOR_ADDRESS, TEST_SUPERVISOR_API_KEY)
        assert bs.get_device_status('appState') == 'applied'
Exemplo n.º 2
0
    def test_shutdown_gateway_success_response(self):
        responses.add(
            responses.POST,
            TEST_SUPERVISOR_SHUTDOWN_URL,
            status=200,
            json={"Data": "OK", "Error": ""}
        )

        bs = BalenaSupervisor(TEST_SUPERVISOR_ADDRESS, TEST_SUPERVISOR_API_KEY)
        resp = bs.shutdown()

        assert resp['Data'] == 'OK'
Exemplo n.º 3
0
    def test_device_status_error_on_connection_timeout(self):
        responses.add(
            responses.GET,
            TEST_SUPERVISOR_DEVICE_STATUS_URL,
            body=ConnectTimeout('Timout trying to make connection')
        )

        bs = BalenaSupervisor(TEST_SUPERVISOR_ADDRESS, TEST_SUPERVISOR_API_KEY)

        with self.assertRaises(RuntimeError) as exp:
            bs.get_device_status('appState')

        assert str(exp.exception).startswith("Device status request failed")
Exemplo n.º 4
0
    def test_shutdown_gateway_error_on_connection_timeout(self):
        responses.add(
            responses.POST,
            TEST_SUPERVISOR_SHUTDOWN_URL,
            body=ConnectTimeout('Timout trying to make connection')
        )

        bs = BalenaSupervisor(TEST_SUPERVISOR_ADDRESS, TEST_SUPERVISOR_API_KEY)

        with self.assertRaises(Exception) as exp:
            bs.shutdown()

        assert str(exp.exception) == 'supervisor API not accessible'
Exemplo n.º 5
0
    def test_shutdown_gateway_error_on_connection_error(self):
        responses.add(
            responses.POST,
            TEST_SUPERVISOR_SHUTDOWN_URL,
            body=ConnectionError('Unable to connect')
        )

        bs = BalenaSupervisor(TEST_SUPERVISOR_ADDRESS, TEST_SUPERVISOR_API_KEY)

        with self.assertRaises(Exception) as exp:
            bs.shutdown()

        assert str(exp.exception) == "supervisor API not accessible"
Exemplo n.º 6
0
    def test_device_status_empty_response(self):
        responses.add(
            responses.GET,
            TEST_SUPERVISOR_DEVICE_STATUS_URL,
            body='',
            status=200
        )

        bs = BalenaSupervisor(TEST_SUPERVISOR_ADDRESS, TEST_SUPERVISOR_API_KEY)

        with self.assertRaises(RuntimeError) as exp:
            bs.get_device_status('appState')

        assert str(exp.exception).startswith("Supervisor API did not return valid json response")
Exemplo n.º 7
0
    def test_shutdown_gateway_empty_response(self):
        responses.add(
            responses.POST,
            TEST_SUPERVISOR_SHUTDOWN_URL,
            body='',
            status=200
        )

        bs = BalenaSupervisor(TEST_SUPERVISOR_ADDRESS, TEST_SUPERVISOR_API_KEY)

        with self.assertRaises(Exception) as exp:
            bs.shutdown()

        assert str(exp.exception) == 'shutdown failed due to supervisor API issue'
Exemplo n.º 8
0
    def test_creation(self):
        bs = BalenaSupervisor(TEST_SUPERVISOR_ADDRESS, TEST_SUPERVISOR_API_KEY)

        assert bs.supervisor_address == TEST_SUPERVISOR_ADDRESS
        assert bs.supervisor_api_key == TEST_SUPERVISOR_API_KEY
        assert bs.headers == {'Content-type': 'application/json'}