def test_can_only_see_own_notifications(self): create_notification(self.receiver, self.reporter, self.social_obj, self.notification_type) create_notification(self.reporter, self.receiver, self.social_obj, self.notification_type) # Notifications serialized with thumbnails post = PostFactory() post.thumbnail = settings.PROJECT_ROOT + "/test_app/tests/img/yeti.jpg" post.save() create_notification(self.receiver, self.reporter, post, self.notification_type) url = reverse("notifications") response = self.assertSchemaGet(url, None, "$notificationResponse", self.receiver) self.assertEqual(response.data["count"], self.receiver.notifications_received.count())
def test_serialization_when_content_object_deleted(self): mention_notification = NotificationType.objects.get(slug="mention") content_type = ContentType.objects.get_for_model(Post) user = UserFactory() post = PostFactory(user=user) Notification.objects.create(notification_type=mention_notification, content_type=content_type, object_id=post.pk, user=user, reporter=self.reporter) post.delete() other_post = PostFactory(user=user) Notification.objects.create(notification_type=mention_notification, content_type=content_type, object_id=other_post.pk, user=user, reporter=self.reporter) url = reverse("notifications") response = self.assertSchemaGet(url, None, "$notificationResponse", user) self.assertEqual(response.data['count'], 1) self.assertEqual(response.data['results'][0]['post']['id'], other_post.pk)
def test_liked_mixin(self): post = PostFactory() url = reverse("posts-detail", args=[post.pk]) like = Like.objects.create( content_type=ContentType.objects.get_for_model(Post), object_id=post.pk, user=self.dev_user) response = self.assertSchemaGet(url, None, "$postResponse", self.dev_user) self.assertEqual(response.data["liked_id"], like.pk) other_post = PostFactory() url = reverse("posts-detail", args=[other_post.pk]) response = self.assertSchemaGet(url, None, "$postResponse", self.dev_user) self.assertIsNone(response.data["liked_id"])
def test_users_can_flag_content(self): test_user = UserFactory() content_type = ContentType.objects.get_for_model(Post) flag_url = reverse('flag') data = {'content_type': content_type.pk, 'object_id': PostFactory().pk} self.assertSchemaPost(flag_url, "$flagRequest", "$flagResponse", data, test_user)
def test_comment_mention_creates_notification(self): """ User receives a notification when their username is @mentioned, even if they are not the owner of the post """ url = reverse("comments-list") content_type = ContentType.objects.get_for_model(Post) data = { "content_type": content_type.pk, "object_id": PostFactory().pk, "description": "@{} look at my cool comment!".format( self.social_obj.user.username) } self.assertSchemaPost(url, "$commentRequest", "$commentResponse", data, self.reporter) mention_type = NotificationType.objects.get(slug="mention") notification_count = Notification.objects.filter( user=self.social_obj.user, reporter=self.reporter, content_type=ContentType.objects.get_for_model(Post), notification_type=mention_type).count() self.assertEqual(notification_count, 1)
def setUp(self): super(NotificationsTestCase, self).setUp() self.social_obj = PostFactory() self.receiver = UserFactory() self.reporter = UserFactory() self.notification_type = NotificationType.objects.get(slug="comment") PushwooshClient.invoke = MagicMock(return_value={"status_code": 200}) PushClient.invoke = MagicMock(return_value={"status_code": 200})
def test_users_can_like_content(self): content_type = ContentType.objects.get_for_model(Post) likes_url = reverse('likes-list') data = { 'content_type': content_type.pk, 'object_id': PostFactory().pk, } self.assertSchemaPost(likes_url, "$likeRequest", "$likeResponse", data, self.dev_user)
def test_users_can_comment_on_content(self): content_type = ContentType.objects.get_for_model(Post) comments_url = reverse('comments-list') data = { 'content_type': content_type.pk, 'object_id': PostFactory().pk, 'description': 'This is a user comment.' } self.assertSchemaPost(comments_url, "$commentRequest", "$commentResponse", data, self.dev_user)
def setUp(self): super(NotificationsTestCase, self).setUp() self.social_obj = PostFactory() self.receiver = UserFactory() self.reporter = UserFactory() self.notification_type = NotificationType.objects.get(slug="comment") patcher = patch('yak.rest_notifications.utils.submit_to_pushwoosh') self.addCleanup(patcher.stop) self.mock_submit_to_pushwoosh = patcher.start() self.mock_submit_to_pushwoosh.return_value = {"status_code": 200}
def test_users_can_share_content(self): test_user = UserFactory() content_type = ContentType.objects.get_for_model(Post) shares_url = reverse('shares-list') data = { 'content_type': content_type.pk, 'object_id': PostFactory().pk, 'shared_with': [test_user.pk] } self.assertSchemaPost(shares_url, "$shareRequest", "$shareResponse", data, self.dev_user)
def test_comments_for_specific_object(self): test_user = UserFactory() post_content_type = ContentType.objects.get_for_model(Post) post = PostFactory(user=test_user) comment = CommentFactory(content_type=post_content_type, object_id=post.pk) post2 = PostFactory(user=test_user) CommentFactory(content_type=post_content_type, object_id=post2.pk) url = reverse('comments-list') parameters = { 'content_type': post_content_type.pk, 'object_id': post.pk, } response = self.assertSchemaGet(url, parameters, "$commentResponse", self.dev_user) self.assertEqual(len(response.data["results"]), 1) self.assertEqual(response.data["results"][0]["id"], comment.pk)