Example #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')
Example #2
0
    def test_filter_videos_by_type(self):
        friend = create_friends(1)
        videos = [
            Video.objects.create(friend=friend,
                                 url='http://example.com/video/0',
                                 type=Video.ACE),
            Video.objects.create(friend=friend,
                                 url='http://example.com/video/1',
                                 type=Video.ACE),
            Video.objects.create(friend=friend,
                                 url='http://example.com/video/2',
                                 type=Video.ACE),
            Video.objects.create(friend=friend,
                                 url='http://example.com/video/3',
                                 type=Video.IN_THE_BAG),
            Video.objects.create(friend=friend,
                                 url='http://example.com/video/4',
                                 type=Video.IN_THE_BAG),
            Video.objects.create(friend=friend,
                                 url='http://example.com/video/5',
                                 type=Video.OTHER),
        ]

        self.assert_videos(friend, Video.ACE, videos[0:3])
        self.assert_videos(friend, Video.IN_THE_BAG, videos[3:5])
        self.assert_videos(friend, Video.OTHER, videos[5:])
Example #3
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'
     )
Example #4
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])
Example #5
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)
Example #6
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)
Example #7
0
    def test_filter_discs_by_type(self):
        friend = create_friends(1)
        discs = create_discs(10)
        DiscInBag.objects.create(friend=friend,
                                 disc=discs[0],
                                 type=DiscInBag.PUTTER)
        DiscInBag.objects.create(friend=friend,
                                 disc=discs[1],
                                 type=DiscInBag.PUTTER)
        DiscInBag.objects.create(friend=friend,
                                 disc=discs[2],
                                 type=DiscInBag.PUTTER)
        DiscInBag.objects.create(friend=friend,
                                 disc=discs[3],
                                 type=DiscInBag.PUTTER)
        DiscInBag.objects.create(friend=friend,
                                 disc=discs[4],
                                 type=DiscInBag.MID_RANGE)
        DiscInBag.objects.create(friend=friend,
                                 disc=discs[5],
                                 type=DiscInBag.MID_RANGE)
        DiscInBag.objects.create(friend=friend,
                                 disc=discs[6],
                                 type=DiscInBag.MID_RANGE)
        DiscInBag.objects.create(friend=friend,
                                 disc=discs[7],
                                 type=DiscInBag.FAIRWAY_DRIVER)
        DiscInBag.objects.create(friend=friend,
                                 disc=discs[8],
                                 type=DiscInBag.FAIRWAY_DRIVER)
        DiscInBag.objects.create(friend=friend,
                                 disc=discs[9],
                                 type=DiscInBag.DISTANCE_DRIVER)

        self.assert_in_the_bag(friend, DiscInBag.PUTTER, discs[0:4])
        self.assert_in_the_bag(friend, DiscInBag.MID_RANGE, discs[4:7])
        self.assert_in_the_bag(friend, DiscInBag.FAIRWAY_DRIVER, discs[7:9])
        self.assert_in_the_bag(friend, DiscInBag.DISTANCE_DRIVER, discs[9:])
Example #8
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)