Пример #1
0
    def test_upcoming_events_date_change(self):
        self.add_tournament_data('333', 'Tremonia Series #3', '2021-07-24',
                                 '2021-07-24')
        self.add_tournament_data('444', 'Tremonia Series #4', '2021-07-24',
                                 '2021-07-25')
        self.fake_pdga_player_page_with_upcoming_events(111828)

        manolo = Friend.objects.create(username='******', pdga_number=111828)
        Tournament.objects.create(pdga_id=333,
                                  name='Tremonia Series #3',
                                  begin=APRIL_2,
                                  end=APRIL_2)
        Tournament.objects.create(pdga_id=444,
                                  name='Tremonia Series #4',
                                  begin=JULY_24,
                                  end=JULY_24)

        pdga.update_friend_tournaments(manolo, self.pdga_api)

        ts3 = Tournament.objects.get(pdga_id=333)
        self.assertEqual(ts3.begin, JULY_24)
        self.assertEqual(ts3.end, JULY_24)

        ts4 = Tournament.objects.get(pdga_id=444)
        self.assertEqual(ts4.begin, JULY_24)
        self.assertEqual(ts4.end, JULY_25)
Пример #2
0
    def test_no_pdga_number_no_attendance(self):
        manolo = Friend.objects.create(username='******')

        pdga.update_friend_tournaments(manolo, self.pdga_api)

        attendance_list = list(Attendance.objects.filter(friend=manolo))
        self.assertListEqual(attendance_list, [])
Пример #3
0
    def test_upcoming_events_existing_attendance_existing_tournaments(self):
        self.add_tournament_data('333', 'Tremonia Series #3', '2021-07-24',
                                 '2021-07-24')
        self.add_tournament_data('444', 'Tremonia Series #4', '2021-07-24',
                                 '2021-07-25')
        self.fake_pdga_player_page_with_upcoming_events(111828)

        manolo = Friend.objects.create(username='******', pdga_number=111828)
        ts3 = Tournament.objects.create(pdga_id=333,
                                        name='Tremonia Series #3',
                                        begin=JULY_24,
                                        end=JULY_24)
        ts4 = Tournament.objects.create(pdga_id=444,
                                        name='Tremonia Series #4',
                                        begin=JULY_24,
                                        end=JULY_25)
        Attendance.objects.create(friend=manolo, tournament=ts3)
        Attendance.objects.create(friend=manolo, tournament=ts4)

        pdga.update_friend_tournaments(manolo, self.pdga_api)

        attendance_list = Attendance.objects.filter(friend=manolo)
        self.assertEqual(len(attendance_list), 2)

        attendance_ts3 = attendance_list.get(tournament__pdga_id=333)
        self.assertEqual(attendance_ts3.tournament, ts3)
        self.assertEqual(attendance_ts3.friend, manolo)

        attendance_ts4 = attendance_list.get(tournament__pdga_id=444)
        self.assertEqual(attendance_ts4.tournament, ts4)
        self.assertEqual(attendance_ts4.friend, manolo)
Пример #4
0
    def test_upcoming_events_no_attendance_no_tournaments(self):
        self.add_tournament_data('333', 'Tremonia Series #3', '2021-07-24',
                                 '2021-07-24')
        self.add_tournament_data('444', 'Tremonia Series #4', '2021-07-24',
                                 '2021-07-25')
        self.fake_pdga_player_page_with_upcoming_events(111828)

        manolo = Friend.objects.create(username='******', pdga_number=111828)

        pdga.update_friend_tournaments(manolo, self.pdga_api)

        attendance_list = Attendance.objects.filter(friend=manolo)
        self.assertEqual(len(attendance_list), 2)

        attendance_ts3 = attendance_list.get(tournament__pdga_id=333)
        self.assertEqual(attendance_ts3.tournament.name, 'Tremonia Series #3')
        self.assertEqual(attendance_ts3.tournament.url,
                         'https://www.pdga.com/tour/event/333')
        self.assertEqual(attendance_ts3.tournament.begin, JULY_24)
        self.assertEqual(attendance_ts3.tournament.end, JULY_24)
        self.assertEqual(attendance_ts3.friend, manolo)

        attendance_ts4 = attendance_list.get(tournament__pdga_id=444)
        self.assertEqual(attendance_ts4.tournament.name, 'Tremonia Series #4')
        self.assertEqual(attendance_ts4.tournament.url,
                         'https://www.pdga.com/tour/event/444')
        self.assertEqual(attendance_ts4.tournament.begin, JULY_24)
        self.assertEqual(attendance_ts4.tournament.end, JULY_25)
        self.assertEqual(attendance_ts4.friend, manolo)
