def test_not_anonymous_form(self): idea = create_idea() data = get_valid_form_data(idea) f = MPTTCommentForm(idea, data=data) c = f.get_comment_object() self.assertTrue(isinstance(c, MPTTComment)) self.assertEqual(c.is_anonymous, False)
def test_anonymous_form(self): idea = create_idea() data = get_valid_form_data(idea) data['is_anonymous'] = True f = MPTTCommentForm(idea, data=data) c = f.get_comment_object() self.assertTrue(isinstance(c, MPTTComment)) self.assertEqual(c.is_anonymous, True) # (It is up to the front end to hide the name) self.assertEqual(c.user_name, data['name'])
def get_valid_form_data(obj): f = MPTTCommentForm(obj) data = {} data['comment'] = "sample comment" user = random_user() data['name'] = user.username data['email'] = user.email data.update(f.initial) return data
def test_anonymous_comment_hidden_name(self): idea = create_idea() data = get_valid_form_data(idea) data['is_anonymous'] = True f = MPTTCommentForm(idea, data=data) c = f.get_comment_object() c.save() create_superuser() login(self) resp = self.client.get(reverse('idea:idea_detail', args=(idea.id,))) self.assertFalse(data['name'] in resp.content) # add a second comment where anonymous = False data['is_anonymous'] = False data['comment'] = "new comment" f = MPTTCommentForm(idea, data=data) c = f.get_comment_object() c.save() resp = self.client.get(reverse('idea:idea_detail', args=(idea.id,))) self.assertTrue(data['name'] in resp.content)
def test_anonymous_comment_hidden_name(self): idea = create_idea() data = get_valid_form_data(idea) data['is_anonymous'] = True f = MPTTCommentForm(idea, data=data) c = f.get_comment_object() c.save() create_superuser() login(self) resp = self.client.get(reverse('idea:idea_detail', args=(idea.id, ))) self.assertFalse(data['name'] in resp.content) # add a second comment where anonymous = False data['is_anonymous'] = False data['comment'] = "new comment" f = MPTTCommentForm(idea, data=data) c = f.get_comment_object() c.save() resp = self.client.get(reverse('idea:idea_detail', args=(idea.id, ))) self.assertTrue(data['name'] in resp.content)