Ejemplo n.º 1
0
    def test_create_game_view_with_no_conflict(self):
        test_user, test_player = th.generate_test_user(
            "test-user-1", "fivesPass123", "*****@*****.**", "Test",
            "User")
        self.client.login(username='******', password='******')
        response = self.client.get(reverse('create_game'), follow=True)

        # This line just adds the game to the database.
        # To fix it, mimic the client submitting a form with self.client.post()
        # See here: https://stackoverflow.com/questions/46001747/django-test-client-post-data
        th.create_game(0, 9, "2018-04-23 14:00", "2018-04-23 15:00", 1,
                       "66 Bankhead Dr", "Edinburgh", "EH11 4EQ", 5, 1,
                       test_user)
Ejemplo n.º 2
0
 def test_create_game_view_with_conflict(self):
     test_user, test_player = th.generate_test_user(
         "test-user-1", "fivesPass123", "*****@*****.**", "Test",
         "User")
     th.create_game(0, 9, "2018-04-28 16:00", "2018-04-28 18:00", 2,
                    "66 Bankhead Dr", "Edinburgh", "EH11 4EQ", 5, 1,
                    test_user)
     self.client.login(username='******', password='******')
     response = self.client.get(reverse('create_game'))
     # Same issue as above,
     # This line requires self.client.post().
     th.create_game(0, 9, "2018-04-28 17:00", "2018-04-28 18:00", 1,
                    "10 Keith St", "Glasgow", "G11 6QQ", 0, 0, test_user)
Ejemplo n.º 3
0
    def test_show_game_with_existing_game(self):
        test_user, test_player = th.generate_test_user("test-user-1", "fivesPass123", "*****@*****.**", "Test", "User")
        test_game = th.create_game(0, 9, "2018-04-28 14:00", "2018-04-28 15:00", 1, "66 Bankhead Dr", "Edinburgh", "EH11 4EQ", 5, 1, test_user)
        th.create_participation(test_game, test_player, 0)

        game_custom_slug = Game.objects.all()[0].custom_slug
        response = self.client.get(reverse('show_game', kwargs={'game_custom_slug': game_custom_slug}))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Competitive")
Ejemplo n.º 4
0
 def test_game_string_representation(self):
     test_user, test_player = th.generate_test_user(
         "test-user-1", "fivesPass123", "*****@*****.**", "Test",
         "User")
     test_game = th.create_game(0, 9, "2018-02-28 14:00",
                                "2018-02-28 15:00", 1, "66 Bankhead Dr",
                                "Edinburgh", "EH11 4EQ", 5, 1, test_user)
     self.assertEqual(
         str(test_game),
         str(test_game.host) + " " + str(test_game.start) + " " +
         str(test_game.game_id)[:6])
Ejemplo n.º 5
0
 def test_participation_string_representation(self):
     test_user, test_player = th.generate_test_user(
         "test-user-1", "fivesPass123", "*****@*****.**", "Test",
         "User")
     test_game = th.create_game(0, 9, "2018-04-28 14:00",
                                "2018-04-28 15:00", 1, "66 Bankhead Dr",
                                "Edinburgh", "EH11 4EQ", 5, 1, test_user)
     test_participation = th.create_participation(test_game, test_player, 0)
     self.assertEqual(
         str(test_participation),
         str(test_participation.player) + " " +
         str(test_participation.game) + " " + str(test_participation.rated))
Ejemplo n.º 6
0
    def test_show_past_game_not_rated_by_user(self):
        # Create test user and login.
        test_user, test_player = th.generate_test_user("test-user-1", "fivesPass1", "*****@*****.**", "Test", "User")
        test_user2, test_player2 = th.generate_test_user("test-user-2", "fivesPass2", "*****@*****.**", "Test2", "User2")
        self.client.login(username='******', password='******')
        # Create test game and add test users to particpation.
        start_datetime, end_datetime = th.start_and_end_datetime_generator(-100,2)
        test_game = th.create_game(0, 9, start_datetime, end_datetime, 2, "10 Keith St", "Glasgow", "G11 6QQ", 0, 1, test_user)
        th.create_participation(test_game, test_player, 0)
        th.create_participation(test_game, test_player2, 0)

        game_custom_slug = test_game.custom_slug
        response = self.client.get(reverse('show_past_game', kwargs={'player': test_user, 'game_custom_slug': game_custom_slug}))
        self.assertEqual(response.status_code, 200)
        # Check that a formset was passed from view to the template, giving the user the opportunity ro rate.
        formset = response.context['rating_formset']
        self.assertNotEqual(formset, None)
Ejemplo n.º 7
0
    def test_create_game_view_with_conflict(self):
        # Add user and login, add game and particpation to database, and redirect to create game.
        test_user, test_player = th.generate_test_user("test-user-1", "fivesPass123", "*****@*****.**", "Test", "User")
        self.client.login(username='******', password='******')

        start_datetime, end_datetime = th.start_and_end_datetime_generator(10,2)
        test_game = th.create_game(0, 9, start_datetime, end_datetime, 2, "10 Keith St", "Glasgow", "G11 6QQ", 0, 0, test_user)
        th.create_participation(test_game, test_player, 0)

        self.client.get(reverse('create_game'))

        # Try creating a game with a time conflict.
        start_date, start_time = th.start_date_and_time_generator(10)
        response = self.client.post(reverse('create_game'), {'game_type': 0, 'date': start_date, 'time': start_time, 'duration': 1,
                                                  'street': "66 Bankhead Dr", 'city': "Edinburgh", 'postcode': "EH11 4EQ", 'price': 5, 'booked': 1} )

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "You already have a game scheduled during this time")

        # Game should not have been added to the database.
        response = self.client.get(reverse('index'))
        num_games = len(response.context['games'])
        self.assertEqual(num_games , 1)