Example #1
0
    def test_clan_detail_view(self):
        """TEST VIEW ClanView OK (GET): Get GameClan"""
        new_user = User.objects.create(username=f'Test1',
                                       password='******',
                                       game=self.game)
        clan = GameClan.create(creator=new_user,
                               name='TEST1',
                               description='TEST',
                               game=self.game)
        clan = GameClan.create(creator=self.user,
                               name='TEST',
                               description='TEST',
                               game=self.game)
        url = reverse('clan')
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        response = self.client.get(url + '?id=2', )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
Example #2
0
    def test_clan_remove_invalid__user_not_in_user_clan(self):
        """TEST VIEW RemoveClanMemberView BAD REQUEST (POST): Removing User from the GameClan,
            But User in another GameClan"""
        clan = GameClan.create(creator=self.user,
                               name='TEST',
                               description='TEST',
                               game=self.game)
        new_user = User.objects.create(username='******',
                                       password='******',
                                       game=self.game)
        clan = GameClan.create(creator=new_user,
                               name='TEST1',
                               description='TEST',
                               game=self.game)

        url = reverse('clan-remove-member')
        param = f'?member_id={new_user.id}'
        response = self.client.post(url + param)
        self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)
Example #3
0
    def setUp(self):
        self.game = Game.objects.create(game='Test', slug='test')
        self.user = User.objects.create(username='******',
                                        password='******',
                                        game=self.game)
        self.clan = GameClan.create(name='TEST',
                                    description='Test',
                                    game=self.game,
                                    creator=self.user)

        self.client = APIClient()
        self.client.force_authenticate(user=self.user)
Example #4
0
    def test_clan_remove_invalid__user_not_exists(self):
        """TEST VIEW RemoveClanMemberView BAD REQUEST (POST): Removing User from the GameClan,
            But User not exists"""
        clan = GameClan.create(creator=self.user,
                               name='TEST',
                               description='TEST',
                               game=self.game)

        url = reverse('clan-remove-member')
        param = f'?member_id=10'
        response = self.client.post(url + param)
        self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)
Example #5
0
    def test_clan_delete(self):
        """TEST VIEW DeleteClanView OK (POST): Delete GameClan"""
        new_user = User.objects.create(username=f'Test1',
                                       password='******',
                                       game=self.game)
        clan = GameClan.create(creator=self.user,
                               name='TEST',
                               description='TEST',
                               game=self.game)

        url = reverse('clan-delete')
        data = {}
        response = self.client.post(url, data)
        self.assertEqual(status.HTTP_200_OK, response.status_code)
Example #6
0
    def test_clan_update__invalid_user(self):
        """TEST VIEW UpdateClanView BAD REQUEST (POST): Update GameClan, But not from creator"""
        new_user = User.objects.create(username=f'Test1',
                                       password='******',
                                       game=self.game)
        clan = GameClan.create(creator=new_user,
                               name='TEST1',
                               description='TEST',
                               game=self.game)

        url = reverse('clan-update')
        data = {'name': 'Test1', 'description': 'TEST!', 'max_members': 2}
        response = self.client.post(url, data)
        self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)
Example #7
0
    def test_clan_remove_member(self):
        """TEST VIEW RemoveClanMember OK (POST): Remove User from the GameClan"""
        clan = GameClan.create(creator=self.user,
                               name='TEST',
                               description='TEST',
                               game=self.game)
        new_user = User.objects.create(username='******',
                                       password='******',
                                       game=self.game)
        clan.add(new_user)

        url = reverse('clan-remove-member')
        param = f'?member_id={new_user.id}'
        response = self.client.post(url + param)
        self.assertEqual(status.HTTP_200_OK, response.status_code)
Example #8
0
    def test_creating_clan__invalid_creator(self):
        """TEST VIEW ClanListView BAD REQUEST (GET): Create clan, But creator must be UNIQUE and have a game"""
        clan = GameClan.create(creator=self.user,
                               name='TEST',
                               description='TEST',
                               game=self.game)

        url = reverse('clan-create')
        data = {"name": 'Test1', "description": "TestClan"}

        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

        new_client = APIClient()
        new_client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Example #9
0
    def test_clan_update(self):
        """TEST VIEW UpdateClanView OK (POST): Update GameClan"""
        clan = GameClan.create(creator=self.user,
                               name='TEST1',
                               description='TEST',
                               game=self.game)

        url = reverse('clan-update')
        data = {'name': 'Test1', 'description': 'TEST!', 'max_members': 2}
        response = self.client.post(url, data)
        clan.refresh_from_db()

        self.assertEqual(status.HTTP_200_OK, response.status_code)
        self.assertEqual(data['name'], clan.name)
        self.assertEqual(data['description'], clan.description)
        self.assertEqual(data['max_members'], clan.max_members)
Example #10
0
    def test_creating_clan__invalid_name(self):
        """TEST VIEW ClanListView BAD REQUEST (GET): Create clan if name not UNIQUE"""
        clan_name = 'CLAN'
        new_user = User.objects.create(username=f'Test1',
                                       password='******',
                                       game=self.game)
        clan = GameClan.create(creator=new_user,
                               name=f'{clan_name}',
                               description='TEST',
                               game=self.game)

        url = reverse('clan-create')
        data = {"name": clan_name, "description": "TestClan"}

        response = self.client.post(url, data, format='json')

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Example #11
0
    def test_clan_list(self):
        """TEST VIEW ClanListView OK (GET): Get list of all clans"""
        n = 5
        users = [
            User.objects.create(username=f'Test{index}',
                                password='******',
                                game=self.game) for index in range(n)
        ]
        clans = [
            GameClan.create(creator=user,
                            name=f'{user.username} Clan',
                            description='TEST',
                            game=self.game) for user in users
        ]

        url = reverse('clans')
        response = self.client.get(url)
        self.assertEqual(n, len(response.data))