def test_clean_response(self, mockrequests): client = SpotlightClient() cleaned_data = client._clean_response(self.sample_result) self.assert_('text' in cleaned_data) self.assert_('@text' not in cleaned_data) self.assert_('types' in cleaned_data) self.assert_('@types' not in cleaned_data) self.assert_('URI' in cleaned_data['Resources'][0]) self.assert_('@support' not in cleaned_data['Resources'][0])
def test_clean_response(self, mockrequests): client = SpotlightClient() cleaned_data = client._clean_response(self.sample_result) self.assert_("text" in cleaned_data) self.assert_("@text" not in cleaned_data) self.assert_("types" in cleaned_data) self.assert_("@types" not in cleaned_data) self.assert_("URI" in cleaned_data["Resources"][0]) self.assert_("@support" not in cleaned_data["Resources"][0])
def test_init(self, mockrequests): # all default options client = SpotlightClient() self.assertEqual(client.default_url, client.base_url) # all custom options base_url = 'http://my.spotlight.org/mirror/' confidence = 0.2 support = 42 types = ['Person', 'Place'] client = SpotlightClient(base_url, confidence=confidence, support=support, types=types) self.assertEqual(base_url, client.base_url) self.assertEqual(confidence, client.default_confidence) self.assertEqual(support, client.default_support) self.assertEqual(','.join(types), client.default_types)
def test_annotate(self, mockrequests): client = SpotlightClient() text = 'some bogus text to annotate' # simulate ok response mockrequests.get.return_value.status_code = 200 mockrequests.codes.ok = 200 mockrequests.get.return_value.json.return_value = self.sample_result result = client.annotate(text) self.assertEqual(client._clean_response(self.sample_result), result) get_headers = { 'accept': 'application/json', #'content-type': 'application/x-www-form-urlencoded' } mockrequests.get.assert_called_with(client.default_url + '/annotate', params={'text': text}, headers=get_headers)
def test_annotate(self, mockrequests): client = SpotlightClient() text = "some bogus text to annotate" # simulate ok response mockrequests.get.return_value.status_code = 200 mockrequests.codes.ok = 200 mockrequests.get.return_value.json.return_value = self.sample_result result = client.annotate(text) self.assertEqual(client._clean_response(self.sample_result), result) get_headers = { "accept": "application/json", #'content-type': 'application/x-www-form-urlencoded' } mockrequests.get.assert_called_with( client.default_url + "/annotate", params={"text": text}, headers=get_headers )