def test_conflict_resolution_notifications(self): user1, user2, user3 = UserFactory(), UserFactory(), UserFactory() group = GroupFactory(members=[user1, user2, user3]) Notification.objects.all().delete() issue = IssueFactory(group=group, created_by=user1, affected_user=user2) notifications = Notification.objects.order_by('type') self.assertEqual(notifications.count(), 2) self.assertEqual( notifications[1].type, NotificationType.CONFLICT_RESOLUTION_CREATED_ABOUT_YOU.value) self.assertEqual(notifications[1].user, user2) self.assertEqual(notifications[1].context, { 'issue': issue.id, 'group': group.id, 'user': user2.id }) self.assertEqual(notifications[0].type, NotificationType.CONFLICT_RESOLUTION_CREATED.value) self.assertEqual(notifications[0].user, user3) # keep discussing Notification.objects.all().delete() voting = issue.latest_voting() vote_for_further_discussion(voting=voting, user=user1) with fast_forward_to_voting_expiration(voting): process_expired_votings() notifications = Notification.objects.order_by('type') self.assertEqual(notifications.count(), 3) self.assertEqual(notifications[0].type, NotificationType.CONFLICT_RESOLUTION_CONTINUED.value) self.assertEqual(notifications[1].type, NotificationType.CONFLICT_RESOLUTION_CONTINUED.value) self.assertEqual( notifications[2].type, NotificationType.CONFLICT_RESOLUTION_CONTINUED_ABOUT_YOU.value) # remove user Notification.objects.all().delete() voting = issue.latest_voting() vote_for_remove_user(voting=voting, user=user1) with fast_forward_to_voting_expiration(voting): process_expired_votings() notifications = Notification.objects.order_by('type') self.assertEqual(notifications.count(), 3) self.assertEqual([n.type for n in notifications], [ NotificationType.CONFLICT_RESOLUTION_DECIDED.value, NotificationType.CONFLICT_RESOLUTION_DECIDED.value, NotificationType.CONFLICT_RESOLUTION_YOU_WERE_REMOVED.value, ])
def test_delete_vote(self): member = VerifiedUserFactory() member2 = VerifiedUserFactory() group = GroupFactory(members=[member, member2]) issue = IssueFactory(group=group, affected_user=member2, created_by=member) vote_for_further_discussion(voting=issue.latest_voting(), user=member) client = self.connect_as(member) issue.latest_voting().delete_votes(user=member) messages = client.messages_by_topic self.assertEqual(len(client.messages), 1) self.assertEqual(len(messages['issues:issue']), 1)
def test_create_voting_ends_soon_notifications(self): creator, affected_user, voter = UserFactory(), UserFactory(), UserFactory() group = GroupFactory(members=[creator, affected_user, voter]) issue = IssueFactory(group=group, created_by=creator, affected_user=affected_user) voting = issue.latest_voting() # let's vote with user "voter" vote_for_further_discussion(voting=voting, user=voter) Notification.objects.all().delete() with fast_forward_just_before_voting_expiration(voting): create_voting_ends_soon_notifications() # can call it a second time without duplicating notifications create_voting_ends_soon_notifications() notifications = Notification.objects.filter(type=NotificationType.VOTING_ENDS_SOON.value) # user "voter" is not being notified self.assertEqual( sorted([n.user_id for n in notifications]), sorted([issue.affected_user_id, issue.created_by_id]) )