def test_report_document_to_dict(self, mock_date): mock_date.now = mock.MagicMock() mock_date.now.return_value = "now" report_doc = mreport.ReportDocument("name") report_doc.id = "id" report_doc.job = "job" report_doc.git_branch = "branch" report_doc.kernel = "kernel" report_doc.report_type = "boot" report_doc.status = "ERROR" report_doc.updated_on = "now" report_doc.errors = [(1, "msg")] expected = { "_id": "id", "created_on": "now", "errors": [(1, "msg")], "job": "job", "kernel": "kernel", "git_branch": "branch", "name": "name", "status": "ERROR", "type": "boot", "updated_on": "now", "version": "1.1" } self.assertDictEqual(expected, report_doc.to_dict())
def test_report_setter(self): report_doc = mreport.ReportDocument("name") report_doc.created_on = "now" report_doc.version = "foo" self.assertEqual("name", report_doc.name) self.assertEqual("now", report_doc.created_on) self.assertEqual("foo", report_doc.version)
def save_report(job, branch, kernel, r_type, status, errors, db_options): """Save the email report status in the database. It does not save the actual email report sent. :param job: The job name. :type job: str :param kernel: The kernel name. :type kernel: str :param r_type: The type of report to save. :type r_type: str :param status: The status of the send action. :type status: str :param errors: A list of errors from the send action. :type errors: list :param db_options: The mongodb database connection parameters. :type db_options: dict """ name = "%s-%s-%s" % (job, branch, kernel) utils.LOG.info("Saving '%s' report for '%s'", r_type, name) spec = { models.JOB_KEY: job, models.GIT_BRANCH_KEY: branch, models.KERNEL_KEY: kernel, models.NAME_KEY: name, models.TYPE_KEY: r_type } database = utils.db.get_db_connection(db_options) prev_doc = utils.db.find_one2(database[models.REPORT_COLLECTION], spec_or_id=spec) if prev_doc: report = mreport.ReportDocument.from_json(prev_doc) report.status = status report.errors = errors utils.db.save(database, report) else: report = mreport.ReportDocument(name) report.job = job report.kernel = kernel report.git_branch = branch report.report_type = r_type report.status = status report.errors = errors utils.db.save(database, report, manipulate=True)
def test_report_to_dict_simple(self): report_doc = mreport.ReportDocument("report") report_doc.created_on = "now" expected = { "created_on": "now", "errors": [], "job": None, "kernel": None, "git_branch": None, "name": "report", "status": None, "type": None, "updated_on": None, "version": "1.1" } self.assertDictEqual(expected, report_doc.to_dict())
def test_report_collection_name(self): report_doc = mreport.ReportDocument("name") self.assertEqual("report", report_doc.collection)
def test_report_document_valid_instance(self): report_doc = mreport.ReportDocument("name") self.assertIsInstance(report_doc, mbase.BaseDocument)