Exemplo n.º 1
0
    def test_check_client_not_found(self):
        clients_manager = ClientsManager({'test': ClientCollectionTest.TestClient()})
        clients_manager.check_connection = MagicMock(side_effect=KeyError)

        client = ClientCheck(clients_manager)
        client.__no_auth__ = True
        self.api.add_route('/api/clients/{client}/check', client)

        self.simulate_request('/api/clients/{0}/check'.format('tracker.org'))
        self.assertEqual(self.srmock.status, falcon.HTTP_NOT_FOUND)
Exemplo n.º 2
0
    def test_check_client_error(self):
        clients_manager = ClientsManager({'test': ClientCollectionTest.TestClient()})
        clients_manager.check_connection = MagicMock(side_effect=Exception)

        client = ClientCheck(clients_manager)
        client.__no_auth__ = True
        self.api.add_route('/api/clients/{client}/check', client)

        self.simulate_request('/api/clients/{0}/check'.format('tracker.org'))
        self.assertEqual(self.srmock.status, falcon.HTTP_INTERNAL_SERVER_ERROR)
Exemplo n.º 3
0
    def test_check_client(self, value):
        clients_manager = ClientsManager({'test': ClientCollectionTest.TestClient()})
        clients_manager.check_connection = MagicMock(return_value=value)

        client = ClientCheck(clients_manager)
        client.__no_auth__ = True
        self.api.add_route('/api/clients/{client}/check', client)

        body = self.simulate_request('/api/clients/{0}/check'.format('tracker.org'), decode="utf-8")
        self.assertEqual(self.srmock.status, falcon.HTTP_OK)
        self.assertTrue('application/json' in self.srmock.headers_dict['Content-Type'])

        result = json.loads(body)

        self.assertIsInstance(result, dict)
        self.assertEqual(result, {'status': value})