예제 #1
0
    def test_get_auth_headers(self, mock_authenticate, mock_cache, mock_update_auth_headers):
        mock_cache.get.return_value = settings.GEOCODING_AUTH_URL
        self.assertIsNone(get_auth_headers())
        mock_cache.reset_mock()

        mock_cache.get.return_value = {}
        example_token = "test_token"
        mock_authenticate.return_value = example_token
        expected_header = {"Authorization": "Bearer " + str(example_token)}
        self.assertEquals(expected_header, get_auth_headers())
        mock_update_auth_headers.assert_called_once_with(expected_header)
        mock_cache.get.assert_called_once_with(CACHE_TOKEN_KEY, {})
예제 #2
0
 def get_response(self, payload):
     response = requests.get(self.url,
                             params=payload,
                             headers=get_auth_headers())
     if response.status_code in [401, 403]:
         authenticate()
         response = requests.get(self.url,
                                 params=payload,
                                 headers=get_auth_headers())
         if not response.ok:
             error_message = "EventKit was not able to authenticate to the Geocoding service."
             logger.error(error_message)
             raise AuthenticationError(error_message)
     return response
예제 #3
0
 def testGetHeaders(self):
     testJwt = {'token': 'hello_world'}
     self.mock_requests.get(settings.GEOCODING_AUTH_URL,
                            text=json.dumps(testJwt),
                            status_code=200)
     self.assertEqual(get_auth_headers(),
                      {'Authorization': 'Bearer ' + testJwt['token']})
예제 #4
0
def get_cached_response(url, payload):
    cookies = get_session_cookies()
    headers = get_auth_headers()
    session = get_or_update_session(headers=headers)
    response = session.get(url, params=payload, cookies=cookies)
    if response.ok and check_data(response):
        return response
예제 #5
0
 def testGetHeaders(self):
     cacheValue = 'this_was_in_cache'
     cache.set('pelias_token', cacheValue, None)
     self.assertEqual(get_auth_headers(),
                      {'Authorization': 'Bearer ' + cacheValue})
예제 #6
0
 def testGetHeadersWithNoURL(self):
     self.assertEqual(get_auth_headers(), {})
예제 #7
0
 def testGetHeaders(self):        
     cacheValue = 'this_was_in_cache'
     cache.set('pelias_token', cacheValue, None)
     self.assertEqual(get_auth_headers(), {'Authorization': 'Bearer ' + cacheValue})
예제 #8
0
 def testGetHeaders(self):
     testJwt = {'token': 'hello_world'}
     self.mock_requests.get(settings.GEOCODING_AUTH_URL, text=json.dumps(testJwt), status_code=200)
     self.assertEqual(get_auth_headers(), {'Authorization': 'Bearer ' + testJwt['token']})
예제 #9
0
 def testGetHeadersWithNoURL(self):        
     self.assertEqual(get_auth_headers(), {})