예제 #1
0
    def setUp(self):
        self.event = self.tenant
        self.team_admin = UserProfileFactory()
        self.applicant = UserProfileFactory()
        self.team = TeamFactory(at_event=self.event, members={self.team_admin})

        # The "applicant" is requesting a place on "team".
        self.client.force_login(self.applicant.user)
        response = self.client.post(
            reverse('request', kwargs={'team_id': self.team.id}),
            json.dumps({}),
            content_type='application/json',
        )
        self.assertEqual(response.status_code, 200)
예제 #2
0
    def setUp(self):
        self.event = self.tenant
        self.team_admin = UserProfileFactory()
        self.invitee = UserProfileFactory()
        self.team = TeamFactory(at_event=self.event, members={self.team_admin})

        # Create an invite for the "invitee" user using the "team_admin" account.
        self.client.force_login(self.team_admin.user)
        response = self.client.post(
            reverse('invite', kwargs={'team_id': self.team.id}),
            json.dumps({
                'user': self.invitee.id
            }),
            content_type='application/json',
        )
        self.assertEqual(response.status_code, 200)
예제 #3
0
    def test_one_team_per_member_per_event(self):
        event = self.tenant
        teams = TeamFactory.create_batch(2, at_event=event)
        user = UserProfileFactory()

        with self.assertRaises(ValidationError):
            teams[0].members.add(user)
            teams[1].members.add(user)
예제 #4
0
    def test_max_team_size(self):
        event = self.tenant
        event.max_team_size = 2
        event.save()
        team  = TeamFactory(at_event=event)

        # Add 3 users to a team when that max is less than that.
        self.assertLess(event.max_team_size, 3)
        users = UserProfileFactory.create_batch(3)

        with self.assertRaises(ValidationError):
            for user in users:
                team.members.add(user)
예제 #5
0
    def test_team_create(self):
        creator = UserProfileFactory()
        team_template = TeamFactory.build()

        self.client.force_login(creator.user)
        response = self.client.post(
            reverse('create_team'),
            {
                'name': team_template.name,
            },
        )
        self.assertEqual(response.status_code, 302)
        team = Team.objects.get(name=team_template.name)
        self.assertTrue(creator in team.members.all())
예제 #6
0
    def test_search_create_with_logged_in_user(self):
        url = reverse("search:api_search")
        response = self.client.post(
            url,
            {
                "search_type":
                0,
                "search_terms":
                "Test text",
                "search_results": [
                    "https://google.com/1",
                    "https://google.com/2",
                ],
            },
        )
        self.assertEqual(response.status_code, 200)
        count = Search.objects.count()
        self.assertEqual(count, 1)

        # Login
        user_data = {"email": "*****@*****.**", "password": "******"}
        user = UserProfileFactory(**user_data)
        resp = self.client.post(reverse("token_obtain_pair"), user_data)
        token = resp.data["token"]
        # pylint: disable=no-member
        self.client.credentials(HTTP_AUTHORIZATION="Bearer " + token)
        self.client.post(
            url,
            {
                "search_type":
                0,
                "search_terms":
                "Test text",
                "search_results": [
                    "https://google.com/2",
                    "https://google.com/3",
                    "https://google.com/4",
                ],
            },
        )
        count = Search.objects.count()
        self.assertEqual(count, 2)
        search = Search.objects.last()
        self.assertEqual(search.user_id, user.id)
        self.assertEqual(search.search_results.count(), 3)
        self.assertEqual(Result.objects.count(), 4)
예제 #7
0
    def test_request_accept(self):
        self.client.force_login(self.team_admin.user)
        response = self.client.post(
            reverse('acceptrequest', kwargs={'team_id': self.team.id}),
            json.dumps({
                'user': self.applicant.id
            }),
            content_type='application/json',
        )
        self.assertEqual(response.status_code, 200)
        self.assertTrue(self.applicant in self.team.members.all())
        self.assertFalse(self.applicant in self.team.requests.all())

        # Now try to send a request to the full team
        self.event.max_team_size = 2
        self.event.save()
        applicant2 = UserProfileFactory()
        self.client.force_login(applicant2.user)
        response = self.client.post(
            reverse('request', kwargs={'team_id': self.team.id}),
            json.dumps({}),
            content_type='application/json',
        )
        self.assertEqual(response.status_code, 400)
        self.assertFalse(applicant2 in self.team.members.all())
        self.assertFalse(applicant2 in self.team.requests.all())

        # Now bypass the request mechanism to add a request anyway and
        # check it can't be accepted
        self.team.requests.add(applicant2)
        self.client.force_login(self.team_admin.user)
        response = self.client.post(
            reverse('acceptrequest', kwargs={'team_id': self.team.id}),
            json.dumps({
                'user': applicant2.id
            }),
            content_type='application/json',
        )
        self.assertEqual(response.status_code, 400)
        self.assertFalse(applicant2 in self.team.members.all())
        # Finally check we cleaned up the request after failing
        self.assertFalse(applicant2 in self.team.requests.all())
예제 #8
0
    def test_invite_accept(self):
        self.client.force_login(self.invitee.user)
        response = self.client.post(
            reverse('acceptinvite', kwargs={'team_id': self.team.id}),
            json.dumps({}),
            content_type='application/json',
        )
        self.assertEqual(response.status_code, 200)
        self.assertTrue(self.invitee in self.team.members.all())
        self.assertFalse(self.invitee in self.team.invites.all())

        # Now try to invite to a full team
        self.event.max_team_size = 2
        self.event.save()
        invitee2 = UserProfileFactory()
        self.client.force_login(self.invitee.user)
        response = self.client.post(
            reverse('invite', kwargs={'team_id': self.team.id}),
            json.dumps({
                'user': invitee2.id
            }),
            content_type='application/json',
        )
        self.assertEqual(response.status_code, 400)
        self.assertFalse(invitee2 in self.team.members.all())
        self.assertFalse(invitee2 in self.team.invites.all())

        # Now bypass the invitation mechanism to add an invite anyway and
        # check it can't be accepted
        self.team.invites.add(invitee2)
        self.client.force_login(invitee2.user)
        response = self.client.post(
            reverse('acceptinvite', kwargs={'team_id': self.team.id}),
            json.dumps({}),
            content_type='application/json',
        )
        self.assertEqual(response.status_code, 400)
        self.assertFalse(invitee2 in self.team.members.all())
        # Finally check we cleaned up the invite after failing
        self.assertFalse(invitee2 in self.team.invites.all())
예제 #9
0
파일: tests.py 프로젝트: fish-face/hunter2
 def test_user_profile_factory_default_construction(self):
     UserProfileFactory.create()