def test_search_corrupted_data_repr(self): results = Results(CORRUPTED) self.assertEqual( 'conspirators in the assassination of Abraham Lincoln – George Atzerodt died in 1865 this date' ' (born in 1833) – David Herold died in 1865 this date (born in 1842) – Lewis Payne died in ' '1865 this date (born in 1844) – Mary Surratt died in 1865 this date (born in 1823)', str(results.search('1865')[0]))
def _fetch(self, endpoint): '''Helper method to communicate with the data provider.''' r = requests.get(endpoint) if r.status_code == requests.codes.ok: return Results(r.json()) raise ValueError('Got invalid status code {status_code} when trying to access the endpoint {endpoint}' .format(endpoint=endpoint, status_code=r.status_code))
def setUp(self): self.results = Results(DATA)
def test_search_corrupted_data(self): results = Results(CORRUPTED) self.assertEqual(2, len(results.search('2003')))
def test_search_results_double_right(self): data = deepcopy(DATA) data['data']['Events'].insert(2, data['data']['Events'][2]) results = Results(data) self.assertEqual(2, len(results.search(results.deaths[2].year)))
def test_search_results_double_left(self): data = deepcopy(DATA) data['data']['Deaths'].insert(0, data['data']['Deaths'][0]) results = Results(data) self.assertEqual(2, len(results.search(results.deaths[0].year)))