def test_post_with_comments_from_friend(self): test_user = Pleb(email=str(uuid1()) + '@gmail.com', username=str(uuid1())[:32]) test_user.save() test_post = Post(content='test', object_uuid=str(uuid1()), owner_username=self.pleb.username, wall_owner_username=self.pleb.username) test_post.save() wall = self.pleb.wall.all()[0] test_post.posted_on_wall.connect(wall) wall.posts.connect(test_post) test_post.owned_by.connect(self.pleb) my_comment = Comment(content='test comment', object_uuid=str(uuid1()), owner_username=self.pleb.username) my_comment.save() my_comment.owned_by.connect(test_user) test_post.comments.connect(my_comment) request = self.factory.get('/%s' % self.pleb.username) request.user = self.user profile_page = ProfileView.as_view() response = profile_page(request, self.pleb.username) self.assertIn(response.status_code, [status.HTTP_200_OK, status.HTTP_302_FOUND]) test_user.delete() test_post.delete() my_comment.delete()
def test_create_post_notification_user_is_same(self): post = Post(content='as;ldkfja;') post.save() response = create_notification_util(post.object_uuid, self.pleb, [self.pleb], str(uuid1()), self.url, post.action_name) self.assertTrue(response)
def test_multiple_posts_multiple_comments_friends(self): wall = self.pleb.get_wall() pleb_array = [] post_array = [] comment_array = [] for item in range(0, 2): test_pleb = Pleb(email=str(uuid1())[:32], username=str(uuid1())[:32]) test_pleb.save() pleb_array.append(test_pleb) for number in range(0, 10): test_post = Post(content='test', object_uuid=str(uuid1()), owner_username=self.pleb.username, wall_owner_username=self.pleb.username) test_post.save() test_post.posted_on_wall.connect(wall) wall.posts.connect(test_post) test_post.owned_by.connect(test_pleb) post_array.append(test_post) for num in range(0, 1): my_comment = Comment(content='test comment', object_uuid=str(uuid1()), owner_username=self.pleb.username) my_comment.save() my_comment.owned_by.connect(test_pleb) test_post.comments.connect(my_comment) comment_array.append(my_comment) my_comment = Comment(content='test comment', object_uuid=str(uuid1()), owner_username=self.pleb.username) my_comment.save() my_comment.owned_by.connect(self.pleb) test_post.comments.connect(my_comment) comment_array.append(my_comment) test_post = Post(content='test', object_uuid=str(uuid1()), owner_username=self.pleb.username, wall_owner_username=self.pleb.username) test_post.save() test_post.posted_on_wall.connect(wall) wall.posts.connect(test_post) test_post.owned_by.connect(self.pleb) request = self.factory.get('/%s' % self.pleb.username) request.user = self.user profile_page = ProfileView.as_view() response = profile_page(request, self.pleb.username) self.assertIn(response.status_code, [status.HTTP_200_OK, status.HTTP_302_FOUND]) for item in pleb_array: item.delete() for post in post_array: post.delete() for comment in comment_array: comment.delete() test_post.delete()
def test_create_post_notification_already_exists_not_sent(self): notification = Notification().save() post = Post(object_uuid=uuid1(), content='as;ldkfja;') post.save() response = create_notification_util(post.object_uuid, self.pleb, [self.pleb2], notification.object_uuid, self.url, post.action_name) self.assertTrue(response)
def test_create_comment_notification_pleb_is_the_same(self): post = Post(content='as;ldkfja;') post.save() comment = Comment(content='sdfasd') comment.save() response = create_notification_util(comment.object_uuid, self.pleb, [self.pleb], str(uuid1()), self.url, post.action_name) self.assertTrue(response)
def test_create_comment_notification_already_exists_not_sent(self): comment = Comment(content='sdfasd') comment.save() notification = Notification().save() post = Post(content='as;ldkfja;') post.save() response = create_notification_util(comment.object_uuid, self.pleb, [self.pleb2], notification.object_uuid, self.url, post.action_name) self.assertTrue(response)
def test_create_notification_task_failure(self): post = Post(**self.post_info_dict) post.save() data = { 'sb_object': post, 'from_pleb': self.pleb.email, 'to_plebs': [self.pleb2.email, '*****@*****.**'] } response = spawn_notifications.apply_async(kwargs=data) while not response.ready(): time.sleep(1) self.assertIsInstance(response.result, Exception)
def test_create_notification_post_task(self): post = Post(**self.post_info_dict) post.save() data = { 'sb_object': post, 'from_pleb': self.pleb.email, 'to_plebs': [ self.pleb2.email, ] } response = spawn_notifications.apply_async(kwargs=data) while not response.ready(): time.sleep(3) self.assertTrue(response.result)
def test_with_post(self): test_post = Post(content='test', object_uuid=str(uuid1()), owner_username=self.pleb.username, wall_owner_username=self.pleb.username) test_post.save() wall = self.pleb.get_wall() test_post.posted_on_wall.connect(wall) wall.posts.connect(test_post) test_post.owned_by.connect(self.pleb) request = self.factory.get('/%s' % self.pleb.username) request.user = self.user profile_page = ProfileView.as_view() response = profile_page(request, self.pleb.username) self.assertIn(response.status_code, [status.HTTP_200_OK, status.HTTP_302_FOUND]) test_post.delete()
def test_multiple_posts(self): post_array = [] wall = self.pleb.get_wall() for item in range(0, 50): test_post = Post(content='test', object_uuid=str(uuid1()), owner_username=self.pleb.username, wall_owner_username=self.pleb.username) test_post.save() test_post.posted_on_wall.connect(wall) wall.posts.connect(test_post) test_post.owned_by.connect(self.pleb) post_array.append(test_post) self.client.login(username=self.username, password=self.password) response = self.client.get(reverse( "profile_page", kwargs={"pleb_username": self.pleb.username}), follow=True) self.assertEqual(response.status_code, 200) for post in post_array: post.delete()