Exemplo n.º 1
0
    def test_api_key_http_ok(self):
        """ Verifies that test_api_key does not raise an error when HTTP OK
        is returned from the server.
        """
        client = Client(api_key='some-api-key')

        response = MockResponse(HTTPStatus.OK)
        with patch.object(client._session, 'get', return_value=response):
            client.test_api_key()
Exemplo n.º 2
0
    def test_api_key_http_unauthorized(self):
        """ Verifies that test_api_key raises UnauthorizedError when HTTP
        Unauthorized is returned from the server.
        """
        client = Client(api_key='some-api-key')

        response = MockResponse(HTTPStatus.UNAUTHORIZED)
        with patch.object(client._session, 'get', return_value=response):
            with self.assertRaises(UnauthorizedError):
                client.test_api_key()
Exemplo n.º 3
0
    def test_produktionsenhed_success(self):
        """ Verifies that the client returns a list of Produktionsenheder and
        deserializes them when HTTP status code 200 is returned.
        """
        client = Client(api_key='some-api-key')

        expected = [
            {
                "pNummer": 1234
            },
            {
                "pNummer": 2345
            },
            {
                "pNummer": 3456
            },
        ]

        response = MockResponse(
            status_code=HTTPStatus.OK,
            content=expected,
        )
        with patch.object(client._session, 'get', return_value=response):
            produktionsenheder = client.cvr.produktionsenheder(
                adresse="some adresse")
            self.assertEqual(len(expected), len(produktionsenheder))
            for i, penhed in enumerate(expected):
                self.assertEqual(penhed["pNummer"],
                                 produktionsenheder[i].p_nummer)
Exemplo n.º 4
0
 def test_api_key_invalid_api_key(self):
     """
     Verifies that test_api_key raises an error using an invalid api key.
     """
     with Client(api_key="invalid api key") as client:
         with self.assertRaises(UnauthorizedError):
             client.test_api_key()
Exemplo n.º 5
0
 def test_cvr_numre_exists_and_not_exists(self):
     """ Verifies that no virksomhed is returned when both existing and non-existing
     cvr_numre are given.
     """
     with Client(api_key=get_api_key()) as client:
         virksomheder = client.cvr.virksomheder(cvr_numre=[10103940, 1337])
         self.assertEqual(0, len(virksomheder))
Exemplo n.º 6
0
 def test_navn_and_cvr_numre(self):
     """ Verifies that InvalidRequestError is raised when both navn and
     cvr_numre is given.
     """
     with Client(api_key=get_api_key()) as client:
         with self.assertRaises(InvalidRequestError):
             client.cvr.virksomheder(navn="navn", cvr_numre=[1234])
Exemplo n.º 7
0
 def test_navn_exists(self):
     """ Verifies that at least one virksomhed is returned when given a navn
     that exists.
     """
     with Client(api_key=get_api_key()) as client:
         virksomheder = client.cvr.virksomheder(navn="statsministeriet")
         self.assertTrue(len(virksomheder) > 0)
Exemplo n.º 8
0
 def test_p_nummer_exists_and_not_exists(self):
     """ Verifies that an empty list is returned if one of the given p numre do not exist.
     """
     with Client(api_key=get_api_key()) as client:
         produktionsenheder = client.cvr.produktionsenheder(
             p_numre=[1004862579, 1337])
         self.assertEqual(0, len(produktionsenheder))
Exemplo n.º 9
0
 def test_adresse_not_exists(self):
     """ Verifies that no produktionsenheder are returned when given an address that has
     no produktionsenheder.
     """
     with Client(api_key=get_api_key()) as client:
         produktionsenheder = client.cvr.produktionsenheder(
             adresse="aklsdajhk1kj81342")
         self.assertEqual(0, len(produktionsenheder))
Exemplo n.º 10
0
 def test_navn_not_exists(self):
     """ Verifies that no virksomhed is returned when given a navn that does
     not exist.
     """
     with Client(api_key=get_api_key()) as client:
         virksomheder = client.cvr.virksomheder(
             navn="kfgnkjdfgkjdgkdfhgkdjhgkdjgkjdfhgkjdfkdfngkdfjn")
         self.assertEqual(0, len(virksomheder))
Exemplo n.º 11
0
 def test_both_p_numre_and_adresse_given(self):
     """ Verifies that InvalidRequestError is raised if both adresse and p_numre
     args are given.
     """
     with Client(api_key=get_api_key()) as client:
         with self.assertRaises(InvalidRequestError):
             client.cvr.produktionsenheder(adresse="adresse",
                                           p_numre=[1234])
