class TestSpreadAbstract(unittest.TestCase): def setUp(self): self.spread = Spread() self.week = 1 def test_initial(self): self.assertIsNone( self.spread.next, "Testing initial state") def test_fetch_is_not_implemented(self): with self.assertRaises(NotImplementedError): self.spread.fetch(self.week), def test_protected_fetch_is_unimplemented(self): with self.assertRaises(NotImplementedError): self.spread._fetch_spread(self.week) def test_save_is_not_implemented(self): data = {} with self.assertRaises(NotImplementedError): self.spread.save(self.week, data), def test_protected_save_is_unimplemented(self): data = {} with self.assertRaises(NotImplementedError): self.spread._save_spread(self.week, data)
def test_fetch_spread(self): expected_count = 1 test_data = self._prepopulate_datastore(year=self.year, week=self.week, count=expected_count) spread = Spread() data = spread.fetch(year=self.year, week=self.week) self.assertEqual(len(data), expected_count) for index, game in enumerate(data): expected_game = test_data[index] self.assertEqual(game, expected_game)
def get(self, year, week): year = int(year) week = int(week) spread = Spread() spread_data = spread.fetch(year=year, week=week) result = { 'spread': spread_data } self._send_response(result)