Пример #5
0
    def test_without_events_no_attendance(self):
        self.fake_pdga_player_page_without_events(111828)

        manolo = Friend.objects.create(username='******', pdga_number=111828)

        pdga.update_friend_tournaments(manolo, self.pdga_api)

        attendance_list = list(Attendance.objects.filter(friend=manolo))
        self.assertListEqual(attendance_list, [])
Пример #6
0
    def handle_friend(self, pdga_api, friend):

        try:

            pdga_api.update_friend_rating(friend)
            pdga_api.update_friend_tournament_statistics(friend)
            pdga.update_friend_tournaments(friend, pdga_api)

        except Exception as e:
            logger.error(f'Exception updating PDGA data for friend: {friend}')
            error_handler.handle(self, e, friend)
Пример #7
0
    def test_no_pdga_number_but_attendance(self):
        manolo = Friend.objects.create(username='******')
        tournament = Tournament.objects.create(pdga_id=123,
                                               name='test',
                                               begin=date.today(),
                                               end=date.today())
        existing_attendance = Attendance.objects.create(friend=manolo,
                                                        tournament=tournament)

        pdga.update_friend_tournaments(manolo, self.pdga_api)

        attendance_list = list(Attendance.objects.filter(friend=manolo))
        self.assertListEqual(attendance_list, [existing_attendance])
Пример #8
0
    def test_without_events_but_attendance(self):
        self.fake_pdga_player_page_without_events(111828)

        manolo = Friend.objects.create(username='******', pdga_number=111828)
        ts3 = Tournament.objects.create(pdga_id=333,
                                        name='Tremonia Series #3',
                                        begin=JULY_24,
                                        end=JULY_24)
        Attendance.objects.create(friend=manolo, tournament=ts3)

        pdga.update_friend_tournaments(manolo, self.pdga_api)

        attendance_list = Attendance.objects.filter(friend=manolo)
        self.assertEqual(len(attendance_list), 1)

        attendance_ts3 = attendance_list.get(tournament__pdga_id=333)
        self.assertEqual(attendance_ts3.tournament, ts3)
        self.assertEqual(attendance_ts3.friend, manolo)
Пример #9
0
    def test_next_event_existing_attendance_existing_tournament(self):
        self.add_tournament_data('333', 'Tremonia Series #3', '2021-07-24',
                                 '2021-07-24')
        self.fake_pdga_player_page_with_next_event(111828)

        manolo = Friend.objects.create(username='******', pdga_number=111828)
        ts3 = Tournament.objects.create(pdga_id=333,
                                        name='Tremonia Series #3',
                                        begin=JULY_24,
                                        end=JULY_24)
        Attendance.objects.create(friend=manolo, tournament=ts3)

        pdga.update_friend_tournaments(manolo, self.pdga_api)

        attendance_list = Attendance.objects.filter(friend=manolo)
        self.assertEqual(len(attendance_list), 1)

        attendance_ts3 = attendance_list.get(tournament__pdga_id=333)
        self.assertEqual(attendance_ts3.tournament.name, 'Tremonia Series #3')
        self.assertEqual(attendance_ts3.tournament.url,
                         'https://www.pdga.com/tour/event/333')
        self.assertEqual(attendance_ts3.tournament.begin, JULY_24)
        self.assertEqual(attendance_ts3.tournament.end, JULY_24)
        self.assertEqual(attendance_ts3.friend, manolo)