Beispiel #1
0
 def test_return_404_if_game_doesnt_exist(self):
     http_authorization = build_http_auth_header(self.username, self.password)
     response = self.client.delete(
         reverse('game_config:game_info', kwargs={'uuid':'1234'}),
         HTTP_AUTHORIZATION = http_authorization
     )
     self.assertEqual(response.status_code, 404)
Beispiel #2
0
 def test_return_401_with_incorrect_login(self):
     http_authorization = build_http_auth_header(self.username, 'wrong')
     response = self.client.delete(
         reverse('game_config:game_info', kwargs={'uuid':self.game.uuid}),
         HTTP_AUTHORIZATION = http_authorization
     )
     self.assertEqual(response.status_code, 401)
Beispiel #3
0
 def test_return_unauthorized_with_wrong_credentials(self):
     http_authorization = build_http_auth_header(self.username, 'wrong')
     response = self.client.post(
         reverse('game_config:root'),
         {'game_name':'name'},
         content_type='application/json',
         HTTP_AUTHORIZATION = http_authorization
     )
     self.assertEqual(response.status_code, 401)
Beispiel #4
0
    def test_return_unauthorized_with_wrong_credentials(self):
        http_authorization = build_http_auth_header(self.user.username, 'wrong')

        response = self.client.get(
            reverse('projects:get_project', kwargs={'game_uuid':self.game.uuid}),
            HTTP_AUTHORIZATION = http_authorization
        )

        self.assertEqual(response.status_code, 401)
Beispiel #5
0
    def test_return_404_if_user_has_no_player(self):
        new_user, password = self.create_django_user(username='******')
        http_authorization = build_http_auth_header(new_user.username, password)

        response = self.client.get(
            reverse('projects:get_project', kwargs={'game_uuid':self.game.uuid}),
            HTTP_AUTHORIZATION = http_authorization
        )
        self.assertEqual(response.status_code, 404)
Beispiel #6
0
    def test_return_404_if_user_doesnt_belong_to_the_game(self):
        new_user, password = self.create_django_user(username='******')
        game, player = self.create_game_and_player(new_user, game_name='new_game')
        http_authorization = build_http_auth_header(new_user.username, password)

        response = self.client.get(
            reverse('projects:calc_pontuation', kwargs={'game_uuid':self.game.uuid}),
            HTTP_AUTHORIZATION = http_authorization
        )
        self.assertEqual(response.status_code, 404)
Beispiel #7
0
    def test_returns_404_if_game_doesnt_exist(self):
        http_authorization = build_http_auth_header(self.username, self.password)
        response = self.client.post(
            reverse('game_config:game_info', kwargs={'uuid':'not_exists'}),
            {},
            content_type='application/json',
            HTTP_AUTHORIZATION = http_authorization
        )

        self.assertEqual(response.status_code, 404)
Beispiel #8
0
    def test_delete_game_if_it_exist_and_is_creator_login(self):
        self.assertTrue(Game.objects.all())

        http_authorization = build_http_auth_header(self.username, self.password)
        response = self.client.delete(
            reverse('game_config:game_info', kwargs={'uuid':self.game.uuid}),
            HTTP_AUTHORIZATION = http_authorization
        )
        self.assertEqual(response.status_code, 200)
        self.assertFalse(Game.objects.all())
Beispiel #9
0
    def test_bad_request_with_corret_credentials_and_without_game_info(self):
        http_authorization = build_http_auth_header(self.username, self.password)
        response = self.client.post(
            reverse('game_config:root'),
            {},
            content_type='application/json',
            HTTP_AUTHORIZATION = http_authorization
        )

        self.assertEqual(response.status_code, 400)
    def test_return_unauthorized_with_wrong_credentials(self):
        http_auth = build_http_auth_header(self.username, 'wrong')
        request = HttpRequest()
        request.META['HTTP_AUTHORIZATION'] = http_auth

        @user_auth
        def some_view(request):
            return HttpResponse('OK')

        response = some_view(request)
        self.assertEqual(response.status_code, 401)
Beispiel #11
0
    def test_return_unauthorized_with_wrong_credentials(self):
        http_authorization = build_http_auth_header(self.user.username, 'wrong')

        response = self.client.post(
            reverse('teams:single_team', kwargs={'team_uuid':self.team.uuid}),
            {'game_uuid':self.game.uuid},
            content_type='application/json',
            HTTP_AUTHORIZATION = http_authorization,
        )

        self.assertEqual(response.status_code, 401)
    def test_auth_with_correct_credentials(self):
        http_auth = build_http_auth_header(self.username, self.password)
        request = HttpRequest()
        request.META['HTTP_AUTHORIZATION'] = http_auth

        @user_auth
        def some_view(request):
            return HttpResponse('OK')

        response = some_view(request)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(request.user)
