def test_images_from_a_banned_user_are_visible_to_banned_user(self): """Images posted by banned members are visible to the banned member.""" banned_user = self.create_user(is_banned=True) group = self.create_group() banned_user.add_to_group(group.pk) thread = self.create_thread(group=group) message = mommy.make('connectmessages.Message', thread=thread, sender=banned_user) # Create and attach a new image image1 = Image() image1.user = message.sender image1.image = File(open(self.smallfile)) image1.save() message.images.add(image1) self.login(banned_user) result = self.client.get( reverse('group_images', kwargs={'group_id': group.pk})) self.assertIn(image1, result.context['images'])
def get_in_memory_image_instance(user): """Returns an instance of Image with an in-memory image.""" image = Image() image.image = get_in_memory_image_file() image.user = user image.save() return image
def test_images_from_a_banned_user_are_visible_to_banned_user(self): """Images posted by banned members are visible to the banned member.""" banned_user = self.create_user(is_banned=True) group = mommy.make(Group) banned_user.add_to_group(group.pk) self.user2.add_to_group(group.pk) # Create a new thread and message thread = mommy.make('connectmessages.Thread', group=group) message = mommy.make('connectmessages.Message', thread=thread, sender=banned_user) # Create and attach a new image image1 = Image() image1.user = message.sender image1.image = File(open(self.smallfile)) image1.save() message.images.add(image1) client = Client() client.post(reverse('login'), { 'username': banned_user.email, 'password': '******' }) result = client.get( reverse('group_images', kwargs={'group_id': group.pk})) self.assertIn(image1, result.context['images'])
def test_images_from_a_banned_user_are_visible_to_banned_user(self): """Images posted by banned members are visible to the banned member.""" banned_user = self.create_user(is_banned=True) group = mommy.make(Group) banned_user.add_to_group(group.pk) self.user2.add_to_group(group.pk) # Create a new thread and message thread = mommy.make('connectmessages.Thread', group=group) message = mommy.make( 'connectmessages.Message', thread=thread, sender=banned_user) # Create and attach a new image image1 = Image() image1.user = message.sender image1.image = File(open(self.smallfile)) image1.save() message.images.add(image1) client = Client() client.post( reverse('login'), {'username': banned_user.email, 'password': '******'} ) result = client.get( reverse('group_images', kwargs={'group_id': group.pk})) self.assertIn(image1, result.context['images'])
def get_image(self, filename): """Returns the specified image.""" path = os.path.join(self.path, filename) image = Image() image.image = File(open(path)) image.user = self.create_user() image.save(process=False) return image
def get_image(self, filename): """Returns the specified image.""" path = os.path.join(self.path, filename) image = Image() image.image = File(open(path)) image.user = self.create_user() image.save(process=False) return image
def test_with_user_no_images_from_banned_users(self): """Images from banned users shouldn't be present.""" # Create a new thread and message thread = mommy.make('connectmessages.Thread', group=self.group) message = mommy.make( 'connectmessages.Message', thread=thread, sender=self.banned_user) # Create and attach a new image image1 = Image() image1.user = message.sender image1.image = File(open(self.smallfile)) image1.save() message.images.add(image1) result = self.client.get(reverse('admin_gallery')) self.assertEqual(result.status_code, 200) self.assertNotIn(image1, result.context['images'])
def test_with_user_no_images_from_banned_users(self): """Images from banned users shouldn't be present.""" # Create a new thread and message thread = mommy.make('connectmessages.Thread', group=self.group) message = mommy.make( 'connectmessages.Message', thread=thread, sender=self.banned_user) # Create and attach a new image image1 = Image() image1.user = message.sender image1.image = File(open(self.smallfile)) image1.save() message.images.add(image1) result = self.client.get(reverse('admin_gallery')) self.assertEqual(result.status_code, 200) self.assertNotIn(image1, result.context['images'])
def test_moderated_messages_properly_appear(self): """ Test that messages appear differently to different users depending on the message's moderation status """ # Create a new group group = mommy.make(Group) self.user1.add_to_group(group.pk) self.user2.add_to_group(group.pk) # Create a new thread and message thread = mommy.make('connectmessages.Thread', group=group) message = mommy.make('connectmessages.Message', thread=thread, sender=self.user1) # Create and attach a new image image1 = Image() image1.user = message.sender image1.image = File(open(self.smallfile)) image1.save() message.images.add(image1) # Test the visibility of an image when the message has not yet been # approved by a group moderator message.status = 'pending' message.save() sender_response, receiver_response = self.request_multiple_users(group) self.assertContains(sender_response, image1.get_thumbnail) self.assertNotContains(receiver_response, image1.get_thumbnail) # Test the visibility when the message has been approved message.status = 'approved' message.save() sender_response, receiver_response = self.request_multiple_users(group) self.assertContains(sender_response, image1.get_thumbnail) self.assertContains(receiver_response, image1.get_thumbnail) # As we want spammers to think their content was approved, test when # a message has been marked as spam message.status = 'spam' message.save() sender_response, receiver_response = self.request_multiple_users(group) self.assertContains(sender_response, image1.get_thumbnail) self.assertNotContains(receiver_response, image1.get_thumbnail)
def test_moderated_messages_properly_appear(self): """ Test that messages appear differently to different users depending on the message's moderation status """ # Create a new group group = mommy.make(Group) self.user1.add_to_group(group.pk) self.user2.add_to_group(group.pk) # Create a new thread and message thread = mommy.make('connectmessages.Thread', group=group) message = mommy.make( 'connectmessages.Message', thread=thread, sender=self.user1) # Create and attach a new image image1 = Image() image1.user = message.sender image1.image = File(open(self.smallfile)) image1.save() message.images.add(image1) # Test the visibility of an image when the message has not yet been # approved by a group moderator message.status = 'pending' message.save() sender_response, receiver_response = self.request_multiple_users(group) self.assertContains(sender_response, image1.get_thumbnail) self.assertNotContains(receiver_response, image1.get_thumbnail) # Test the visibility when the message has been approved message.status = 'approved' message.save() sender_response, receiver_response = self.request_multiple_users(group) self.assertContains(sender_response, image1.get_thumbnail) self.assertContains(receiver_response, image1.get_thumbnail) # As we want spammers to think their content was approved, test when # a message has been marked as spam message.status = 'spam' message.save() sender_response, receiver_response = self.request_multiple_users(group) self.assertContains(sender_response, image1.get_thumbnail) self.assertNotContains(receiver_response, image1.get_thumbnail)
def test_with_user(self): """Should return images attached to approved messages.""" # Create a new thread and message thread = mommy.make('connectmessages.Thread', group=self.group) message = mommy.make('connectmessages.Message', thread=thread, sender=self.normal_user, status='approved') # Create and attach a new image image1 = Image() image1.user = message.sender image1.image = File(open(self.smallfile)) image1.save() message.images.add(image1) result = self.client.get(reverse('admin_gallery')) self.assertEqual(result.status_code, 200) self.assertIn(image1, result.context['images'])
def test_with_user_message_not_approved_user_is_sender(self): """Images that are not approved should be returned to the sender.""" # Create a new thread and message thread = mommy.make('connectmessages.Thread', group=self.group) message = mommy.make('connectmessages.Message', thread=thread, sender=self.super_user, status='spam') # Create and attach a new image image1 = Image() image1.user = message.sender image1.image = File(open(self.smallfile)) image1.save() message.images.add(image1) result = self.client.get(reverse('admin_gallery')) self.assertEqual(result.status_code, 200) self.assertIn(image1, result.context['images'])
def test_with_user_message_not_approved_user_is_sender(self): """Images that are not approved should be returned to the sender.""" # Create a new thread and message thread = mommy.make('connectmessages.Thread', group=self.group) message = mommy.make( 'connectmessages.Message', thread=thread, sender=self.super_user, status='spam' ) # Create and attach a new image image1 = Image() image1.user = message.sender image1.image = File(open(self.smallfile)) image1.save() message.images.add(image1) result = self.client.get(reverse('admin_gallery')) self.assertEqual(result.status_code, 200) self.assertIn(image1, result.context['images'])
def test_with_user(self): """Should return images attached to approved messages.""" # Create a new thread and message thread = mommy.make('connectmessages.Thread', group=self.group) message = mommy.make( 'connectmessages.Message', thread=thread, sender=self.normal_user, status='approved' ) # Create and attach a new image image1 = Image() image1.user = message.sender image1.image = File(open(self.smallfile)) image1.save() message.images.add(image1) result = self.client.get(reverse('admin_gallery')) self.assertEqual(result.status_code, 200) self.assertIn(image1, result.context['images'])
def test_with_user_non_group_message(self): """Images posted in direct messages shouldn't be returned.""" # Create a new thread and message thread = mommy.make('connectmessages.Thread', group=None, thread_type='direct') message = mommy.make('connectmessages.Message', thread=thread, sender=self.normal_user, status='spam') # Create and attach a new image image1 = Image() image1.user = message.sender image1.image = File(open(self.smallfile)) image1.save() message.images.add(image1) result = self.client.get(reverse('admin_gallery')) self.assertEqual(result.status_code, 200) self.assertNotIn(image1, result.context['images'])
def test_with_user_non_group_message(self): """Images posted in direct messages shouldn't be returned.""" # Create a new thread and message thread = mommy.make( 'connectmessages.Thread', group=None, thread_type='direct') message = mommy.make( 'connectmessages.Message', thread=thread, sender=self.normal_user, status='spam' ) # Create and attach a new image image1 = Image() image1.user = message.sender image1.image = File(open(self.smallfile)) image1.save() message.images.add(image1) result = self.client.get(reverse('admin_gallery')) self.assertEqual(result.status_code, 200) self.assertNotIn(image1, result.context['images'])
def test_no_images_from_banned_users(self): """Test that images posted by banned users are not visible.""" banned_user = mommy.make('accounts.User', is_banned=True) group = mommy.make(Group) banned_user.add_to_group(group.pk) self.user2.add_to_group(group.pk) # Create a new thread and message thread = mommy.make('connectmessages.Thread', group=group) message = mommy.make( 'connectmessages.Message', thread=thread, sender=banned_user) # Create and attach a new image image1 = Image() image1.user = message.sender image1.image = File(open(self.smallfile)) image1.save() message.images.add(image1) result = self.client.get( reverse('group_images', kwargs={'group_id': group.pk})) self.assertNotIn(image1, result.context['images'])
def test_no_images_from_banned_users(self): """Test that images posted by banned users are not visible.""" banned_user = mommy.make('accounts.User', is_banned=True) group = mommy.make(Group) banned_user.add_to_group(group.pk) self.user2.add_to_group(group.pk) # Create a new thread and message thread = mommy.make('connectmessages.Thread', group=group) message = mommy.make('connectmessages.Message', thread=thread, sender=banned_user) # Create and attach a new image image1 = Image() image1.user = message.sender image1.image = File(open(self.smallfile)) image1.save() message.images.add(image1) result = self.client.get( reverse('group_images', kwargs={'group_id': group.pk})) self.assertNotIn(image1, result.context['images'])
def test_with_user_current_user_is_banned(self): """Images from banned users should be visible to the banned user..""" # Create a new thread and message thread = mommy.make('connectmessages.Thread', group=self.group) message = mommy.make( 'connectmessages.Message', thread=thread, sender=self.banned_user) # Create and attach a new image image1 = Image() image1.user = message.sender image1.image = File(open(self.smallfile)) image1.save() message.images.add(image1) client = Client() client.post( reverse('login'), {'username': self.banned_user.email, 'password': '******'} ) result = client.get(reverse('admin_gallery')) self.assertEqual(result.status_code, 200) self.assertIn(image1, result.context['images'])
def test_with_user_current_user_is_banned(self): """Images from banned users should be visible to the banned user..""" # Create a new thread and message thread = mommy.make('connectmessages.Thread', group=self.group) message = mommy.make( 'connectmessages.Message', thread=thread, sender=self.banned_user) # Create and attach a new image image1 = Image() image1.user = message.sender image1.image = File(open(self.smallfile)) image1.save() message.images.add(image1) client = Client() client.post( reverse('account_login'), {'login': self.banned_user.email, 'password': '******'} ) result = client.get(reverse('admin_gallery')) self.assertEqual(result.status_code, 200) self.assertIn(image1, result.context['images'])