Ejemplo n.º 1
0
    def assert_points(self, point_system, positions, points):
        self.assertEqual(
            len(positions),
            len(points),
            msg=
            'This test makes no sense: there is not the same number of positions and points'
        )
        friends = create_friends(len(positions))
        if len(positions) == 1:
            friends = [friends]
        tournament = create_tournaments(1)
        tournament.point_system = point_system
        tournament.save()
        results = [
            Result.objects.create(tournament=tournament,
                                  friend=friends[i],
                                  position=position)
            for i, position in enumerate(positions)
        ]

        for i, position in enumerate(positions):
            self.assertEqual(
                calculate_points(results[i]),
                points[i],
                msg=f'positon {position} should result in {points[i]} points')
Ejemplo n.º 2
0
 def test_representation(self):
     create_divisions()
     result = Result(friend=create_friends(1),
                     tournament=create_tournaments(1),
                     position=1,
                     division=Division.objects.get(id='MPO'))
     self.assertEqual(
         str(result),
         'Friend0 was 1st at Tournament0 (01. Jan 2020) in the "MPO - Pro Open" division'
     )
Ejemplo n.º 3
0
 def test_repeated_first_positions(self):
     tournament = create_tournaments(1)
     tournament.name = 'Tremonia Series #1'
     friends = create_friends(4)
     self.assert_that(tournament, IS_OK, friends,
                      in_positions=[])  # empty results
     self.assert_that(tournament, IS_OK, friends, in_positions=[1, 2, 3, 4])
     self.assert_that(tournament,
                      NOT_OK,
                      friends,
                      in_positions=[1, 2, 3, 3])
     self.assert_that(tournament,
                      NOT_OK,
                      friends,
                      in_positions=[1, 2, 2, 3])
     self.assert_that(tournament,
                      NOT_OK,
                      friends,
                      in_positions=[1, 2, 2, 4])
     self.assert_that(tournament,
                      NOT_OK,
                      friends,
                      in_positions=[1, 2, 2, 2])
     self.assert_that(tournament,
                      NOT_OK,
                      friends,
                      in_positions=[1, 1, 3, 4])
     self.assert_that(tournament,
                      NOT_OK,
                      friends,
                      in_positions=[1, 1, 3, 3])
     self.assert_that(tournament,
                      NOT_OK,
                      friends,
                      in_positions=[1, 1, 1, 2])
     self.assert_that(tournament,
                      NOT_OK,
                      friends,
                      in_positions=[1, 1, 1, 3])
     self.assert_that(tournament,
                      NOT_OK,
                      friends,
                      in_positions=[1, 1, 1, 4])
     self.assert_that(tournament,
                      NOT_OK,
                      friends,
                      in_positions=[1, 1, 1, 1])
Ejemplo n.º 4
0
    def test_recalculate_points_witout_point_system(self):
        friends = create_friends(2)
        tournament = create_tournaments(1)
        first = Result.objects.create(tournament=tournament,
                                      friend=friends[0],
                                      position=1)
        second = Result.objects.create(tournament=tournament,
                                       friend=friends[1],
                                       position=2)
        self.assertEqual(first.points, None)
        self.assertEqual(second.points, None)

        tournament.recalculate_points()
        first.refresh_from_db()
        second.refresh_from_db()

        self.assertEqual(first.points, None)
        self.assertEqual(second.points, None)
Ejemplo n.º 5
0
    def test_recalculate_points(self):
        friends = create_friends(2)
        tournament = create_tournaments(1)
        tournament.point_system = Tournament.TS_POINTS_WITH_BEATEN_PLAYERS
        tournament.save()
        first = Result.objects.create(tournament=tournament,
                                      friend=friends[0],
                                      position=1)
        second = Result.objects.create(tournament=tournament,
                                       friend=friends[1],
                                       position=2)
        self.assertEqual(first.points, None)
        self.assertEqual(second.points, None)

        tournament.recalculate_points()
        first.refresh_from_db()
        second.refresh_from_db()

        self.assertEqual(first.points, 20)
        self.assertEqual(second.points, 17)
Ejemplo n.º 6
0
 def test_metrix_url(self):
     tournament = create_tournaments(1)
     tournament.metrix_id = 123
     tournament.save()
     self.assertEqual(metrix_url(tournament),
                      'https://discgolfmetrix.com/123')
Ejemplo n.º 7
0
 def test_ts_number_mobile_with_no_ts_tournament(self):
     tournament = create_tournaments(1)
     tournament.name = 'Tremonia Open 2020'
     tournament.save()
     self.assertEqual(ts_number_mobile(tournament), '')
Ejemplo n.º 8
0
 def test_ts_number_mobile_with_text_after_number(self):
     tournament = create_tournaments(1)
     tournament.name = 'Tremonia Series #1 (Putter)'
     tournament.save()
     self.assertEqual(ts_number_mobile(tournament), '#1')
Ejemplo n.º 9
0
 def test_ts_number_mobile(self):
     tournament = create_tournaments(1)
     tournament.name = 'Tremonia Series #1'
     tournament.save()
     self.assertEqual(ts_number_mobile(tournament), '#1')
Ejemplo n.º 10
0
 def test_metrix_url_without_id(self):
     tournament = create_tournaments(1)
     tournament.metrix_id = None
     tournament.save()
     self.assertEqual(metrix_url(tournament), '')
Ejemplo n.º 11
0
 def assert_ordinal(self, expected, position):
     result = Result(friend=create_friends(1),
                     tournament=create_tournaments(1),
                     position=position)
     self.assertEqual(result.ordinal_position, expected)