Beispiel #13
0
    def test_return_404_if_user_has_no_player(self):
        new_user, password = self.create_django_user(username='******')
        http_authorization = build_http_auth_header(new_user.username, password)

        response = self.client.post(
            reverse('teams:single_team', kwargs={'team_uuid':self.team.uuid}),
            {'game_uuid':self.game.uuid},
            content_type='application/json',
            HTTP_AUTHORIZATION = http_authorization,
        )

        self.assertEqual(response.status_code, 404)
Beispiel #14
0
    def test_returns_forbidden_in_case_user_is_already_in_a_game(self):
        player = Player.objects.create(user=self.user, current_game=self.game)

        http_authorization = build_http_auth_header(self.username, self.password)
        response = self.client.post(
            reverse('game_config:game_info', kwargs={'uuid':self.game.uuid}),
            {},
            content_type='application/json',
            HTTP_AUTHORIZATION = http_authorization
        )

        self.assertEqual(response.status_code, 403)
Beispiel #15
0
    def test_return_forbiden_in_case_user_is_already_in_a_game(self):
        game, player = self.create_game_and_player(self.user)

        http_authorization = build_http_auth_header(self.username, self.password)
        response = self.client.post(
            reverse('game_config:root'),
            {"game_name":"name"},
            content_type='application/json',
            HTTP_AUTHORIZATION = http_authorization
        )

        self.assertEqual(response.status_code, 403)
        self.assertEqual(Game.objects.count(), 1)
        self.assertEqual(Player.objects.count(), 1)
Beispiel #16
0
    def test_succefull_response_returns_correct_content(self):
        http_authorization = build_http_auth_header(self.username, self.password)
        response = self.client.post(
            reverse('game_config:root'),
            {"game_name":"name"},
            content_type='application/json',
            HTTP_AUTHORIZATION = http_authorization
        )
        content = json.loads(response.content)

        self.assertTrue(content['game'])
        self.assertTrue(content['delete_game_uri'])
        self.assertTrue(content['game_info_uri'])
        self.assertTrue(content['get_project_uri'])
Beispiel #17
0
    def test_leave_game_if_it_exist_and_player_login(self):
        user, password = self.create_django_user(username='******')
        player = Player.objects.create(user=user, current_game=self.game)

        self.assertTrue(Game.objects.all())
        self.assertTrue(Player.objects.all())

        http_authorization = build_http_auth_header(user.username, password)
        response = self.client.delete(
            reverse('game_config:game_info', kwargs={'uuid':self.game.uuid}),
            HTTP_AUTHORIZATION = http_authorization
        )

        self.assertEqual(response.status_code, 200)
        self.assertTrue(Game.objects.all())
        self.assertFalse(Player.objects.all())
Beispiel #18
0
    def test_404_player_does_not_belong_to_the_game(self):
        user, password = self.create_django_user(username='******')
        game, player = self.create_game_and_player(user, game_name='new_game')

        self.assertTrue(Game.objects.all())
        self.assertTrue(Player.objects.all())

        http_authorization = build_http_auth_header(user.username, password)
        response = self.client.delete(
            reverse('game_config:game_info', kwargs={'uuid':self.game.uuid}),
            HTTP_AUTHORIZATION = http_authorization
        )

        self.assertEqual(response.status_code, 404)
        self.assertTrue(Game.objects.all())
        self.assertTrue(Player.objects.all())
Beispiel #19
0
    def test_creates_new_game_with_corret_credentials_and_game_info(self):
        self.assertFalse(Game.objects.all())
        self.assertFalse(Player.objects.all())

        http_authorization = build_http_auth_header(self.username, self.password)
        response = self.client.post(
            reverse('game_config:root'),
            {"game_name":"name"},
            content_type='application/json',
            HTTP_AUTHORIZATION = http_authorization
        )

        self.assertEqual(response.status_code, 200)
        self.assertTrue(Game.objects.all())
        self.assertTrue(Player.objects.all())
        game = Game.objects.all()[0]
        self.assertTrue(game.creator, self.user)
Beispiel #20
0
    def test_join_game_with_correct_credentials(self):
        self.assertFalse(Player.objects.all())

        http_authorization = build_http_auth_header(self.username, self.password)
        response = self.client.post(
            reverse('game_config:game_info', kwargs={'uuid':self.game.uuid}),
            {},
            content_type='application/json',
            HTTP_AUTHORIZATION = http_authorization
        )
        content = json.loads(response.content)

        self.assertEqual(response.status_code, 200)
        self.assertTrue(Player.objects.all())
        self.assertTrue(content['game'])
        self.assertTrue(content['leave_game_uri'])
        self.assertTrue(content['game_info_uri'])
        self.assertTrue(content['get_project_uri'])
Beispiel #21
0
    def setUp(self):
        self.user, password = self.create_django_user()
        self.game, self.player = self.create_game_and_player(self.user)

        self.http_authorization = build_http_auth_header(self.user.username, password)
Beispiel #22
0
 def setUp(self):
     self.user, password = self.create_django_user()
     self.http_authorization = build_http_auth_header(self.user.username, password)
     self.game, self.player = self.create_game_and_player(self.user)
     self.game_team = GameTeam.objects.create(team=Team.objects.all()[0], player=self.player)