def test_rest_endpoint_is_called(self): _mock_fetch_uris(self.endpoint, self.resource_uri) reader = APIReader(endpoint='http://' + self.endpoint, type='install', field='foo') values = list(reader.extract(self.last_week, self.yesterday)) # If we get back 20 values, it means that all the data had been read # from the API self.assertEquals(len(values), 20)
def test_purge_raise_on_errors(self): HTTPretty.register_uri( HTTPretty.DELETE, re.compile(self.endpoint + ".*"), body="", status=400) reader = APIReader(endpoint='http://' + self.endpoint, type='install', purge_data=True, field='foo') with self.assertRaises(HTTPError): reader.purge(self.last_week, self.now)
def test_purge_calls_delete(self): HTTPretty.register_uri( HTTPretty.DELETE, re.compile(self.endpoint + ".*install.*"), body="", status=204) reader = APIReader(endpoint='http://' + self.endpoint, type='install', purge_data=True, field='foo') reader.purge(self.last_week, self.now) self.assertEquals(HTTPretty.last_request.method, 'DELETE')
def test_purge_raise_on_errors(self): HTTPretty.register_uri(HTTPretty.DELETE, re.compile(self.endpoint + ".*"), body="", status=400) reader = APIReader(endpoint='http://' + self.endpoint, type='install', purge_data=True, field='foo') with self.assertRaises(HTTPError): reader.purge(self.last_week, self.now)
def test_purge_calls_delete(self): HTTPretty.register_uri(HTTPretty.DELETE, re.compile(self.endpoint + ".*install.*"), body="", status=204) reader = APIReader(endpoint='http://' + self.endpoint, type='install', purge_data=True, field='foo') reader.purge(self.last_week, self.now) self.assertEquals(HTTPretty.last_request.method, 'DELETE')
def test_get_id(self): reader = APIReader(id='mkt-install-foo', endpoint='http://' + self.endpoint, type='install', field='foo') self.assertEqual(reader.get_id(), 'mkt-install-foo')