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_save_same(self): expected_count = 1 generated_data = self._generate_data(year=self.year, week=self.week, count=expected_count) spread = Spread() count = spread.save(year=self.year, week=self.week, data=generated_data) generated_data[0]['game_line'] += 13 count = spread.save(year=self.year, week=self.week, data=generated_data) # Check datastore ancestor_key = spread._generate_key(year=self.year, week=self.week) data = SpreadModel().query(ancestor=ancestor_key).fetch(expected_count+1) self.assertEqual(len(data), expected_count) for index in range(expected_count): expected_game = generated_data[index] game = data[index].to_dict() self.assertEqual(game, expected_game)
def put(self, year, week): """ WARNING! Use of this endpoint will create odd side-effects This endpoint does not acknowledge the 'game_id' property of spread data """ year = int(year) week = int(week) param = self.request.POST['spread'] # webapp2 treats POST body the same for PUT spread_data = json.loads(param) spread = Spread() result = spread.save(year=year, week=week, data=spread_data) self.response.set_status(201) self._send_response()
def test_save_multiple_spread(self): expected_count = randint(2, 16) test_data = self._generate_data(year=self.year, week=self.week, count=expected_count) spread = Spread() count = spread.save(year=self.year, week=self.week, data=test_data) self.assertEqual(count, expected_count) # Check datastore ancestor_key = spread._generate_key(year=self.year, week=self.week) data = SpreadModel().query(ancestor=ancestor_key).order(SpreadModel.game_id).fetch(expected_count+1) self.assertEqual(len(data), expected_count) for index in range(expected_count): expected_game = test_data[index] game = data[index].to_dict() self.assertEqual(game, expected_game)