def setUp(self): self.custom_useragent = 'test UA' self.cache = mock.MagicMock(spec=evelink_api.APICache) self.api = evelink_api.API(cache=self.cache, user_agent=self.custom_useragent) self.test_xml = r""" <?xml version='1.0' encoding='UTF-8'?> <eveapi version="2"> <currentTime>2009-10-18 17:05:31</currentTime> <result> <rowset> <row foo="bar" /> <row foo="baz" /> </rowset> </result> <cachedUntil>2009-11-18 17:05:31</cachedUntil> </eveapi> """.strip() self.error_xml = r""" <?xml version='1.0' encoding='UTF-8'?> <eveapi version="2"> <currentTime>2009-10-18 17:05:31</currentTime> <error code="123"> Test error message. </error> <cachedUntil>2009-11-18 19:05:31</cachedUntil> </eveapi> """.strip() requests_patcher = mock.patch('requests.Session') requests_patcher.start() import requests self.mock_sessions = requests.Session() self.requests_patcher = requests_patcher
def __init__(self): # Set up caching. cache_file = os.path.join(tempfile.gettempdir(), 'koscheck') self.cache = shelf.ShelveCache(cache_file) self.api = api.API(cache=self.cache) self.eve = eve.EVE(api=self.api)
def setUp(self): self.cache = mock.MagicMock(spec=evelink_api.APICache) self.api = evelink_api.API(cache=self.cache) # force disable requests if enabled. self._has_requests = evelink_api._has_requests evelink_api._has_requests = False self.test_xml = r""" <?xml version='1.0' encoding='UTF-8'?> <eveapi version="2"> <currentTime>2009-10-18 17:05:31</currentTime> <result> <rowset> <row foo="bar" /> <row foo="baz" /> </rowset> </result> <cachedUntil>2009-11-18 17:05:31</cachedUntil> </eveapi> """.strip().encode() self.error_xml = r""" <?xml version='1.0' encoding='UTF-8'?> <eveapi version="2"> <currentTime>2009-10-18 17:05:31</currentTime> <error code="123"> Test error message. </error> <cachedUntil>2009-11-18 19:05:31</cachedUntil> </eveapi> """.strip().encode()
def test_get_with_sso_token_and_apikey(self, mock_urlopen): mock_urlopen.return_value.read.return_value = self.test_xml self.cache.get.return_value = None sso_token = (123, 'character') api_key = (1, 'code') api = evelink_api.API(cache=self.cache, sso_token=sso_token, api_key=api_key) api.get('foo', {'a': [2, 3, 4]}) # Make sure the sso token and access type were passed, # and that the api key is not (SSO overrides). self.assertTrue(mock_urlopen.called) self.assertTrue(len(mock_urlopen.call_args[0]) > 0) request = mock_urlopen.call_args[0][0] self.assertEqual('https://api.eveonline.com/foo.xml.aspx', request.get_full_url()) request_dict = urllib.parse.parse_qs(request.data.decode()) expected_request_dict = urllib.parse.parse_qs( "a=2%2C3%2C4&accessType=character&accessToken=123") self.assertEqual(request_dict, expected_request_dict)
def __init__(self, keyID, vCode, char_id): self.checker = ChatKosLookup.KosChecker() self.cache = self.checker.cache self.api = api.API(cache=self.cache, api_key=(keyID, vCode)) self.corp = corp.Corp(api=self.api) self.eve = eve.EVE(api=self.api) self.char = char.Char(api=self.api, char_id=char_id)
def test_get_with_apikey(self): self.mock_sessions.post.return_value = DummyResponse(self.test_xml) self.cache.get.return_value = None api_key = (1, 'code') api = evelink_api.API(cache=self.cache, api_key=api_key) api.get('foo', {'a':[2,3,4]}) # Make sure the api key id and verification code were passed call_args, call_kwargs = self.mock_sessions.post.mock_calls[0][1:3] called_url = call_args[0] called_param_dict = call_kwargs["data"] expected_url = 'https://api.eveonline.com/foo.xml.aspx' expected_param_dict = {'a': '2,3,4', 'vCode': 'code', 'keyID': 1} self.assertEqual(called_url, expected_url) self.assertEqual(called_param_dict, expected_param_dict)
def test_get_with_apikey(self, mock_urlopen): mock_urlopen.return_value.read.return_value = self.test_xml self.cache.get.return_value = None api_key = (1, 'code') api = evelink_api.API(cache=self.cache, api_key=api_key) api.get('foo', {'a': [2, 3, 4]}) # Make sure the api key id and verification code were passed self.assertTrue(mock_urlopen.called) self.assertTrue(len(mock_urlopen.call_args[0]) > 0) request = mock_urlopen.call_args[0][0] self.assertEqual('https://api.eveonline.com/foo.xml.aspx', request.get_full_url()) request_dict = urllib.parse.parse_qs(request.data.decode()) expected_request_dict = urllib.parse.parse_qs( "a=2%2C3%2C4&vCode=code&keyID=1") self.assertEqual(request_dict, expected_request_dict)