def _construct_form_data(self): form = CommentSecurityForm(self.obj) timestamp = int(time.time()) security_hash = form.initial_security_hash(timestamp) self.data["content_type"] = ".".join((self.ct.app_label, self.ct.model)) self.data["timestamp"] = str(timestamp) self.data["security_hash"] = str(security_hash) self.data["next"] = "/next"
def _construct_form_data(self): form = CommentSecurityForm(self.obj) timestamp = int(time.time()) security_hash = form.initial_security_hash(timestamp) self.data["content_type"] = ".".join( (self.ct.app_label, self.ct.model)) self.data["timestamp"] = str(timestamp) self.data["security_hash"] = str(security_hash) self.data["next"] = "/next"
def test_empty_comment_form(self): """empty comment should send user to preview form""" self.c.login(username='******', password='******') # all this bullshit to create an empty f*****g comment data = {'content_type': 'stories.story', 'object_pk': '1', 'timestamp': str(int(time.time())), 'comment': ''} csf = CommentSecurityForm(self.story) security_hash = csf.generate_security_hash(data['content_type'], data['object_pk'], data['timestamp']) data['security_hash'] = security_hash response = self.c.post('/comments/post/', data) self.assertTemplateUsed(response, 'comments/preview.html')
def post_comment(self, entry_id=1, comment_text='Hello', author_name='Bobby'): """ Attempts to post a comment to an Entry. """ form = CommentSecurityForm( Entry.live.get(pk=entry_id) ) timestamp = int(time.time()) security_hash = form.initial_security_hash(timestamp) c = Client() response = c.post('/cmnt/post/', { 'name': author_name, 'email': '*****@*****.**', 'url': '', 'comment': comment_text, 'content_type': 'weblog.entry', 'timestamp': timestamp, 'object_pk': entry_id, 'security_hash': security_hash, },follow=True) return response