def test_get_url(self): from comment.tests.base import RequestFactory factory = RequestFactory() request = factory.get('/') request.user = self.user_1 attr = 'COMMENT_PER_PAGE' comment = self.parent_comment_3 # no pagination(parent comment 3, 2, 1 belong to the same content_object_1) with patch.object(settings, attr, 0): comment_url = comment.content_object.get_absolute_url( ) + '#' + comment.urlhash self.assertEqual(comment_url, comment.get_url(request)) # with pagination with patch.object(settings, attr, 3): # comment on first page self.assertEqual(comment_url, comment.get_url(request)) # comment on the second page comment = self.parent_comment_1 comment_url = comment.content_object.get_absolute_url( ) + '?page=2' + '#' + comment.urlhash self.assertEqual(comment_url, comment.get_url(request))
def setUp(self): super().setUp() self.time_posted = timezone.now() _email = '*****@*****.**' _content = 'posting anonymous comment' _parent = None _factory = RequestFactory() self.comment_obj = Comment(content_object=self.post_1, content=_content, user=None, parent=_parent, email=_email, posted=self.time_posted) self.key = signing.dumps(self.comment_obj.to_dict(), compress=True) self.request = _factory.get('/')
def setUp(self): super().setUp() factory = RequestFactory() self.request = factory.get('/')
def setUpTestData(cls): super().setUpTestData() cls.request = RequestFactory().get('/') cls.request.user = cls.user_1