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_removed_member_cannot_access_issue(self): issue = self.create_issue(affected_user=self.affected_member) vote_for_remove_user(voting=issue.latest_voting(), user=issue.created_by) with self.fast_forward_to_voting_expiration(issue.latest_voting()): process_expired_votings() self.client.force_login(user=self.affected_member) # cannot access issue response = self.get_results('/api/issues/{}/'.format(issue.id)) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND, response.data) # cannot access conversation response = self.get_results('/api/conversations/{}/'.format( issue.conversation.id)) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND, response.data)
def test_cannote_change_and_delete_vote_in_cancelled_issue(self): issue = self.create_issue(affected_user=self.affected_member) voting = issue.votings.first() vote_for_remove_user(voting=voting, user=issue.created_by) self.client.force_login(user=issue.affected_user) response = self.client.post('/api/groups/{}/leave/'.format( issue.group.id)) self.assertEqual(response.status_code, status.HTTP_200_OK) self.client.force_login(user=issue.created_by) response = self.vote_via_API(issue) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN, response.data) response = self.delete_vote_via_API(issue) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN, response.data)