Exemplo n.º 1
0
 def test_geocode_raises_error_if_afrigis_key_missing(self):
     """
     Type error should be thrown if afrigis key is not passed
     """
     with self.assertRaises(
             TypeError,
             msg='geocode() should fail if `afrigis_key` is not passed'):
         geocode(
             afrigis_secret='stub',
             address_id='stub',
         )
Exemplo n.º 2
0
 def test_geocode_raises_error_if_afrigis_secret_is_empty(self):
     """
     geocode() should fail if `afrigis_secret` is empty
     """
     with self.assertRaises(
             ValueError,
             msg='geocode() should fail if `afrigis_secret is empty`'):
         geocode(
             afrigis_key='stub',
             afrigis_secret='',
             address_id='stub',
         )
Exemplo n.º 3
0
 def test_geocode_raises_error_if_afrigis_secret_is_nonetype(self):
     """
     geocode() should fail if `afrigis_secret` is nonetype
     """
     with self.assertRaises(
             ValueError,
             msg='geocode() should fail if `afrigis_secret` is None'):
         geocode(
             afrigis_key='stub',
             afrigis_secret=None,
             address_id='stub',
         )
Exemplo n.º 4
0
 def test_geocode_raises_error_if_afrigis_key_is_non_string_edge_1(self):
     """
     geocode() should fail if `afrigis_key` is <NoneType>
     """
     with self.assertRaises(
             ValueError,
             msg='geocode() should fail if `afrigis_key` is non-string'):
         geocode(
             afrigis_key=dict(foo='bar'),
             afrigis_secret='stub',
             address_id='stub',
         )
Exemplo n.º 5
0
 def test_geocode_raises_error_if_address_id_is_non_string_edge_0(self):
     """
     geocode() should fail if `address_id` is non-string
     """
     with self.assertRaises(
             ValueError,
             msg='geocode() should fail if `address_id` is non-string'):
         geocode(
             afrigis_key='stub',
             afrigis_secret='stub',
             address_id=123,
         )
Exemplo n.º 6
0
    def test_geocode_raises_authentication_exception_if_call_fails_with_401(
            self, urlopen_mock):
        mock = Mock()
        mock.read.side_effect = lambda: afrigis_geocode_unauthenticated_mock
        mock.getcode.side_effect = lambda: 200
        urlopen_mock.return_value = mock

        from afrigis.exceptions import AuthenticationFailedException

        with self.assertRaises(AuthenticationFailedException):
            geocode(
                afrigis_key='fake-key',
                afrigis_secret='fake-secret',
                address_id='some-fake-id',
            )
Exemplo n.º 7
0
    def test_geocode_returns_correct_json_response_if_afrigis_call_successful(
            self, urlopen_mock):
        mock = Mock()
        mock.read.side_effect = lambda: afrigis_geocode_success_mock
        mock.getcode.side_effect = lambda: 200
        urlopen_mock.return_value = mock

        res = geocode(
            afrigis_key='fake-key',
            afrigis_secret='fake-secret',
            address_id='some-fake-id',
        )

        self.assertIsInstance(res, dict)

        self.assertIsInstance(res.get('result'), list)