def test_doc_to_dict(self): doc = msumm.ErrorSummaryDocument("job_id", "1.1") doc.git_branch = "branch" doc.errors = [("error1", 1)] doc.job = "job" doc.kernel = "kernel" doc.mismatches = [("mismatch1", 1)] doc.warnings = [("warning1", 1)] doc.created_on = "today" doc.version = "1.1" expected = { "created_on": "today", "errors": [("error1", 1)], "git_branch": "branch", "job": "job", "job_id": "job_id", "kernel": "kernel", "mismatches": [("mismatch1", 1)], "version": "1.1", "warnings": [("warning1", 1)] } self.assertDictEqual(expected, doc.to_dict()) doc.id = "id" expected["_id"] = "id" self.assertDictEqual(expected, doc.to_dict())
def _create_new_summary(errors, warnings, mismatches, job_id, build_doc, database): """Save a new error summary in the database. :param errors: :type errors: dict :param warnings: :type warnings: dict :param mismatches: :type mismatches: :param job_id: :type job_id: bson.objectid.ObjectId :param build_doc: The BuildDocument. :type build_doc: BuildDocument :param database: The database connection. :return The return value from the save operation. """ error_summary = mesumm.ErrorSummaryDocument(job_id, "1.1") error_summary.created_on = datetime.datetime.now(tz=bson.tz_util.utc) error_summary.job = build_doc.job error_summary.kernel = build_doc.kernel error_summary.git_branch = build_doc.git_branch # Store the summary as lists of 2-tuple values. error_summary.errors = _dict_to_list(errors) error_summary.mismatches = _dict_to_list(mismatches) error_summary.warnings = _dict_to_list(warnings) ret_val, _ = utils.db.save(database, error_summary, manipulate=True) return ret_val
def test_doc_wrong_lists(self): doc = msumm.ErrorSummaryDocument("job_id", "1.1") self.assertRaises(TypeError, setattr, doc, "errors", {}) self.assertRaises(TypeError, setattr, doc, "errors", "") self.assertRaises(TypeError, setattr, doc, "errors", 0) self.assertRaises(TypeError, setattr, doc, "errors", ()) self.assertRaises(TypeError, setattr, doc, "warnings", {}) self.assertRaises(TypeError, setattr, doc, "warnings", "") self.assertRaises(TypeError, setattr, doc, "warnings", 0) self.assertRaises(TypeError, setattr, doc, "warnings", ()) self.assertRaises(TypeError, setattr, doc, "mismatches", {}) self.assertRaises(TypeError, setattr, doc, "mismatches", "") self.assertRaises(TypeError, setattr, doc, "mismatches", 0) self.assertRaises(TypeError, setattr, doc, "mismatches", ())
def test_doc_collection(self): doc = msumm.ErrorSummaryDocument("job_id", "1.1") self.assertEqual("errors_summary", doc.collection)
def test_doc_valid_instance(self): doc = msumm.ErrorSummaryDocument("job_id", "1.1") self.assertIsInstance(doc, modb.BaseDocument) self.assertIsInstance(doc, msumm.ErrorSummaryDocument)