Beispiel #1
0
    def test_should_handle_request_failures(self, mock_request):
        client = DefaultClientApi(api_url=self.url,
                                  api_token=self.token,
                                  context=DefaultHttpsContext(verify=False))
        mock_request.return_value = MockResponse.failure(
            response='test failure')

        with self.assertRaises(Abort):
            client.operations()
Beispiel #2
0
    def test_should_handle_init_state_retrieval_failures(self, mock_request):
        client = DefaultInitApi(api_url=self.url,
                                connect_retries=1,
                                backoff_factor=2,
                                context=DefaultHttpsContext(verify=False))
        mock_request.return_value = MockResponse.failure(
            response='test failure')

        with self.assertRaises(Abort):
            client.state()
Beispiel #3
0
    def test_should_handle_failures_when_providing_init_credentials(
            self, mock_request):
        client = DefaultInitApi(api_url=self.url,
                                connect_retries=1,
                                backoff_factor=2,
                                context=DefaultHttpsContext(verify=False))
        mock_request.return_value = MockResponse.failure(
            response='test failure')

        username = '******'
        password = '******'

        with self.assertRaises(Abort):
            client.provide_credentials(username=username, password=password)
Beispiel #4
0
    def test_should_check_if_api_is_active(self, mock_request):
        client = DefaultClientApi(api_url=self.url,
                                  api_token=self.token,
                                  context=DefaultHttpsContext(verify=False))
        mock_request.return_value = MockResponse.success(mock_data.PING)

        self.assertTrue(client.is_active())

        self.assert_valid_request(mock=mock_request,
                                  expected_method='get',
                                  expected_url='/service/ping')

        mock_request.return_value = MockResponse.failure()

        self.assertFalse(client.is_active())
Beispiel #5
0
    def test_should_send_service_termination_requests(self, mock_request):
        client = DefaultClientApi(api_url=self.url,
                                  api_token=self.token,
                                  context=DefaultHttpsContext(verify=False))
        mock_request.return_value = MockResponse.success()

        self.assertDictEqual(client.stop(), {
            'successful': True,
            'operation': None
        })

        self.assert_valid_request(mock=mock_request,
                                  expected_method='put',
                                  expected_url='/service/stop')

        mock_request.return_value = MockResponse.failure()

        self.assertDictEqual(client.stop(), {'successful': False})