Пример #1
0
    def test_rank_dynamic_mock(self, module):
        modname, module = module
        t1 = self.make_team(active=True)
        t2 = self.make_team(active=True)
        module.get_points = lambda t: 1 if t == t1 else 0
        c = self.make_challenge(dynamic=True, module=modname)
        self.dbsession.add_all([t1, t2, c])

        def get_points_query(t=None):
            if t is None:
                t = Team
            stmt = select([case([
                (t.id == t1.id, 1),
            ],
            else_=0,
            )]).correlate(t)
            return stmt
        module.get_points_query = get_points_query

        self.dbsession.flush()
        update_score(self.dbsession.connection())
        assert t1.rank == 1
        assert t2.rank == 2

        team_list = self.dbsession.query(Team, Team.rank).order_by(Team.id).all()
        t1_ref, t1_rank = team_list[0]
        t2_ref, t2_rank = team_list[1]
        assert t1_ref is t1
        assert t2_ref is t2
        assert t1_rank == 1
        assert t2_rank == 2
Пример #2
0
    def test_rank(self):
        t1 = self.make_team(active=True)
        t2 = self.make_team(active=True)
        t3 = self.make_team(active=True)
        t4 = self.make_team(active=True)
        c1 = self.make_challenge(base_points=100, published=True)
        self.dbsession.add_all([t1, t2, t3, t4, c1])
        Submission(challenge=c1, team=t1)
        Submission(challenge=c1, team=t2, additional_pts=3)
        Submission(challenge=c1, team=t3)
        self.dbsession.flush()
        self.dbsession.expire(t1)
        self.dbsession.expire(t2)
        self.dbsession.expire(t3)
        self.dbsession.expire(t4)
        update_score(self.dbsession.connection())
        assert t1.rank == 2
        assert t2.rank == 1
        assert t3.rank == 2
        assert t4.rank == 4

        team_list = self.dbsession.query(Team, Team.rank).order_by(Team.id).all()
        assert len(team_list) == 4
        t1_ref, t1_rank = team_list[0]
        t2_ref, t2_rank = team_list[1]
        t3_ref, t3_rank = team_list[2]
        t4_ref, t4_rank = team_list[3]
        assert t1_ref is t1
        assert t2_ref is t2
        assert t3_ref is t3
        assert t4_ref is t4
        assert t1_rank == 2
        assert t2_rank == 1
        assert t3_rank == 2
        assert t4_rank == 4
Пример #3
0
    def test_score_bonus(self):
        t = self.make_team(active=True)
        c = self.make_challenge(published=True)
        self.dbsession.add_all([t, c])
        Submission(challenge=c, team=t, additional_pts=3)
        self.dbsession.flush()
        self.dbsession.expire(c)
        update_score(self.dbsession.connection())
        assert t.score == 3 + c.points

        t_ref, score = self.dbsession.query(Team, Team.score).first()
        assert t_ref is t
        assert score == 3 + c.points
Пример #4
0
    def test_score_dynamic_mock(self, module):
        modname, module = module
        t = self.make_team(active=True)
        c = self.make_challenge(dynamic=True, module=modname)
        self.dbsession.add_all([t, c])
        c = self.dbsession.query(Challenge).one()
        t = self.dbsession.query(Team).one()
        module.get_points.return_value = 123
        module.get_points_query.return_value = select([0]).as_scalar()
        update_score(self.dbsession.connection())
        assert t.score == 123

        self.dbsession.flush()
        self.dbsession.expire(c)
        module.get_points_query.return_value = select([1234]).as_scalar()
        update_score(self.dbsession.connection())
        t_ref, score = self.dbsession.query(Team, Team.score).first()
        assert t_ref is t
        assert score == 1234
        t._score = None