Exemplo n.º 12
0
 def test_adresse_exists(self):
     """ Verifies that at least one produktionsenhed is returned when given an address
     that has produktionsenheder.
     """
     with Client(api_key=get_api_key()) as client:
         produktionsenheder = client.cvr.produktionsenheder(
             adresse="Prins Jørgens Gård 11")
         self.assertTrue(len(produktionsenheder) > 1)
Exemplo n.º 13
0
 def test_cvr_nummer_exists(self):
     """ Verifies that a single virksomhed is returned when a single cvr_nummer is given.
     """
     cvr_nummer = 10103940
     with Client(api_key=get_api_key()) as client:
         virksomheder = client.cvr.virksomheder(cvr_numre=[cvr_nummer])
         self.assertEqual(1, len(virksomheder))
         self.assertEqual(cvr_nummer, virksomheder[0].cvr_nummer)
Exemplo n.º 14
0
 def test_p_nummer_exists(self):
     """ Verifies that a single produktionsenhed is returned when a single p_nummer is given.
     """
     p_nummer = 1004862579
     with Client(api_key=get_api_key()) as client:
         produktionsenheder = client.cvr.produktionsenheder(
             p_numre=[p_nummer])
         self.assertEqual(1, len(produktionsenheder))
         self.assertEqual(p_nummer, produktionsenheder[0].p_nummer)
Exemplo n.º 15
0
 def test_multiple_cvr_numre_exists(self):
     """ Verifies that multiple virksomheder are returned when multiple cvr_numre are given
     """
     cvr_numre = {10103940, 10150817, 10213231}
     with Client(api_key=get_api_key()) as client:
         virksomheder = client.cvr.virksomheder(cvr_numre=cvr_numre)
         self.assertEqual(3, len(virksomheder))
         for virksomhed in virksomheder:
             self.assertTrue(virksomhed.cvr_nummer in cvr_numre)
Exemplo n.º 16
0
 def test_multiple_p_numre_exists(self):
     """ Verifies that multiple produktionsenheder are returned when multiple p_numre are given
     """
     p_numre = [1004862579, 1003388394, 1020852379]
     with Client(api_key=get_api_key()) as client:
         produktionsenheder = client.cvr.produktionsenheder(p_numre=p_numre)
         self.assertEqual(3, len(produktionsenheder))
         for produktionsenhed in produktionsenheder:
             self.assertTrue(produktionsenhed.p_nummer in p_numre)
Exemplo n.º 17
0
    def test_unauthorized(self):
        """ Verifies that UnauthorizedError is raised when the client receives
        HTTP status code 401.
        """
        client = Client(api_key='some-api-key')

        response = MockResponse(HTTPStatus.UNAUTHORIZED)
        with patch.object(client._session, 'get', return_value=response):
            with self.assertRaises(UnauthorizedError):
                client.cvr.produktionsenheder(adresse="adresse")
Exemplo n.º 18
0
    def test_server_error(self):
        """ Verifies that InternalServerError is raised when the client receives
        HTTP status code 500.
        """
        client = Client(api_key='some-api-key')

        response = MockResponse(HTTPStatus.INTERNAL_SERVER_ERROR)
        with patch.object(client._session, 'get', return_value=response):
            with self.assertRaises(InternalServerError):
                client.cvr.produktionsenheder(adresse="adresse")
Exemplo n.º 19
0
    def test_produktionsenhed_not_found(self):
        """ Verifies that the client returns an empty list when HTTP status code
        404 is received.
        """
        client = Client(api_key='some-api-key')

        response = MockResponse(HTTPStatus.NOT_FOUND)
        with patch.object(client._session, 'get', return_value=response):
            produktionsenheder = client.cvr.produktionsenheder(
                adresse="some adresse")
            self.assertEqual(0, len(produktionsenheder))
Exemplo n.º 20
0
 def test_api_key_valid_api_key(self):
     """ Verifies that test_api_key succeeds with a valid api key. """
     with Client(api_key=get_api_key()) as client:
         client.test_api_key()
Exemplo n.º 21
0
 def test_regression_virksomhed_with_regnummer(self):
     """ Regression: verifies that a virksomhed with the regnummer field is parsed correctly.
     """
     with Client(api_key=get_api_key()) as client:
         virksomheder = client.cvr.virksomheder(navn="aldi")
Exemplo n.º 22
0
 def test_cvr_nummer_not_exists(self):
     """ Verifies that a no virksomhed is returned when a non-existing cvr_nummer is given.
     """
     with Client(api_key=get_api_key()) as client:
         virksomheder = client.cvr.virksomheder(cvr_numre=[1337])
         self.assertEqual(0, len(virksomheder))