def test_unsubscribe_from_thread(self): thread = self.group.conversation.messages.create(author=self.user, content='foo') self.group.conversation.messages.create(author=self.user, content='foo reply', thread=thread) token = generate_token(self.user, self.group, thread=thread) participant = thread.participants.filter(user=self.user) self.assertFalse(participant.get().muted) self.client.post(self.url.format(token), {'choice': 'thread'}, format='json') self.assertTrue(participant.get().muted)
def test_with_notification_types(self): token = generate_token( self.user, self.group, notification_type=GroupNotificationType.DAILY_PICKUP_NOTIFICATION) data = parse_token(token) self.assertEqual(data['notification_type'], 'daily_pickup_notification')
def test_with_a_conversation(self): token = generate_token(self.user, self.group, conversation=self.group.conversation) data = parse_token(token) self.assertEqual(self.user, data['user']) self.assertEqual(self.group, data['group']) self.assertEqual(self.group.conversation, data['conversation'])
def test_with_a_thread(self): thread = self.group.conversation.messages.create(author=self.user, content='foo') self.group.conversation.messages.create(author=self.user, content='foo reply', thread=thread) token = generate_token(self.user, self.group, thread=thread) data = parse_token(token) self.assertEqual(self.user, data['user']) self.assertEqual(self.group, data['group']) self.assertEqual(thread, data['thread'])
def test_unsubscribe_from_notification_type(self): token = generate_token( self.user, group=self.group, notification_type=GroupNotificationType.NEW_APPLICATION, ) notification_types = self.group.groupmembership_set.filter(user=self.user).values_list( 'notification_types', flat=True, ) self.assertIn('new_application', notification_types.get()) self.client.post(self.url.format(token), {'choice': 'notification_type'}, format='json') self.assertNotIn('new_application', notification_types.get())
def unsubscribe_url(user, group=None, conversation=None, thread=None, notification_type=None): return '{hostname}/#/unsubscribe/{token}'.format( hostname=settings.HOSTNAME, token=generate_token( user, group=group, conversation=conversation, thread=thread, notification_type=notification_type, ), )
def test_fails_without_a_group(self): token = generate_token(self.user, conversation=self.group.conversation) response = self.client.post(self.url.format(token), {'choice': 'group'}, format='json') self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data)
def test_does_not_unsubscribe_from_other_group(self): token = generate_token(self.user, self.group) participant = self.other_group.conversation.conversationparticipant_set.filter(user=self.user) self.assertFalse(participant.get().muted) self.client.post(self.url.format(token), {'choice': 'group'}, format='json') self.assertFalse(participant.get().muted)
def test_unsubscribe_from_conversation(self): participant = self.group.conversation.conversationparticipant_set.filter(user=self.user) token = generate_token(self.user, self.group, conversation=self.group.conversation) self.assertFalse(participant.get().muted) self.client.post(self.url.format(token), {'choice': 'conversation'}, format='json') self.assertTrue(participant.get().muted)