Exemple #1
0
    def test_create_or_replace(self):
        tim = PlayerTest().add_player()
        data = self.fake_data(tim, 1, "DK")
        first = Projection.create_or_replace(data)
        self.assertEqual(tim.id, first.player_id)
        self.assertEqual(1000, first.salary)
        self.db.session.add(first)
        self.db.session.flush()

        data['salary'] = 2500
        second = Projection.create_or_replace(data)
        self.assertEqual(tim.id, second.player_id)
        self.assertEqual(first.site, second.site)
        self.assertEqual(2500, second.salary)
        self.db.session.add(second)
        self.db.session.commit()

        self.assertEqual(1, Projection.query.count())
 def commit_projections(self):
     for id, data in self.player_id_to_data.items():
         projection = self.for_projection(data)
         row = Projection.create_or_replace(projection)
         self.db.session.add(row)
     self.db.session.commit()