def test_fail_to_post_a_comment(self): # The long content will fail the process. comments = add_comment( self.tester, 'testcases.testcase', [self.case_1.pk], 'comment' * 2000) self.assertListEqual([], comments)
def test_ignore_nonexisting_object_pk(self): object_pks = [self.case_2.pk, 99999999] comments = add_comment( self.tester, 'testcases.testcase', object_pks, 'comment abc') self.assertEqual(1, len(comments)) self.assertEqual('comment abc', comments[0].comment)
def test_add_a_comment(self): comments = add_comment( self.tester, 'testcases.testcase', [self.case_1.pk], 'comment 1') self.assertEqual('comment 1', comments[0].comment) self.assertTrue( Comment.objects.filter( object_pk=self.case_1.pk, comment='comment 1').exists() )
def test_add_a_comment_to_multiple_objects(self): object_pks = [self.case_2.pk, self.case_3.pk] comments = add_comment( self.tester, 'testcases.testcase', object_pks, 'comment abc') self.assertEqual('comment abc', comments[0].comment) self.assertEqual('comment abc', comments[1].comment) for pk in object_pks: self.assertTrue(Comment.objects.filter( object_pk=pk, comment='comment abc').exists())
def test_get_comments(self, now): now.return_value = datetime(2017, 7, 7, 7, 7, 7) add_comment(self.tester, 'testruns.testcaserun', [self.case_run_4.pk, self.case_run_5.pk], 'new comment') add_comment(self.tester, 'testruns.testcaserun', [self.case_run_4.pk], 'make better') data = TestCaseRunDataMixin() comments = data.get_caseruns_comments(self.test_run_1.pk) comments[self.case_run_4.pk] = sorted( comments[self.case_run_4.pk], key=operator.itemgetter('comment')) expected_comments = { self.case_run_4.pk: [ { 'case_run_id': self.case_run_4.pk, 'user_name': self.tester.username, 'submit_date': now.return_value, 'comment': 'make better' }, { 'case_run_id': self.case_run_4.pk, 'user_name': self.tester.username, 'submit_date': now.return_value, 'comment': 'new comment' }, ], self.case_run_5.pk: [{ 'case_run_id': self.case_run_5.pk, 'user_name': self.tester.username, 'submit_date': now.return_value, 'comment': 'new comment' }] } self.assertEqual(expected_comments, comments)
def setUpTestData(cls): super().setUpTestData() cls.comment_author = f.UserFactory() user_should_have_perm(cls.tester, 'django_comments.can_moderate') cls.case_1 = f.TestCaseFactory() cls.case_2 = f.TestCaseFactory() add_comment(cls.tester, 'testcases.testcase', [cls.case_1.pk, cls.case_2.pk], 'first comment') add_comment(cls.tester, 'testcases.testcase', [cls.case_1.pk, cls.case_2.pk], 'second comment') add_comment(cls.tester, 'testcases.testcase', [cls.case_1.pk, cls.case_2.pk], 'third comment') add_comment(cls.comment_author, 'testcases.testcase', [cls.case_1.pk], '4th comment')
def setUpTestData(cls): super().setUpTestData() cls.tester = User.objects.create_user(username='******', email='*****@*****.**') cls.tester.set_password('password') cls.tester.save() cls.comment_author = f.UserFactory() user_should_have_perm(cls.tester, 'django_comments.can_moderate') cls.case_1 = f.TestCaseFactory() cls.case_2 = f.TestCaseFactory() add_comment(cls.tester, 'testcases.testcase', [cls.case_1.pk, cls.case_2.pk], 'first comment') add_comment(cls.tester, 'testcases.testcase', [cls.case_1.pk, cls.case_2.pk], 'second comment') add_comment(cls.tester, 'testcases.testcase', [cls.case_1.pk, cls.case_2.pk], 'third comment') add_comment(cls.comment_author, 'testcases.testcase', [cls.case_1.pk], '4th comment')