def test_grouping_comments(self, _): """Test that comments are grouped by parent object in daily digest data.""" factories.AuditFactory(slug="Audit") self.import_file("assessment_template_no_warnings.csv") self.import_file("assessment_with_templates.csv") asmt1 = Assessment.query.filter_by(slug="A 1").first() asmt4 = Assessment.query.filter_by(slug="A 4").first() asmt6 = Assessment.query.filter_by(slug="A 6").first() asmt_ids = (asmt1.id, asmt4.id, asmt6.id) self.generator.generate_comment(asmt1, "Verifiers", "comment X on asmt " + str(asmt1.id), send_notification="true") self.generator.generate_comment(asmt6, "Verifiers", "comment A on asmt " + str(asmt6.id), send_notification="true") self.generator.generate_comment(asmt4, "Verifiers", "comment FOO on asmt " + str(asmt4.id), send_notification="true") self.generator.generate_comment(asmt4, "Verifiers", "comment BAR on asmt " + str(asmt4.id), send_notification="true") self.generator.generate_comment(asmt1, "Verifiers", "comment Y on asmt " + str(asmt1.id), send_notification="true") _, notif_data = common.get_daily_notifications() assignee_notifs = notif_data.get("*****@*****.**", {}) common.sort_comments(assignee_notifs) comment_notifs = assignee_notifs.get("comment_created", {}) self.assertEqual(len(comment_notifs), 3) # for 3 different Assessments # for each group of comment notifications, check that it contains comments # for that particular Assessment for parent_obj_key, comments_info in comment_notifs.iteritems(): self.assertIn(parent_obj_key.id, asmt_ids) for comment in comments_info: self.assertEqual(comment["parent_id"], parent_obj_key.id) self.assertEqual(comment["parent_type"], "Assessment") expected_suffix = "asmt " + str(parent_obj_key.id) self.assertTrue( comment["description"].endswith(expected_suffix))
def test_grouping_comments(self, _): """Test that comments are grouped by parent object in daily digest data.""" factories.AuditFactory(slug="Audit") self.import_file("assessment_template_no_warnings.csv") self.import_file("assessment_with_templates.csv") asmt1 = Assessment.query.filter_by(slug="A 1").first() asmt4 = Assessment.query.filter_by(slug="A 4").first() asmt6 = Assessment.query.filter_by(slug="A 6").first() asmt_ids = (asmt1.id, asmt4.id, asmt6.id) self.generator.generate_comment( asmt1, "Verifiers", "comment X on asmt " + str(asmt1.id), send_notification="true") self.generator.generate_comment( asmt6, "Verifiers", "comment A on asmt " + str(asmt6.id), send_notification="true") self.generator.generate_comment( asmt4, "Verifiers", "comment FOO on asmt " + str(asmt4.id), send_notification="true") self.generator.generate_comment( asmt4, "Verifiers", "comment BAR on asmt " + str(asmt4.id), send_notification="true") self.generator.generate_comment( asmt1, "Verifiers", "comment Y on asmt " + str(asmt1.id), send_notification="true") _, notif_data = common.get_daily_notifications() assignee_notifs = notif_data.get("*****@*****.**", {}) common.sort_comments(assignee_notifs) comment_notifs = assignee_notifs.get("comment_created", {}) self.assertEqual(len(comment_notifs), 3) # for 3 different Assessments # for each group of comment notifications, check that it contains comments # for that particular Assessment for parent_obj_key, comments_info in comment_notifs.iteritems(): self.assertIn(parent_obj_key.id, asmt_ids) for comment in comments_info: self.assertEqual(comment["parent_id"], parent_obj_key.id) self.assertEqual(comment["parent_type"], "Assessment") expected_suffix = "asmt " + str(parent_obj_key.id) self.assertTrue(comment["description"].endswith(expected_suffix))
def test_sorts_comments_inline_newest_first(self): """Test that comments data is sorted by creation date (descending).""" asmt5_info = (5, "Assessment", "Asmt 5", "www.5.com") data = { "*****@*****.**": { "comment_created": { asmt5_info: { 12: { "description": "ABCD...", "created_at": datetime(2017, 5, 31, 8, 15, 0) }, 19: { "description": "All tasks can be closed", "created_at": datetime(2017, 10, 16, 0, 30, 0) }, 10: { "description": "Comment One", "created_at": datetime(2017, 5, 29, 16, 20, 0) }, 15: { "description": "I am confused", "created_at": datetime(2017, 8, 15, 11, 13, 0) } } } } } sort_comments(data) comment_data = data["*****@*****.**"]["comment_created"].values()[0] self.assertIsInstance(comment_data, list) descriptions = [c["description"] for c in comment_data] expected_descriptions = [ "All tasks can be closed", "I am confused", "ABCD...", "Comment One" ] self.assertEqual(descriptions, expected_descriptions)
def test_grouping_comments(self, _): # pylint: disable=too-many-locals """Test that comments are grouped by parent object in daily digest data.""" with factories.single_commit(): audit = factories.AuditFactory() audit_slug = audit.slug asmt_templ = factories.AssessmentTemplateFactory(audit=audit) asmt_templ_slug = asmt_templ.slug assessments_data = [ collections.OrderedDict([ ("object_type", "Assessment"), ("Code*", ""), ("Audit*", audit_slug), ("Assignees*", "*****@*****.**"), ("Creators", "*****@*****.**"), ("Template", ""), ("Title", "A1"), ]), collections.OrderedDict([ ("object_type", "Assessment"), ("Code*", ""), ("Audit*", audit_slug), ("Assignees*", "*****@*****.**"), ("Creators", "*****@*****.**"), ("Template", asmt_templ_slug), ("Title", "A2"), ]), collections.OrderedDict([ ("object_type", "Assessment"), ("Code*", ""), ("Audit*", audit_slug), ("Assignees*", "*****@*****.**"), ("Creators", "*****@*****.**"), ("Template", asmt_templ_slug), ("Title", "A3"), ]), ] self.import_data(*assessments_data) asmt_with_no_templ = Assessment.query.filter_by(title="A1").first() asmt_with_templ_1 = Assessment.query.filter_by(title="A2").first() asmt_with_templ_2 = Assessment.query.filter_by(title="A3").first() asmt_ids = (asmt_with_no_templ.id, asmt_with_templ_1.id, asmt_with_templ_2.id) self.generator.generate_comment(asmt_with_no_templ, "Verifiers", "comment X on asmt " + str(asmt_with_no_templ.id), send_notification="true") self.generator.generate_comment(asmt_with_templ_2, "Verifiers", "comment A on asmt " + str(asmt_with_templ_2.id), send_notification="true") self.generator.generate_comment(asmt_with_templ_1, "Verifiers", "comment FOO on asmt " + str(asmt_with_templ_1.id), send_notification="true") self.generator.generate_comment(asmt_with_templ_1, "Verifiers", "comment BAR on asmt " + str(asmt_with_templ_1.id), send_notification="true") self.generator.generate_comment(asmt_with_no_templ, "Verifiers", "comment Y on asmt " + str(asmt_with_no_templ.id), send_notification="true") _, notif_data = common.get_daily_notifications() assignee_notifs = notif_data.get("*****@*****.**", {}) common.sort_comments(assignee_notifs) comment_notifs = assignee_notifs.get("comment_created", {}) self.assertEqual(len(comment_notifs), 3) # for 3 different Assessments # for each group of comment notifications, check that it contains comments # for that particular Assessment for parent_obj_key, comments_info in comment_notifs.iteritems(): self.assertIn(parent_obj_key.id, asmt_ids) for comment in comments_info: self.assertEqual(comment["parent_id"], parent_obj_key.id) self.assertEqual(comment["parent_type"], "Assessment") expected_suffix = "asmt " + str(parent_obj_key.id) self.assertTrue( comment["description"].endswith(expected_suffix))