def test_proposed_item_does_not_exist(self, admin_user, thread, charity):
     setup_thread(thread, charity)
     add_break_even_amount(thread)
     thread = Thread.objects.get(id=thread.id)
     thread.extra["proposed_item_id"] = thread.id + 12345678765432
     thread.save(update_fields=["extra"])
     UserVoteFactory.create(thread=thread, direction=True, user=admin_user)
     assert WantedItem.objects.count() == 0
 def test_combined_staff_and_user_should_count(self, thread, admin_user,
                                               charity):
     """Tests that with combined staff and users, merge should happen
     because we need a minimum of 10 people
     """
     setup_thread(thread, charity)
     add_break_even_amount(thread)
     UserVoteFactory.create(thread=thread, direction=True, user=admin_user)
     assert WantedItem.objects.count() == 10
 def test_signal_only_sent_on_staff_vote(self, user, thread, charity):
     """Tests that the signal is only sent on staff vote to avoid DoS.
     This test acts like the vote should win but a staff member
     didn't vote, so the signal doesn't count.
     """
     setup_thread(thread, charity)
     add_break_even_amount(thread)
     UserVoteFactory.create(thread=thread, direction=True, user=user)
     assert WantedItem.objects.count() == 0
    def handle(self, *args, **options):
        if not settings.DEBUG:
            raise Exception("You cannot use this command in production.")
        print("Creating Forum app data.")

        for _ in range(2):
            for thread_type, _ in THREAD_TYPE_CHOICES:
                ThreadFactory.create(type=thread_type)

        for thread in Thread.objects.all():
            MessageFactory.create_batch(randint(6, 30), thread=thread)

        for thread in Thread.objects.filter(type__gt=0):
            UserVoteFactory.create_batch(randint(10, 50), thread=thread)

        print("Finished creating Forum app data.")
 def test_regular_voted_minority(self, admin_user, thread, charity):
     setup_thread(thread, charity)
     UserVoteFactory.create_batch(3, thread=thread, direction=True)
     UserVoteFactory.create_batch(5, thread=thread, direction=False)
     UserVoteFactory.create(thread=thread,
                            direction=True,
                            user=UserFactory.create(is_staff=True))
     UserVoteFactory.create(thread=thread, direction=True, user=admin_user)
     assert WantedItem.objects.count() == 0
 def test_complete_merge(self, admin_user, thread, charity):
     setup_thread(thread, charity)
     UserVoteFactory.create_batch(6, thread=thread, direction=True)
     UserVoteFactory.create_batch(4, thread=thread, direction=False)
     UserVoteFactory.create(thread=thread,
                            direction=True,
                            user=UserFactory.create(is_staff=True))
     assert WantedItem.objects.count() == 0
     UserVoteFactory.create(thread=thread, direction=True, user=admin_user)
     assert WantedItem.objects.count() == 10
     assert ProposedItem.objects.count() == 1
     assert ProposedItem.objects.first().closed is True
Exemple #7
0
def user_vote() -> UserVote:
    return UserVoteFactory()
 def test_not_enough_staff_votes(self, admin_user, thread, charity):
     setup_thread(thread, charity)
     UserVoteFactory.create_batch(4, thread=thread, direction=True)
     UserVoteFactory.create_batch(4, thread=thread, direction=False)
     UserVoteFactory.create(thread=thread, direction=True, user=admin_user)
     assert WantedItem.objects.count() == 0
def add_break_even_amount(thread):
    UserVoteFactory.create_batch(4, thread=thread, direction=True)
    UserVoteFactory.create_batch(4, thread=thread, direction=False)
    UserVoteFactory.create(thread=thread,
                           direction=True,
                           user=UserFactory.create(is_staff=True))