Ejemplo n.º 1
0
 def test_encode(self):
     keyauth = KeyAuth(api_key='test_api_key')
     assert (keyauth.encode() == 'test_api_key')
Ejemplo n.º 2
0
 def __init__(self, api_key=None, loop=None, timeout=None):
     self.auth = KeyAuth(
         api_key=api_key if api_key else env_variable_api_key())
     self.loop = asyncio.get_event_loop() if loop is None else loop
     self.session = aiohttp.ClientSession(auth=self.auth, loop=self.loop)
     self.timeout = timeout
Ejemplo n.º 3
0
 def test_decode_cannot_parse(self):
     '''Authorization HTTP header should look like "Basic test_api_key"'''
     with pytest.raises(ValueError):
         KeyAuth.decode('test_api_key')
Ejemplo n.º 4
0
 def test_decode_not_basic_auth(self):
     '''Authorization HTTP header should look like "Basic test_api_key"'''
     with pytest.raises(ValueError):
         KeyAuth.decode('Not basic test_api_key')
Ejemplo n.º 5
0
 def test_decode(self):
     assert (
         KeyAuth.decode('Basic test_api_key').encode() == 'test_api_key')
Ejemplo n.º 6
0
 def test_from_url_no_api_key(self):
     assert (KeyAuth.from_url(
         URL('https://newsapi.org/v2/[email protected]'))
             is None)
Ejemplo n.º 7
0
 def test_from_url_uses_yarl(self):
     '''from_url takes url as a yarnl.URL object'''
     with pytest.raises(TypeError):
         KeyAuth.from_url(
             'https://newsapi.org/v2/[email protected]&apiKey=test_api_key'
         )
Ejemplo n.º 8
0
 def test_from_url(self):
     assert (KeyAuth.from_url(
         URL('https://newsapi.org/v2/[email protected]&apiKey=test_api_key'
             )) == KeyAuth(api_key='test_api_key'))
Ejemplo n.º 9
0
 def test_api_key_not_none(self):
     with pytest.raises(ValueError):
         KeyAuth(None)