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_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_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_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_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 save_shortreview_as_post(shortreview, object, user): blogs = Blog.objects.select_related().get_or_create(user=user) blog = blogs[0] title = object.get_localized_title() if not title : title = object.title post = Post(title = _('Review') + ": " + title,\ body = shortreview, author = blog,\ permalink = slughifi(title + " " + " ".join((shortreview.split(' ')[:9])))[:128],\ type = Post.TYPE_POST,\ status = Post.PUBLIC_STATUS) post.save() post.related_film.add(object) return post
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_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_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_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 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 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 handle( self, *args, **options ): fetcher = Fetcher( '%s' % settings.BLOG_DOMAIN ) fetcher.fetch_posts() print " ++ %d POSTS TO SAVE ++" % len( fetcher.posts ) user, created = User.objects.get_or_create( username="******" ) for p in fetcher.posts: print " + saving post: %s" % p try: Post.objects.get( user=user, title=p.title, LANG=settings.LANGUAGE_CODE ) print " - already exists [SKIPING]" except Post.DoesNotExist: post = Post( title = p.title, user = user, body = p.content, publish = p.date, is_public = True, is_published = True, tag_list = p.tags ) post.save( permalink=p.url.split( '/' )[-1] )
def handle(self, *args, **options): fetcher = Fetcher('%s' % settings.BLOG_DOMAIN) fetcher.fetch_posts() print " ++ %d POSTS TO SAVE ++" % len(fetcher.posts) user, created = User.objects.get_or_create(username="******") for p in fetcher.posts: print " + saving post: %s" % p try: Post.objects.get(user=user, title=p.title, LANG=settings.LANGUAGE_CODE) print " - already exists [SKIPING]" except Post.DoesNotExist: post = Post(title=p.title, user=user, body=p.content, publish=p.date, is_public=True, is_published=True, tag_list=p.tags) post.save(permalink=p.url.split('/')[-1])
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_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_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_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_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_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)
class WatchingTestCase(TestCase): u1 = None u2 = None u3 = None u4 = None blog1 = None post1 = None def clean_data(self): User.objects.all().delete() Watching.objects.all().delete() notification.Notice.objects.all().delete() def setUp(self): Film.objects.filter(imdb_code__lt=1000).delete() def initialize(self): self.clean_data() # set up users self.u1 = User(username='******', email='*****@*****.**') self.u1.save() self.u2 = User(username='******', email='*****@*****.**') self.u2.save() self.u3 = User(username='******', email='*****@*****.**') self.u3.save() self.u4 = User(username='******', email='*****@*****.**') self.u4.save() #user self.blog1 self.blog1 = Blog(user=self.u1) self.blog1.save() # create a self.post1 from datetime import datetime self.post1 = Post(user=self.u1, title="New Post", type=Object.TYPE_POST, is_public=False, publish=datetime.now()) self.post1.save() def test_watching_subscribe(self): """ User u4 subscribes to a post by u1. Then a comment is added by another user u2. User u4 should receive a notification. Then user4 unsubscribes to the same post and user u2 adds one more comment. This time the reply notification should not be sent to u4. """ self.initialize() # subscribe to this self.post1 by a different user (who haven't commented on it) watching_helper = WatchingHelper() activity = UserActivity.objects.get_for_object(self.post1) # watching_helper.alter_watching_subscribed(self.u4, activity) Watching.subscribe(activity, self.u4, True) # create a comments for blog post by a different user t = ThreadedComment(user=self.u2, comment="This is a comment", content_object=activity, type=Object.TYPE_COMMENT) t.save() # assert all is fine watching_objects = Watching.objects.filter(is_observed=True) self.assertEquals(len(watching_objects), 3) # number of unique comments in threads should be equal to watching objects reply_notices = notification.Notice.objects.filter(notice_type__label='reply') # TODO: uncommend and fix in http://jira.filmaster.org/browse/FLM-1116 # self.assertEquals(len(reply_notices), 2) # number of notices # unsubscribe to the previously subscribed posts # watching_helper.alter_watching_subscribed(self.u4, activity) Watching.subscribe(activity, self.u4, False) # assert the number of observed watching objects is smaler by 1 watching_objects = Watching.objects.filter(is_observed=True) self.assertEquals(len(watching_objects), 2) # number of unique comments in threads should be equal to watching objects # create another comment for blog post by he same user than previously # (should generate 1 reply notification to the author of the post) t = ThreadedComment(user=self.u2, comment="This is also a comment, second one by the same user", content_object=activity, type=Object.TYPE_COMMENT) t.save() reply_notices = notification.Notice.objects.filter(notice_type__label='reply') # TODO: uncommend and fix in http://jira.filmaster.org/browse/FLM-1116 self.assertEquals(len(reply_notices), 3) # number of notices def test_watching_notification(self): """ Testing notifications for different types of activities (posts, short reviews and threads) """ self.initialize() activity = UserActivity.objects.get_for_object(self.post1) # create two comments for blog post by two different users t = ThreadedComment(user=self.u2, comment="This is a comment", content_object=activity, type=Object.TYPE_COMMENT) t.save() t = ThreadedComment(user=self.u3, comment="This is also a comment", content_object=activity, type=Object.TYPE_COMMENT) t.save() # create film and a short review and a comment to it f1 = Film(type=1, permalink='przypadek', imdb_code=111, status=1, version=1, release_year=1999, title='Przypadek', popularity=1, popularity_month=1) f1.save() sr = ShortReview(user=self.u1, review_text="This is a short review", object = f1, type=Object.TYPE_SHORT_REVIEW) sr.save() activity2 = UserActivity.objects.get_for_object(sr) t = ThreadedComment(user=self.u2, comment="This is a comment to a short review", content_object=activity2, type=Object.TYPE_COMMENT) t.save() # assert all is fine watching_objects = Watching.objects.all() self.assertEquals(len(watching_objects), 5) # number of unique comments in threads should be equal to watching objects reply_notices = notification.Notice.objects.filter(notice_type__label='reply') # TODO: uncommend and fix in http://jira.filmaster.org/browse/FLM-1116 self.assertEquals(len(reply_notices), 4) # number of notices
class ThreadedCommentTestCase(TestCase): u1 = None film = None def initialize(self): self.clean_data() # set up users self.u1= User.objects.create_user('michuk', '*****@*****.**', 'secret') self.u1.save() # set up post self.post = Post() self.post.title = "Lorem ipsum" self.post.body = "Sialalala tralalal!" self.post.type = Object.TYPE_POST self.post.permalink = "lorem-ipsum" self.post.status = Post.PUBLIC_STATUS self.post.user = self.u1 self.post.save() def clean_data(self): User.objects.all().delete() Post.objects.all().delete() Blog.objects.all().delete() ThreadedComment.objects.all().delete() def test_comments(self): self.initialize() self.client.login(username=self.u1.username, password='******') # take url for new comment comment_form_url = get_comment_url(self.post) data = { 'comment' : "Tralala bum bum bum", 'next' : self.post.get_absolute_url() } # send data response = self.client.post( comment_form_url, data, ) # if success there should be one comment in db self.failUnlessEqual(len(ThreadedComment.objects.all()), 1) comment = ThreadedComment.objects.get(user=self.u1) # try to delete comment delete_comment_url = "/"+urls["DELETE_COMMENT"]+'/'+str(comment.id)+"/" response = self.client.get( delete_comment_url, ) @unittest.skip("comment delete view not available yet") def test_comment_delete(self): self.initialize() self.client.login(username=self.u1.username, password='******') # take url for new comment comment_form_url = get_comment_url(self.post) data = { 'comment' : "Tralala bum bum bum", 'next' : self.post.get_absolute_url() } # send data response = self.client.post( comment_form_url, data, ) # if success there should be one comment in db self.failUnlessEqual(len(ThreadedComment.objects.all()), 1) comment = ThreadedComment.objects.get(user=self.u1) # try to delete comment delete_comment_url = "/"+urls["DELETE_COMMENT"]+'/'+str(comment.id)+"/" response = self.client.get( delete_comment_url, ) comment = ThreadedComment.objects.get(user=self.u1) # comment in db should have DELETED_STATUS self.failUnlessEqual(comment.status, Object.DELETED_STATUS) def test_comments_ajax(self): self.initialize() self.client.login(username=self.u1.username, password='******') # url for new comment comment_form_url = get_comment_url(self.post) comment_form_url += 'json/' data = { 'comment' : "Tralala bum bum bum", } # sending using ajax response = self.client.post( comment_form_url, data, HTTP_X_REQUESTED_WITH='XMLHttpRequest' ) # if everything is ok - response code should be 200 self.failUnlessEqual(response.status_code, 200)
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)
class WatchingTestCase(TestCase): u1 = None u2 = None u3 = None u4 = None blog1 = None post1 = None def clean_data(self): User.objects.all().delete() Watching.objects.all().delete() notification.Notice.objects.all().delete() def setUp(self): Film.objects.filter(imdb_code__lt=1000).delete() def initialize(self): self.clean_data() # set up users self.u1 = User(username='******', email='*****@*****.**') self.u1.save() self.u2 = User(username='******', email='*****@*****.**') self.u2.save() self.u3 = User(username='******', email='*****@*****.**') self.u3.save() self.u4 = User(username='******', email='*****@*****.**') self.u4.save() #user self.blog1 self.blog1 = Blog(user=self.u1) self.blog1.save() # create a self.post1 from datetime import datetime self.post1 = Post(user=self.u1, title="New Post", type=Object.TYPE_POST, is_public=False, publish=datetime.now()) self.post1.save() def test_watching_subscribe(self): """ User u4 subscribes to a post by u1. Then a comment is added by another user u2. User u4 should receive a notification. Then user4 unsubscribes to the same post and user u2 adds one more comment. This time the reply notification should not be sent to u4. """ self.initialize() # subscribe to this self.post1 by a different user (who haven't commented on it) watching_helper = WatchingHelper() activity = UserActivity.objects.get_for_object(self.post1) # watching_helper.alter_watching_subscribed(self.u4, activity) Watching.subscribe(activity, self.u4, True) # create a comments for blog post by a different user t = ThreadedComment(user=self.u2, comment="This is a comment", content_object=activity, type=Object.TYPE_COMMENT) t.save() # assert all is fine watching_objects = Watching.objects.filter(is_observed=True) self.assertEquals( len(watching_objects), 3 ) # number of unique comments in threads should be equal to watching objects reply_notices = notification.Notice.objects.filter( notice_type__label='reply') # TODO: uncommend and fix in http://jira.filmaster.org/browse/FLM-1116 # self.assertEquals(len(reply_notices), 2) # number of notices # unsubscribe to the previously subscribed posts # watching_helper.alter_watching_subscribed(self.u4, activity) Watching.subscribe(activity, self.u4, False) # assert the number of observed watching objects is smaler by 1 watching_objects = Watching.objects.filter(is_observed=True) self.assertEquals( len(watching_objects), 2 ) # number of unique comments in threads should be equal to watching objects # create another comment for blog post by he same user than previously # (should generate 1 reply notification to the author of the post) t = ThreadedComment( user=self.u2, comment="This is also a comment, second one by the same user", content_object=activity, type=Object.TYPE_COMMENT) t.save() reply_notices = notification.Notice.objects.filter( notice_type__label='reply') # TODO: uncommend and fix in http://jira.filmaster.org/browse/FLM-1116 self.assertEquals(len(reply_notices), 3) # number of notices def test_watching_notification(self): """ Testing notifications for different types of activities (posts, short reviews and threads) """ self.initialize() activity = UserActivity.objects.get_for_object(self.post1) # create two comments for blog post by two different users t = ThreadedComment(user=self.u2, comment="This is a comment", content_object=activity, type=Object.TYPE_COMMENT) t.save() t = ThreadedComment(user=self.u3, comment="This is also a comment", content_object=activity, type=Object.TYPE_COMMENT) t.save() # create film and a short review and a comment to it f1 = Film(type=1, permalink='przypadek', imdb_code=111, status=1, version=1, release_year=1999, title='Przypadek', popularity=1, popularity_month=1) f1.save() sr = ShortReview(user=self.u1, review_text="This is a short review", object=f1, type=Object.TYPE_SHORT_REVIEW) sr.save() activity2 = UserActivity.objects.get_for_object(sr) t = ThreadedComment(user=self.u2, comment="This is a comment to a short review", content_object=activity2, type=Object.TYPE_COMMENT) t.save() # assert all is fine watching_objects = Watching.objects.all() self.assertEquals( len(watching_objects), 5 ) # number of unique comments in threads should be equal to watching objects reply_notices = notification.Notice.objects.filter( notice_type__label='reply') # TODO: uncommend and fix in http://jira.filmaster.org/browse/FLM-1116 self.assertEquals(len(reply_notices), 4) # number of notices
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()
class ThreadedCommentTestCase(TestCase): u1 = None film = None def initialize(self): self.clean_data() # set up users self.u1 = User.objects.create_user('michuk', '*****@*****.**', 'secret') self.u1.save() # set up post self.post = Post() self.post.title = "Lorem ipsum" self.post.body = "Sialalala tralalal!" self.post.type = Object.TYPE_POST self.post.permalink = "lorem-ipsum" self.post.status = Post.PUBLIC_STATUS self.post.user = self.u1 self.post.save() def clean_data(self): User.objects.all().delete() Post.objects.all().delete() Blog.objects.all().delete() ThreadedComment.objects.all().delete() def test_comments(self): self.initialize() self.client.login(username=self.u1.username, password='******') # take url for new comment comment_form_url = get_comment_url(self.post) data = { 'comment': "Tralala bum bum bum", 'next': self.post.get_absolute_url() } # send data response = self.client.post( comment_form_url, data, ) # if success there should be one comment in db self.failUnlessEqual(len(ThreadedComment.objects.all()), 1) comment = ThreadedComment.objects.get(user=self.u1) # try to delete comment delete_comment_url = "/" + urls["DELETE_COMMENT"] + '/' + str( comment.id) + "/" response = self.client.get(delete_comment_url, ) @unittest.skip("comment delete view not available yet") def test_comment_delete(self): self.initialize() self.client.login(username=self.u1.username, password='******') # take url for new comment comment_form_url = get_comment_url(self.post) data = { 'comment': "Tralala bum bum bum", 'next': self.post.get_absolute_url() } # send data response = self.client.post( comment_form_url, data, ) # if success there should be one comment in db self.failUnlessEqual(len(ThreadedComment.objects.all()), 1) comment = ThreadedComment.objects.get(user=self.u1) # try to delete comment delete_comment_url = "/" + urls["DELETE_COMMENT"] + '/' + str( comment.id) + "/" response = self.client.get(delete_comment_url, ) comment = ThreadedComment.objects.get(user=self.u1) # comment in db should have DELETED_STATUS self.failUnlessEqual(comment.status, Object.DELETED_STATUS) def test_comments_ajax(self): self.initialize() self.client.login(username=self.u1.username, password='******') # url for new comment comment_form_url = get_comment_url(self.post) comment_form_url += 'json/' data = { 'comment': "Tralala bum bum bum", } # sending using ajax response = self.client.post(comment_form_url, data, HTTP_X_REQUESTED_WITH='XMLHttpRequest') # if everything is ok - response code should be 200 self.failUnlessEqual(response.status_code, 200)