def test_saving_draft_post_activity(self): """ Test saving draft activity Make sure that activity is not created for draft posts """ self.initialize() post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.DRAFT_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() self.failUnlessEqual(UserActivity.objects.all().count(), 1) # now we want to create an activity each time act = UserActivity.objects.get(post=post) self.failUnlessEqual(act.status, UserActivity.DRAFT_STATUS) post.status = Post.PUBLIC_STATUS post.save() self.failUnlessEqual(UserActivity.objects.all().count(), 1) act = UserActivity.objects.get(post=post) self.failUnlessEqual(act.status, UserActivity.PUBLIC_STATUS) post.status = Post.DRAFT_STATUS post.save() self.failUnlessEqual(UserActivity.objects.all().count(), 1) act = UserActivity.objects.get(post=post) self.failUnlessEqual(act.status, UserActivity.DRAFT_STATUS)
def test_deleting_post_activity(self): """ Test deleting post activity """ self.initialize() post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() act = UserActivity.objects.get(post=post) self.failUnlessEqual(act.status, UserActivity.PUBLIC_STATUS) post.status = Object.DELETED_STATUS post.save() act = UserActivity.objects.get(post=post) self.failUnlessEqual(act.status, UserActivity.DELETED_STATUS)
def test_updating_post_activity(self): """ Test updating post activity """ self.initialize() # set up post post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() post.title = "Bum bum bum" post.permalink = "bum-bum-bum" post.body = "Lubuduubu lubu dubu niech zyje nam prezes naszego klubu!" post.status = Object.DRAFT_STATUS post.save() activity = UserActivity.objects.get(post=post) # testing if activity was updated properly self.failUnlessEqual(activity.title, "Bum bum bum") self.failUnlessEqual(activity.content, "Lubuduubu lubu dubu niech zyje nam prezes naszego klubu!") self.failUnlessEqual(activity.permalink, post.get_absolute_url()) self.failUnlessEqual(activity.status, UserActivity.DRAFT_STATUS) self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_POST) self.failUnlessEqual(activity.username, self.u1.username) self.failUnlessEqual(activity.film_title, self.film.title) self.failUnlessEqual(activity.film_permalink, self.film.permalink)
def test_my_articles(self): """ Test my_articles view """ self.initialize() self.client.login(username=self.u1.username, password='******') post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Post.PUBLIC_STATUS post.type = Post.TYPE_POST post.save() post1 = Post() post1.title = "Lorem ipsum2" post1.permalink = "lorem-ipsum" post1.body = "siala lala tralala" post1.user = self.u1 post1.status = Post.DRAFT_STATUS post1.type = Post.TYPE_POST post1.save() response = self.client.get("/"+urls["ARTICLES"]+"/") self.failUnlessEqual(response.status_code, 200) self.assertEqual(len(response.context['object_list']), 1)
def test_my_articles(self): """ Test my_articles view """ self.initialize() self.client.login(username=self.u1.username, password='******') post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Post.PUBLIC_STATUS post.type = Post.TYPE_POST post.save() post1 = Post() post1.title = "Lorem ipsum2" post1.permalink = "lorem-ipsum" post1.body = "siala lala tralala" post1.user = self.u1 post1.status = Post.DRAFT_STATUS post1.type = Post.TYPE_POST post1.save() response = self.client.get("/" + urls["ARTICLES"] + "/") self.failUnlessEqual(response.status_code, 200) self.assertEqual(len(response.context['object_list']), 1)
def test_edit_existing_post(self): """ Case where user is trying to edit existing post """ self.client.login(username=self.u1.username, password='******') # set up post post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) # this method will call save_activity method and in this case create new activity post.save() first_publish = post.publish # make sure published date is set self.failIf(first_publish is None) post.title = "Lorem ipsum! Lorem ipsum! Lorem ipsum!" post.save() # published date should not change after saving again self.failUnlessEqual(first_publish, post.publish) # make sure related activity also gets updated from film20.useractivity.models import UserActivity activity = UserActivity.objects.get( activity_type=UserActivity.TYPE_POST, post=post, user=post.user) post = Post.objects.get(permalink="lorem-ipsum") self.failUnlessEqual(post.title, "Lorem ipsum! Lorem ipsum! Lorem ipsum!") self.failUnlessEqual( activity.slug, "/" + urls['SHOW_PROFILE'] + '/' + self.u1.username + '/' + urls['ARTICLE'] + "/lorem-ipsum/") # now revert ro draft and then republish post.status = Object.DRAFT_STATUS post.save() post.status = Object.PUBLIC_STATUS post.save() # published date should not change after republishing an article published before self.failUnlessEqual(first_publish, post.publish)
def test_saving_post_activity(self): """ Test saving post activity """ self.initialize() # set up post post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) # this method will call save_activity method and in this case create new activity post.save() activity = UserActivity.objects.get(post=post) # testing if activity was saved properly self.failUnlessEqual(activity.title, post.title) self.failUnlessEqual(activity.content, post.body) self.failUnlessEqual(activity.permalink, post.get_absolute_url()) self.failUnlessEqual(activity.status, post.status) self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_POST) self.failUnlessEqual(activity.username, self.u1.username) self.failUnlessEqual(activity.film_title, self.film.title) self.failUnlessEqual(activity.film_permalink, self.film.permalink)
def test_edit_existing_post(self): """ Case where user is trying to edit existing post """ self.client.login(username=self.u1.username, password='******') # set up post post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) # this method will call save_activity method and in this case create new activity post.save() first_publish = post.publish # make sure published date is set self.failIf(first_publish is None) post.title = "Lorem ipsum! Lorem ipsum! Lorem ipsum!" post.save() # published date should not change after saving again self.failUnlessEqual(first_publish, post.publish) # make sure related activity also gets updated from film20.useractivity.models import UserActivity activity = UserActivity.objects.get(activity_type = UserActivity.TYPE_POST, post = post, user = post.user) post = Post.objects.get(permalink="lorem-ipsum") self.failUnlessEqual(post.title, "Lorem ipsum! Lorem ipsum! Lorem ipsum!") self.failUnlessEqual(activity.slug, "/" + urls['SHOW_PROFILE'] + '/' + self.u1.username + '/' + urls['ARTICLE'] + "/lorem-ipsum/") # now revert ro draft and then republish post.status = Object.DRAFT_STATUS post.save() post.status = Object.PUBLIC_STATUS post.save() # published date should not change after republishing an article published before self.failUnlessEqual(first_publish, post.publish)
def test_saving_comment_activity(self): """ Test saving comment activity """ self.initialize() # set up post for commenting post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() comment = ThreadedComment() comment.user = self.u1 comment.comment = "Lorem ipsum" comment.content_object = post comment.status = Object.PUBLIC_STATUS comment.type = Object.TYPE_COMMENT comment.permalink = "COMMENT" comment.save() activity = UserActivity.objects.get(comment=comment) # testing if activity was saved properly self.failUnlessEqual(activity.title, comment.content_object.get_comment_title()) self.failUnlessEqual(activity.content, comment.comment) if settings.ENSURE_OLD_STYLE_PERMALINKS: self.failUnlessEqual( activity.permalink, comment.content_object.get_absolute_url_old_style() + "#" + str(comment.id)) else: self.failUnlessEqual( activity.permalink, comment.content_object.get_absolute_url() + "#" + str(comment.id)) self.failUnlessEqual(activity.status, comment.status) self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_COMMENT) self.failUnlessEqual(activity.username, self.u1.username) #planet_tag_helper without tag = 1 comment pth = PlanetTagHelper() comments = pth.planet_tag_comments() self.assertEquals(len(comments), 1) #planet_tag_helper with tag 'comedy' = 0 comment #no assigned films to comment pth_tags = PlanetTagHelper(tag='comedy') comments = pth_tags.planet_tag_comments() self.assertEquals(len(comments), 0)
def test_saving_comment_activity(self): """ Test saving comment activity """ self.initialize() # set up post for commenting post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() comment = ThreadedComment() comment.user = self.u1 comment.comment = "Lorem ipsum" comment.content_object = post comment.status = Object.PUBLIC_STATUS comment.type = Object.TYPE_COMMENT comment.permalink = "COMMENT" comment.save() activity = UserActivity.objects.get(comment=comment) # testing if activity was saved properly self.failUnlessEqual(activity.title, comment.content_object.get_comment_title()) self.failUnlessEqual(activity.content, comment.comment) if settings.ENSURE_OLD_STYLE_PERMALINKS: self.failUnlessEqual( activity.permalink, comment.content_object.get_absolute_url_old_style() + "#" + str(comment.id) ) else: self.failUnlessEqual(activity.permalink, comment.content_object.get_absolute_url() + "#" + str(comment.id)) self.failUnlessEqual(activity.status, comment.status) self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_COMMENT) self.failUnlessEqual(activity.username, self.u1.username) # planet_tag_helper without tag = 1 comment pth = PlanetTagHelper() comments = pth.planet_tag_comments() self.assertEquals(len(comments), 1) # planet_tag_helper with tag 'comedy' = 0 comment # no assigned films to comment pth_tags = PlanetTagHelper(tag="comedy") comments = pth_tags.planet_tag_comments() self.assertEquals(len(comments), 0)
def test_updating_relatedfilm_post_activity(self): """ Test updating film fields in post activity when related films are removed from post """ self.initialize() self.client.login(username='******', password='******') # set up post post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() activity = UserActivity.objects.get(post=post) # testing if activity was saved properly self.failUnlessEqual(activity.title, "Lorem ipsum") self.failUnlessEqual(activity.content, "siala lala tralala") self.failUnlessEqual(activity.permalink, post.get_absolute_url()) self.failUnlessEqual(activity.status, UserActivity.PUBLIC_STATUS) self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_POST) self.failUnlessEqual(activity.username, self.u1.username) self.failUnlessEqual(activity.film is None, False) self.failUnlessEqual(activity.film_permalink, self.film.permalink) self.failUnlessEqual(activity.film_title, self.film.title) # update post post.title = "New title" post.body = "Lorem ipsum! Lorem ipsum! Lorem ipsum!" post.related_film = [] post.save() activity = UserActivity.objects.get(post=post) # testing if activity was updated properly self.failUnlessEqual(activity.title, "New title") self.failUnlessEqual(activity.content, "Lorem ipsum! Lorem ipsum! Lorem ipsum!") self.failUnlessEqual(activity.permalink, post.get_absolute_url()) self.failUnlessEqual(activity.status, UserActivity.PUBLIC_STATUS) self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_POST) self.failUnlessEqual(activity.username, self.u1.username) self.failUnlessEqual(activity.film is None, True) self.failUnlessEqual(activity.film_permalink, None) self.failUnlessEqual(activity.film_title, None)
def test_updating_comment_activity(self): """ Test updating comment activity """ self.initialize() # set up post for commenting post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() comment = ThreadedComment() comment.user = self.u1 comment.comment = "Lorem ipsum" comment.content_object = post comment.status = Object.PUBLIC_STATUS comment.type = Object.TYPE_COMMENT comment.permalink = "COMMENT" comment.save() comment.comment = "siala lala tralala" comment.status = Object.DELETED_STATUS comment.save() activity = UserActivity.objects.get(comment=comment) # testing if activity was updated properly self.failUnlessEqual(activity.title, comment.content_object.get_comment_title()) self.failUnlessEqual(activity.content, "siala lala tralala") if settings.ENSURE_OLD_STYLE_PERMALINKS: self.failUnlessEqual( activity.permalink, comment.content_object.get_absolute_url_old_style() + "#" + str(comment.id)) else: self.failUnlessEqual( activity.permalink, comment.content_object.get_absolute_url() + "#" + str(comment.id)) self.failUnlessEqual(activity.status, UserActivity.DELETED_STATUS) self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_COMMENT) self.failUnlessEqual(activity.username, self.u1.username)
def test_all_for_user(self): """ Test all_for_user manager """ post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Post.PUBLIC_STATUS post.type = Post.TYPE_POST post.save() post1 = Post() post1.title = "Lorem ipsum2" post1.permalink = "lorem-ipsum" post1.body = "siala lala tralala" post1.user = self.u1 post1.status = Post.DRAFT_STATUS post1.type = Post.TYPE_POST post1.save() self.assertEqual(Post.objects.all_for_user(self.u1).count(), 2)
def test_public_for_user(self): """ Test public_for_user manager """ post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Post.PUBLIC_STATUS post.type = Post.TYPE_POST post.save() post1 = Post() post1.title = "Lorem ipsum2" post1.permalink = "lorem-ipsum" post1.body = "siala lala tralala" post1.user = self.u1 post1.status = Post.DRAFT_STATUS post1.type = Post.TYPE_POST post1.save() self.assertEqual(Post.objects.public_for_user(self.u1).count(), 1)
def test_updating_post_activity(self): """ Test updating post activity """ self.initialize() # set up post post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() post.title = "Bum bum bum" post.permalink = "bum-bum-bum" post.body = "Lubuduubu lubu dubu niech zyje nam prezes naszego klubu!" post.status = Object.DRAFT_STATUS post.save() activity = UserActivity.objects.get(post=post) # testing if activity was updated properly self.failUnlessEqual(activity.title, "Bum bum bum") self.failUnlessEqual( activity.content, "Lubuduubu lubu dubu niech zyje nam prezes naszego klubu!") self.failUnlessEqual(activity.permalink, post.get_absolute_url()) self.failUnlessEqual(activity.status, UserActivity.DRAFT_STATUS) self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_POST) self.failUnlessEqual(activity.username, self.u1.username) self.failUnlessEqual(activity.film_title, self.film.title) self.failUnlessEqual(activity.film_permalink, self.film.permalink)
def test_saving_draft_post_activity(self): """ Test saving draft activity Make sure that activity is not created for draft posts """ self.initialize() post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.DRAFT_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() post_activities = UserActivity.objects.filter( activity_type=UserActivity.TYPE_POST) self.failUnlessEqual(post_activities.count(), 1) # now we want to create an activity each time act = UserActivity.objects.get(post=post) self.failUnlessEqual(act.status, UserActivity.DRAFT_STATUS) post.status = Post.PUBLIC_STATUS post.save() self.failUnlessEqual(post_activities.count(), 1) act = UserActivity.objects.get(post=post) self.failUnlessEqual(act.status, UserActivity.PUBLIC_STATUS) post.status = Post.DRAFT_STATUS post.save() self.failUnlessEqual(post_activities.count(), 1) act = UserActivity.objects.get(post=post) self.failUnlessEqual(act.status, UserActivity.DRAFT_STATUS)
def test_notifications(self): mail.outbox = [] wallpost = ShortReview() wallpost.user = self.user1 wallpost.review_text = "lorem ipsum @user,@b_as sid at ble" wallpost.status = Object.PUBLIC_STATUS wallpost.kind = ShortReview.WALLPOST wallpost.type = Object.TYPE_SHORT_REVIEW wallpost.save() self.assertEqual(len(mail.outbox), 2) self.assertTrue(wallpost.get_absolute_url() in mail.outbox[0].body) print mail.outbox[0].body mail.outbox = [] comment = ThreadedComment.objects.create_for_object( wallpost, user=self.user2, ip_address='127.0.0.1', comment="test comment @root", status=ThreadedComment.PUBLIC_STATUS, type=ThreadedComment.TYPE_COMMENT) self.assertEqual(len(mail.outbox), 1) self.assertTrue(comment.get_absolute_url() in mail.outbox[0].body) print mail.outbox[0].body mail.outbox = [] post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.lead = "lorem-ipsuam @root" post.body = "siala lala tralala @b_as" post.user = self.user1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() self.assertEqual(len(mail.outbox), 2) self.assertTrue(post.get_absolute_url() in mail.outbox[0].body) print mail.outbox[0].body
def test_tagging( self ): """ test posts tagging """ post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.tag_list = 'ww2,pl,lorem' post.save() self.assertEqual( UserActivity.objects.all_notes().tagged( 'ww2' ).count(), 1 )
def test_tagging(self): """ test posts tagging """ post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.tag_list = 'ww2,pl,lorem' post.save() self.assertEqual( UserActivity.objects.all_notes().tagged('ww2').count(), 1)
def test_updating_comment_activity(self): """ Test updating comment activity """ self.initialize() # set up post for commenting post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() comment = ThreadedComment() comment.user = self.u1 comment.comment = "Lorem ipsum" comment.content_object = post comment.status = Object.PUBLIC_STATUS comment.type = Object.TYPE_COMMENT comment.permalink = "COMMENT" comment.save() comment.comment = "siala lala tralala" comment.status = Object.DELETED_STATUS comment.save() activity = UserActivity.objects.get(comment=comment) # testing if activity was updated properly self.failUnlessEqual(activity.title, comment.content_object.get_comment_title()) self.failUnlessEqual(activity.content, "siala lala tralala") if settings.ENSURE_OLD_STYLE_PERMALINKS: self.failUnlessEqual( activity.permalink, comment.content_object.get_absolute_url_old_style() + "#" + str(comment.id) ) else: self.failUnlessEqual(activity.permalink, comment.content_object.get_absolute_url() + "#" + str(comment.id)) self.failUnlessEqual(activity.status, UserActivity.DELETED_STATUS) self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_COMMENT) self.failUnlessEqual(activity.username, self.u1.username)
def test_notifications( self ): mail.outbox = [] wallpost = ShortReview() wallpost.user = self.user1 wallpost.review_text = "lorem ipsum @user,@b_as sid at ble" wallpost.status = Object.PUBLIC_STATUS wallpost.kind = ShortReview.WALLPOST wallpost.type = Object.TYPE_SHORT_REVIEW wallpost.save() self.assertEqual( len( mail.outbox ), 2 ) self.assertTrue( wallpost.get_absolute_url() in mail.outbox[0].body ) print mail.outbox[0].body mail.outbox = [] comment = ThreadedComment.objects.create_for_object( wallpost, user=self.user2, ip_address='127.0.0.1',comment="test comment @root", status=ThreadedComment.PUBLIC_STATUS, type = ThreadedComment.TYPE_COMMENT ) self.assertEqual( len( mail.outbox ), 1 ) self.assertTrue( comment.get_absolute_url() in mail.outbox[0].body ) print mail.outbox[0].body mail.outbox = [] post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.lead = "lorem-ipsuam @root" post.body = "siala lala tralala @b_as" post.user = self.user1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() self.assertEqual( len( mail.outbox ), 2 ) self.assertTrue( post.get_absolute_url() in mail.outbox[0].body ) print mail.outbox[0].body
def add_super_form_note(request, ajax=None): if request.method == 'POST': blog_object = Blog.objects.select_related().get_or_create(user=request.user) form = SuperForm(request.POST) if form.is_valid(): post = Post() post.author = blog_object[0] post.body = form.cleaned_data["body"] txt = " ".join(post.body.split(' '))[:50] if form.cleaned_data["related_film"]: post.title = _('Review') + ": " + form.cleaned_data["related_film"][0].title post.title = post.title[:200] permalink = slughifi(post.title + " " + txt) else: post.title = _('Review') +": " + txt post.title = post.title[:200] permalink = slughifi(post.title[:128]) post.type = Post.TYPE_POST post.status = Post.PUBLIC_STATUS post.save(permalink=permalink) for film in form.cleaned_data["related_film"]:post.related_film.add(film) if ajax=="json": context = { 'success': True, 'data': post.id, } return json_return(context) else: return HttpResponseRedirect(full_url("PLANET")) else: if ajax == "json": context = { 'success': False, 'errors': str(form.errors), } return JSONResponse(context, is_iterable=False) else: return HttpResponseRedirect(full_url("PLANET"))
def test_cache_featured_review(self): """ test cache invalidate for featured review """ post = Post.objects.featured_review() self.assertEqual(post, None) post = Post() post.title = "first post" post.permalink = "first-post" post.body = "post first post" post.user = self.u1 post.status = Post.PUBLIC_STATUS post.type = Post.TYPE_POST post.featured_note = True post.save() post = Post.objects.featured_review() self.assertEqual(post.permalink, u'first-post') post1 = Post() post1.title = "second post" post1.permalink = "second-post" post1.body = "post second post" post1.user = self.u1 post1.status = Post.PUBLIC_STATUS post1.type = Post.TYPE_POST post1.featured_note = True post1.save() post = Post.objects.featured_review() self.assertEqual(post.permalink, u'second-post') post2 = Post() post2.title = "third post" post2.permalink = "third-post" post2.body = "post third post" post2.user = self.u1 post2.status = Post.PUBLIC_STATUS post2.type = Post.TYPE_POST post2.featured_note = True post2.save() post = Post.objects.featured_review() self.assertEqual(post.permalink, u'third-post') # change featured post status and check if cache is invalidated post2 = Post.objects.get(title__iexact='third post') post2.status = Post.DRAFT_STATUS post2.save() post = Post.objects.featured_review() self.assertEqual(post.permalink, u'second-post') # republished post post2 = Post.objects.get(title__iexact='third post') post2.status = Post.PUBLIC_STATUS post2.save() post = Post.objects.featured_review() self.assertEqual(post.permalink, u'third-post') self.assertEqual(Post.objects.recent_reviews().count(), 0)
def test_cache_recent_reviews(self): """ test cache invalidate for recent reviews """ posts = Post.objects.recent_reviews() self.assertEqual(len(posts), 0) post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Post.PUBLIC_STATUS post.type = Post.TYPE_POST post.is_published = True post.save() posts = Post.objects.recent_reviews() self.assertEqual(posts.count(), 1) post1 = Post() post1.title = "Lorem ipsum2" post1.permalink = "lorem-ipsum2" post1.body = "siala lala tralala" post1.user = self.u1 post1.status = Post.PUBLIC_STATUS post1.type = Post.TYPE_POST post1.is_published = True post1.save() posts = Post.objects.recent_reviews() featured = Post.objects.featured_review() self.assertEqual(posts.count(),2) self.assertEqual(featured, None) post2 = Post() post2.title = "third post" post2.permalink = "third-post" post2.body = "siala lala tralala" post2.user = self.u1 post2.status = Post.PUBLIC_STATUS post2.type = Post.TYPE_POST post2.is_published = True post2.save() posts = Post.objects.recent_reviews() featured = Post.objects.featured_review() self.assertEqual(posts.count(),3) self.assertEqual(featured, None) # change featured post status and check if cache is invalidated post2 = Post.objects.get(title__iexact='third post') post2.status = Post.DRAFT_STATUS post2.save() posts = Post.objects.recent_reviews() featured = Post.objects.featured_review() self.assertEqual(posts.count(),2) self.assertEqual(featured, None) # republished post post2 = Post.objects.get(title__iexact='third post') post2.status = Post.PUBLIC_STATUS post2.save() posts = Post.objects.recent_reviews() featured = Post.objects.featured_review() self.assertEqual(posts.count(),3) self.assertEqual(featured, None)
def test_cache_recent_reviews(self): """ test cache invalidate for recent reviews """ posts = Post.objects.recent_reviews() self.assertEqual(len(posts), 0) post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Post.PUBLIC_STATUS post.type = Post.TYPE_POST post.is_published = True post.save() posts = Post.objects.recent_reviews() self.assertEqual(posts.count(), 1) post1 = Post() post1.title = "Lorem ipsum2" post1.permalink = "lorem-ipsum2" post1.body = "siala lala tralala" post1.user = self.u1 post1.status = Post.PUBLIC_STATUS post1.type = Post.TYPE_POST post1.is_published = True post1.save() posts = Post.objects.recent_reviews() featured = Post.objects.featured_review() self.assertEqual(posts.count(), 2) self.assertEqual(featured, None) post2 = Post() post2.title = "third post" post2.permalink = "third-post" post2.body = "siala lala tralala" post2.user = self.u1 post2.status = Post.PUBLIC_STATUS post2.type = Post.TYPE_POST post2.is_published = True post2.save() posts = Post.objects.recent_reviews() featured = Post.objects.featured_review() self.assertEqual(posts.count(), 3) self.assertEqual(featured, None) # change featured post status and check if cache is invalidated post2 = Post.objects.get(title__iexact='third post') post2.status = Post.DRAFT_STATUS post2.save() posts = Post.objects.recent_reviews() featured = Post.objects.featured_review() self.assertEqual(posts.count(), 2) self.assertEqual(featured, None) # republished post post2 = Post.objects.get(title__iexact='third post') post2.status = Post.PUBLIC_STATUS post2.save() posts = Post.objects.recent_reviews() featured = Post.objects.featured_review() self.assertEqual(posts.count(), 3) self.assertEqual(featured, None)
def test_planet_tag(self): # --- Initialize --- self.initialize() helper_without_tags = PlanetTagHelper() helper_with_tags = PlanetTagHelper(tag='comedy') recom_helper = RecomHelper() user_activity_helper = UserActivityHelper() # --- setup followers --- self.u1.followers.follow(self.u2) self.u1.followers.follow(self.u3) self.u1.followers.follow(self.u4) # similar users from film20.recommendations.bot_helper import do_create_comparators self.films_for_comparator() do_create_comparators() friends_list = recom_helper.get_following_ids_as_list(self.u1) friends_without_activities = helper_without_tags.planet_tag_friends( friends_list) self.assertEquals(len(friends_without_activities), 0) similar_users_list = user_activity_helper.get_similar_users_list( request) similar_users_without_tags = helper_without_tags.planet_tag_similar_users( similar_users_list) self.assertEquals(len(similar_users_without_tags), 0) notes_without_tags = helper_without_tags.planet_tag_notes() self.assertEquals(len(notes_without_tags), 0) all_planet_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_planet_activities), 0) # --- setup User activities --- post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 1) post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film1) post.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 2) obj = Object.objects.get(id=self.film2.id) shortreview = ShortReview() shortreview.user = self.u1 shortreview.review_text = "sialala bumcyk cyk" shortreview.status = Object.PUBLIC_STATUS shortreview.type = Object.TYPE_SHORT_REVIEW shortreview.object = obj shortreview.kind = ShortReview.REVIEW shortreview.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 3) # Activities with 'comedy' tag all_activities_with_tags = helper_with_tags.planet_tag_all() self.assertEquals(len(all_activities_with_tags), 1) # --- setup followers activities --- post = Post() post.title = "#1 Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u2 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 4) post = Post() post.title = "#2 Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u3 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film1) post.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 5) obj = Object.objects.get(id=self.film2.id) shortreview = ShortReview() shortreview.user = self.u4 shortreview.review_text = "sialala bumcyk cyk" shortreview.status = Object.PUBLIC_STATUS shortreview.type = Object.TYPE_SHORT_REVIEW shortreview.object = obj shortreview.kind = ShortReview.REVIEW shortreview.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 6) activities_with_tags = helper_with_tags.planet_tag_all() self.assertEquals(len(activities_with_tags), 2) all_friends_activities = helper_without_tags.planet_tag_friends( friends_list) self.assertEquals(len(all_friends_activities), 3) friends_activities_with_tag = helper_with_tags.planet_tag_friends( friends_list) self.assertEquals(len(friends_activities_with_tag), 1) # --- Check notes --- all_planet_notes = helper_without_tags.planet_tag_notes() self.assertEquals(len(all_planet_notes), 4) # Post notes with 'comedy' tag notes_activities_with_tag = helper_with_tags.planet_tag_notes() self.assertEquals(len(notes_activities_with_tag), 2) similar_users_activities = helper_without_tags.planet_tag_similar_users( similar_users_list) self.assertEquals(len(similar_users_activities), 2) users_with_tags = helper_with_tags.planet_tag_similar_users( similar_users_list) self.assertEquals(len(users_with_tags), 1) activities = UserActivity.objects.all()
def test_planet_tag(self): # --- Initialize --- self.initialize() helper_without_tags = PlanetTagHelper() helper_with_tags = PlanetTagHelper(tag='comedy') recom_helper = RecomHelper() user_activity_helper = UserActivityHelper() # --- setup followers --- self.u1.followers.follow(self.u2) self.u1.followers.follow(self.u3) self.u1.followers.follow(self.u4) # similar users from film20.recommendations.bot_helper import do_create_comparators self.films_for_comparator() do_create_comparators() friends_list = recom_helper.get_following_ids_as_list(self.u1) friends_without_activities = helper_without_tags.planet_tag_friends(friends_list) self.assertEquals(len(friends_without_activities), 0) similar_users_list = user_activity_helper.get_similar_users_list(request) similar_users_without_tags = helper_without_tags.planet_tag_similar_users(similar_users_list) self.assertEquals(len(similar_users_without_tags), 0) notes_without_tags = helper_without_tags.planet_tag_notes() self.assertEquals(len(notes_without_tags), 0) all_planet_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_planet_activities), 0) # --- setup User activities --- post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 1) post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film1) post.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 2) obj = Object.objects.get(id=self.film2.id) shortreview = ShortReview() shortreview.user = self.u1 shortreview.review_text = "sialala bumcyk cyk" shortreview.status = Object.PUBLIC_STATUS shortreview.type = Object.TYPE_SHORT_REVIEW shortreview.object = obj shortreview.kind = ShortReview.REVIEW shortreview.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 3) # Activities with 'comedy' tag all_activities_with_tags = helper_with_tags.planet_tag_all() self.assertEquals(len(all_activities_with_tags), 1) # --- setup followers activities --- post = Post() post.title = "#1 Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u2 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 4) post = Post() post.title = "#2 Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u3 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film1) post.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 5) obj = Object.objects.get(id=self.film2.id) shortreview = ShortReview() shortreview.user = self.u4 shortreview.review_text = "sialala bumcyk cyk" shortreview.status = Object.PUBLIC_STATUS shortreview.type = Object.TYPE_SHORT_REVIEW shortreview.object = obj shortreview.kind = ShortReview.REVIEW shortreview.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 6) activities_with_tags = helper_with_tags.planet_tag_all() self.assertEquals(len(activities_with_tags), 2) all_friends_activities = helper_without_tags.planet_tag_friends(friends_list) self.assertEquals(len(all_friends_activities), 3) friends_activities_with_tag = helper_with_tags.planet_tag_friends(friends_list) self.assertEquals(len(friends_activities_with_tag), 1) # --- Check notes --- all_planet_notes = helper_without_tags.planet_tag_notes() self.assertEquals(len(all_planet_notes), 4) # Post notes with 'comedy' tag notes_activities_with_tag = helper_with_tags.planet_tag_notes() self.assertEquals(len(notes_activities_with_tag), 2) similar_users_activities = helper_without_tags.planet_tag_similar_users(similar_users_list) self.assertEquals(len(similar_users_activities), 2) users_with_tags = helper_with_tags.planet_tag_similar_users(similar_users_list) self.assertEquals(len(users_with_tags), 1) activities = UserActivity.objects.all()