Ejemplo n.º 1
0
 def test_group_id_not_in_request(self):
     """Correct error returned when group_id isn't in request."""
     response = views.handle_group_subscription(self.request, 'subscribe')
     content = loads(response.content)
     self.assertFalse(content['success'])
     self.assertEqual(content['message'], "Requested group doesn't exist.")
     self.assertEqual(content['group_id'], -1)
Ejemplo n.º 2
0
 def test_group_id_not_in_request(self):
     """Correct error returned when group_id isn't in request."""
     response = views.handle_group_subscription(self.request, 'subscribe')
     content = loads(response.content)
     self.assertFalse(content['success'])
     self.assertEqual(content['message'], "Requested group doesn't exist.")
     self.assertEqual(content['group_id'], -1)
Ejemplo n.º 3
0
 def test_group_does_not_exist(self):
     """Correct error is returned when group_id doesn't match a group."""
     self.assertFalse(Group.objects.filter(pk=99999).exists())
     request = self.request_factory.post('/', {'group_id': 99999})
     request.user = self.user1
     response = views.handle_group_subscription(request, 'subscribe')
     content = loads(response.content)
     self.assertFalse(content['success'])
     self.assertEqual(content['message'], "Requested group doesn't exist.")
     self.assertEqual(content['group_id'], '99999')
Ejemplo n.º 4
0
 def test_group_does_not_exist(self):
     """Correct error is returned when group_id doesn't match a group."""
     self.assertFalse(Group.objects.filter(pk=99999).exists())
     request = self.request_factory.post('/', {'group_id': 99999})
     request.user = self.user1
     response = views.handle_group_subscription(request, 'subscribe')
     content = loads(response.content)
     self.assertFalse(content['success'])
     self.assertEqual(content['message'], "Requested group doesn't exist.")
     self.assertEqual(content['group_id'], '99999')
Ejemplo n.º 5
0
 def test_subscribe_to_non_private_group(self):
     """Correct response when joining a non-private group."""
     request = self.request_factory.post('/', {'group_id': self.group.pk})
     request.user = self.user1
     response = views.handle_group_subscription(request, 'subscribe')
     content = loads(response.content)
     self.assertTrue(content['success'])
     self.assertEqual(
         content['message'],
         '<div>Successfully joined %s.</div>' % self.group.group.name)
     self.assertEqual(content['group_id'], self.group.pk)
Ejemplo n.º 6
0
 def test_unsubscribe(self):
     """Correct response when unsubscribing from a group."""
     self.user1.add_to_group(self.group.pk)
     request = self.request_factory.post('/', {'group_id': self.group.pk})
     request.user = self.user1
     response = views.handle_group_subscription(request, 'unsubscribe')
     content = loads(response.content)
     self.assertTrue(content['success'])
     self.assertEqual(
         content['message'],
         'Successfully unsubscribed from %s.' % self.group.group.name)
     self.assertEqual(content['group_id'], self.group.pk)
Ejemplo n.º 7
0
 def test_subscribe_to_non_private_group(self):
     """Correct response when joining a non-private group."""
     request = self.request_factory.post('/', {'group_id': self.group.pk})
     request.user = self.user1
     response = views.handle_group_subscription(request, 'subscribe')
     content = loads(response.content)
     self.assertTrue(content['success'])
     self.assertEqual(
         content['message'],
         '<div>Successfully joined %s.</div>' % self.group.group.name
     )
     self.assertEqual(content['group_id'], self.group.pk)
Ejemplo n.º 8
0
 def test_unsubscribe(self):
     """Correct response when unsubscribing from a group."""
     self.user1.add_to_group(self.group.pk)
     request = self.request_factory.post('/', {'group_id': self.group.pk})
     request.user = self.user1
     response = views.handle_group_subscription(request, 'unsubscribe')
     content = loads(response.content)
     self.assertTrue(content['success'])
     self.assertEqual(
         content['message'],
         'Successfully unsubscribed from %s.' % self.group.group.name
     )
     self.assertEqual(content['group_id'], self.group.pk)
Ejemplo n.º 9
0
 def test_subscribe_to_private_group(self):
     """Correct response when requesting membership to a private group."""
     private_group = Group.objects.create(name='Private group', private=True)
     request = self.request_factory.post('/', {'group_id': private_group.pk})
     request.user = self.user1
     response = views.handle_group_subscription(request, 'subscribe')
     content = loads(response.content)
     self.assertTrue(content['success'])
     self.assertEqual(
         content['message'],
         'Your request to join Private group has been received.'
     )
     self.assertEqual(content['group_id'], private_group.pk)
Ejemplo n.º 10
0
 def test_subscribe_to_private_group(self):
     """Correct response when requesting membership to a private group."""
     private_group = Group.objects.create(name='Private group',
                                          private=True)
     request = self.request_factory.post('/',
                                         {'group_id': private_group.pk})
     request.user = self.user1
     response = views.handle_group_subscription(request, 'subscribe')
     content = loads(response.content)
     self.assertTrue(content['success'])
     self.assertEqual(
         content['message'],
         'Your request to join Private group has been received.')
     self.assertEqual(content['group_id'], private_group.pk)