Exemplo n.º 1
0
def test_user_count(settings):
    """A basic test to execute the get_users_count Celery task."""
    UserFactory.create_batch(3)
    settings.CELERY_TASK_ALWAYS_EAGER = True
    task_result = get_users_count.delay()
    assert isinstance(task_result, EagerResult)
    assert task_result.result == 3
Exemplo n.º 2
0
def fakeit():
    conference = ConferenceFactory()

    USERS_NUMBER = random.randint(10, 50)
    SUBMISSION_NUMBER = int(USERS_NUMBER * 0.4)
    users = UserFactory.create_batch(USERS_NUMBER)

    submissions = SubmissionFactory.create_batch(SUBMISSION_NUMBER,
                                                 conference=conference)

    counts_votes = {}
    for submission in submissions:
        counts_votes[submission.pk] = 0
    for user in users:
        i_vote_only = random.randint(0, len(submissions))
        submission_to_vote = random.sample(submissions, k=i_vote_only)
        for submission in submission_to_vote:
            # make more realistic: skip some voting...
            if bool(random.getrandbits(1)):
                continue

            value = get_random_vote()
            VoteFactory(user=user, value=value, submission=submission)
            counts_votes[submission.pk] += value

    return conference, counts_votes
Exemplo n.º 3
0
    def test_can_view_bookings_from_other_group_with_perm(self, mock_has_perm):
        mock_has_perm.return_value = True

        event = EventFactory()
        users = UserFactory.create_batch(2)
        self.client.force_login(users[0])
        for group_slug, group in zip(
            ["all", users[1].group.slug], [None, users[1].group]
        ):
            response = self.client.get(
                reverse(
                    "booking:event_games_group",
                    kwargs={
                        "event_slug": event.slug,
                        "group_slug": group_slug,
                    },
                ),
                follow=True,
            )
            self.assertEqual(
                response.context["current_group"],
                group,
                "the rendered group is not the requested group",
            )
            self.assertTemplateUsed(response, "booking/event/event.html")
            mock_has_perm.assert_any_call(
                users[0], "booking.view_others_groups_bookings", None
            )
Exemplo n.º 4
0
    def setUp(self):
        self.client = Client(schema)

        self.main_event = Event.objects.create(
            title="Pycon 2019 - GraphQL Workshop",
            description="Descripción del evento",
            invitee_capacity=100,
            event_day=date(2019, 2, 10),
            initial_hour="13:00",
            end_hour="15:00",
            place_name="Universidad Javeriana",
            latitude='4.62844',
            longitude='-74.06508',
            zoom=19,
        )
        self.main_user = User.objects.create(
            first_name="Jhon",
            last_name="Doe",
            email="*****@*****.**",
            profile_image="/profile/image.png",
            profile="This is the profile John Doe",
            username="******")
        self.main_organization = Organization.objects.create(
            title="Python Bogotá", description="Python Bogotá description")
        self.platform_users = UserFactory.create_batch(10)
        for user in self.platform_users:
            self.main_event.enroll_user(user)
Exemplo n.º 5
0
def set_up_many(num_instances):
    """Set up many instances."""
    users = UserFactory.create_batch(num_instances)
    artists = ArtistFactory.create_batch(num_instances)
    festivals = FestivalFactory.create_batch(num_instances, artists=artists)
    ranking_sets = []
    rankings = []
    reviews = []
    genres = []
    for user in users:
        for festival in festivals:
            ranking_set = RankingSetFactory.create(festival=festival, user=user)
            ranking_sets.append(ranking_set)
            for artist in artists:
                ranking = RankingFactory.create(ranking_set=ranking_set, artist=artist)
                rankings.append(ranking)

                review = ReviewFactory.create(user=user, artist=artist, festival=festival)
                reviews.append(review)

                genre = GenreFactory.create(review=review)
                genres.append(genre)
    return {'users': users,
            'artists': artists,
            'festivals': festivals,
            'ranking_sets': ranking_sets,
            'rankings': rankings,
            'reviews': reviews,
            'genres': genres}
Exemplo n.º 6
0
 def test_defaults_to_group_from_user(self):
     event = EventFactory()
     users = UserFactory.create_batch(5)
     self.client.force_login(users[2])
     response = self.client.get(event.get_absolute_url(), follow=True)
     self.assertEqual(
         response.context["current_group"],
         users[2].group,
         "the rendered group is not the user's own group",
     )
     self.assertTemplateUsed(response, "booking/event/event.html")
Exemplo n.º 7
0
 def test_exception_if_user_has_no_group_and_no_perm(self):
     event = EventFactory()
     users = UserFactory.create_batch(5)
     user_without_group = UserFactory(group=None)
     self.client.force_login(user_without_group)
     response = self.client.get(event.get_absolute_url(), follow=True)
     self.assertTemplateUsed(response, "jeugdraad/alert.html")
     self.assertEqual(
         response.context["message"],
         "You are not assigned to a group. Please contact a board member to resolve "
         "this issue.",
     )
Exemplo n.º 8
0
    def test_defaults_to_all_if_user_has_no_group_and_perm(self, mock_has_perm):
        mock_has_perm.return_value = True

        event = EventFactory()
        users = UserFactory.create_batch(5)
        user_without_group = UserFactory(group=None)
        self.client.force_login(user_without_group)
        response = self.client.get(event.get_absolute_url(), follow=True)
        self.assertEqual(
            response.context["current_group"], None, "the rendered group is not 'all'"
        )
        self.assertTemplateUsed(response, "booking/event/event.html")
        mock_has_perm.assert_any_call(
            user_without_group, "booking.view_others_groups_bookings", None
        )
 def setUp(self):
     self.main_event = Event.objects.create(
         title="Pycon 2019 - GraphQL Workshop",
         description="Descripción del evento",
         invitee_capacity=100,
         event_day=timezone.now().date(),
         initial_hour="13:00",
         end_hour="15:00",
         place_name="Universidad Javeriana",
         latitude='4.62844',
         longitude='-74.06508',
         zoom=19,
     )
     self.platform_users = UserFactory.create_batch(10)
     for user in self.platform_users:
         self.main_event.enroll_user(user)
Exemplo n.º 10
0
 def test_cannot_view_bookings_from_other_group(self):
     event = EventFactory()
     users = UserFactory.create_batch(2)
     self.client.force_login(users[0])
     for group_slug in ["all", users[1].group.slug]:
         response = self.client.get(
             reverse(
                 "booking:event_games_group",
                 kwargs={"event_slug": event.slug, "group_slug": group_slug},
             ),
             follow=True,
         )
         # The view should default to the users own group
         self.assertEqual(
             response.context["current_group"],
             users[0].group,
             "the rendered group is not the user's own group",
         )
         self.assertTemplateUsed(response, "booking/event/event.html")
Exemplo n.º 11
0
def users():
    return UserFactory.create_batch(3)
Exemplo n.º 12
0
    def test_users_displayed(self):
        UserFactory.create_batch(2)

        response = self.client.get("/users/")
        self.assertContains(response, "user")