def challenge_set(): """ Creates a challenge with creator, 2 participants, and non participant. To use this you must mark the test with @pytest.mark.django_db """ ChallengeSet = namedtuple( 'ChallengeSet', [ 'challenge', 'creator', 'admin', 'participant', 'participant1', 'non_participant', ], ) creator = UserFactory() challenge = ChallengeFactory(creator=creator) admin = UserFactory() challenge.add_admin(admin) participant = UserFactory() challenge.add_participant(participant) participant1 = UserFactory() challenge.add_participant(participant1) non_participant = UserFactory() try: Challenge.objects.get(short_name=settings.MAIN_PROJECT_NAME) except ObjectDoesNotExist: ChallengeFactory(short_name=settings.MAIN_PROJECT_NAME) return ChallengeSet( challenge, creator, admin, participant, participant1, non_participant )
def test_notification_for_new_admin_only(): user = UserFactory() admin = UserFactory() challenge = ChallengeFactory(creator=admin) # clear existing notifications for easier testing below Notification.objects.all().delete() # add user as admin to challenge challenge.add_admin(user) assert Notification.objects.count() == 1 assert Notification.objects.get().user == user assert Notification.objects.get().user != admin
def test_non_posters_notified(group): p = UserFactory() u = UserFactory() c = ChallengeFactory() c.add_admin(user=p) add_method = getattr(c, f"add_{group}") add_method(user=u) TopicFactory(forum=c.forum, poster=p, type=Topic.TOPIC_ANNOUNCE) assert u.user_profile.has_unread_notifications is True assert p.user_profile.has_unread_notifications is False
def generate_challenge_set(): creator = UserFactory() challenge = ChallengeFactory(creator=creator) admin = UserFactory() challenge.add_admin(admin) participant = UserFactory() challenge.add_participant(participant) participant1 = UserFactory() challenge.add_participant(participant1) non_participant = UserFactory() return ChallengeSet( challenge=challenge, creator=creator, admin=admin, participant=participant, participant1=participant1, non_participant=non_participant, )
def generate_challenge_set(): creator = UserFactory() challenge = ChallengeFactory(creator=creator) admin = UserFactory() challenge.add_admin(admin) participant = UserFactory() challenge.add_participant(participant) participant1 = UserFactory() challenge.add_participant(participant1) non_participant = UserFactory() try: Challenge.objects.get(short_name=settings.MAIN_PROJECT_NAME) except ObjectDoesNotExist: ChallengeFactory(short_name=settings.MAIN_PROJECT_NAME) return ChallengeSet( challenge=challenge, creator=creator, admin=admin, participant=participant, participant1=participant1, non_participant=non_participant, )