def test_set_name_setter(self): test_case = mtcase.TestCaseDocument("name", "test_suite_id", "1.0") def test_name_setter(value): test_case.name = value test_name_setter("foo") self.assertEqual("foo", test_case.name)
def test_case_doc_to_dict(self): test_case = mtcase.TestCaseDocument("name", "1.1") test_case.id = "id" test_case.arch = "gothic" test_case.created_on = "now" test_case.build_environment = "tcc-0.9" test_case.defconfig_full = "defconfig+SOMETHING=y" test_case.device_type = "supercar" test_case.git_branch = "branch" test_case.git_commit = "1234abc" test_case.index = 1 test_case.job = "this-job" test_case.kernel = "v123.45" test_case.lab_name = "secret" test_case.log_lines = [{ 'dt': datetime(1970, 1, 1, 0, 0, 0), 'msg': 'foo'}] test_case.device_type = "supercar" test_case.mach = "batmobile" test_case.measurements = [{"foo": 1}] test_case.plan = "cunning" test_case.regression_id = 1234 test_case.status = "FAIL" test_case.test_case_path = "test.case.path" test_case.test_group_id = "another_id" test_case.time = 10 expected = { "_id": "id", "arch": "gothic", "build_environment": "tcc-0.9", "created_on": "now", "defconfig_full": "defconfig+SOMETHING=y", "device_type": "supercar", "git_branch": "branch", "git_commit": "1234abc", "index": 1, "job": "this-job", "kernel": "v123.45", "lab_name": "secret", "log_lines": [{ 'dt': datetime(1970, 1, 1, 0, 0, 0), 'msg': 'foo'}], "mach": "batmobile", "measurements": [{"foo": 1}], "name": "name", "plan": "cunning", "regression_id": 1234, "status": "FAIL", "test_case_path": "test.case.path", "test_group_id": "another_id", "time": 10, "version": "1.1" } self.assertDictEqual(expected, test_case.to_dict())
def test_case_doc_to_dict(self): test_case = mtcase.TestCaseDocument("name", "test_suite_id", "1.0") test_case.id = "id" test_case.attachments = [{"foo": "bar"}] test_case.created_on = "now" test_case.definition_uri = "scheme://authority/path" test_case.index = 1 test_case.kvm_guest = "kvm_guest" test_case.maximum = 1 test_case.measurements = [{"foo": 1}] test_case.metadata = {"foo": "bar"} test_case.minimum = -1 test_case.parameters = {"param": "value"} test_case.samples = 10 test_case.samples_sqr_sum = 1 test_case.samples_sum = 1 test_case.status = "FAIL" test_case.test_group_id = "another_id" test_case.test_group_name = "test-suite" test_case.time = 10 test_case.vcs_commit = "commit_sha" test_case.version = "1.1" expected = { "_id": "id", "attachments": [{ "foo": "bar" }], "created_on": "now", "definition_uri": "scheme://authority/path", "index": 1, "kvm_guest": "kvm_guest", "maximum": 1, "measurements": [{ "foo": 1 }], "metadata": { "foo": "bar" }, "minimum": -1, "name": "name", "parameters": { "param": "value" }, "samples": 10, "samples_sqr_sum": 1, "samples_sum": 1, "status": "FAIL", "test_group_id": "another_id", "test_group_name": "test-suite", "time": 10, "vcs_commit": "commit_sha", "version": "1.1" } self.assertDictEqual(expected, test_case.to_dict())
def test_case_doc_set_status(self): test_case = mtcase.TestCaseDocument("name", "test_suite_id", "1.0") def set_status(value): test_case.status = value self.assertEqual("PASS", test_case.status) self.assertRaises(ValueError, set_status, "FOO") self.assertRaises(ValueError, set_status, "") self.assertRaises(ValueError, set_status, 1) self.assertRaises(ValueError, set_status, {}) self.assertRaises(ValueError, set_status, []) self.assertRaises(ValueError, set_status, ())
def test_case_doc_add_measurement(self): test_case = mtcase.TestCaseDocument("name", "test_suite_id", "1.0") def add_measurement(value): test_case.add_measurement(value) test_case.measurements = [{"foo": "bar"}] test_case.add_measurement({"baz": "foo"}) expected = [{"foo": "bar"}, {"baz": "foo"}] self.assertListEqual(expected, test_case.measurements) self.assertRaises(ValueError, add_measurement, "") self.assertRaises(ValueError, add_measurement, []) self.assertRaises(ValueError, add_measurement, {}) self.assertRaises(ValueError, add_measurement, ())
def test_case_doc_parameters_setter(self): test_case = mtcase.TestCaseDocument("name", "test_suite_id", "1.0") def parameters_setter(value): test_case.parameters = value self.assertRaises(ValueError, parameters_setter, ["foo"]) self.assertRaises(ValueError, parameters_setter, ("foo")) self.assertRaises(ValueError, parameters_setter, "foo") parameters_setter([]) self.assertDictEqual({}, test_case.parameters) parameters_setter(()) self.assertDictEqual({}, test_case.parameters) parameters_setter(None) self.assertDictEqual({}, test_case.parameters) parameters_setter("") self.assertDictEqual({}, test_case.parameters)
def test_case_doc_measurements_setter(self): test_case = mtcase.TestCaseDocument("name", "test_suite_id", "1.0") def measurements_setter(value): test_case.measurements = value self.assertRaises(ValueError, measurements_setter, {"foo": "bar"}) self.assertRaises(ValueError, measurements_setter, "foo") measurements_setter([]) self.assertListEqual([], test_case.measurements) measurements_setter(()) self.assertListEqual([], test_case.measurements) measurements_setter(None) self.assertListEqual([], test_case.measurements) measurements_setter("") self.assertListEqual([], test_case.measurements) measurements_setter({}) self.assertListEqual([], test_case.measurements)
except TestValidationError, ex: utils.LOG.exception(ex) ERR_ADD(errors, 400, str(ex)) return None try: name = test_case[models.NAME_KEY] status = test_case[models.STATUS_KEY].upper() except KeyError, ex: err_msg = "Missing mandatory key in test case data" utils.LOG.exception(ex) utils.LOG.error(err_msg) ERR_ADD(errors, 400, err_msg) return None test_doc = mtest_case.TestCaseDocument(name=name, status=status) test_doc.created_on = datetime.datetime.now(tz=bson.tz_util.utc) _update_test_case_doc_from_json(test_doc, test_case, errors) _update_test_case_doc_ids(group_name, group_doc_id, test_doc, database) return test_doc def _update_test_group_doc_from_json(group_doc, test_dict, errors): """Update a TestGroupDocument from the provided test dictionary. This function does not return anything, the TestGroupDocument passed is updated from the values found in the provided JSON object. :param group_doc: The TestGroupDocument to update. :type group_doc: `models.test_group.TestGroupDocument`. :param test_dict: Test group dictionary.
def test_case_doc_valid_instance(self): test_case = mtcase.TestCaseDocument("name", "test_suite_id", "1.0") self.assertIsInstance(test_case, mbase.BaseDocument) self.assertEqual(test_case.collection, "test_case")
_check_for_null(test_case, NON_NULL_KEYS_CASE) except TestValidationError, ex: utils.LOG.exception(ex) ERR_ADD(errors, 400, str(ex)) return None try: name = test_case[models.NAME_KEY] except KeyError, ex: err_msg = "Missing mandatory key in test case data" utils.LOG.exception(ex) utils.LOG.error(err_msg) ERR_ADD(errors, 400, err_msg) return None test_doc = mtest_case.TestCaseDocument(name) test_doc.created_on = datetime.datetime.now(tz=bson.tz_util.utc) test_doc.test_case_path = '.'.join(path + [test_doc.name]) test_doc.plan = path[0] _update_test_case_doc_from_json(test_doc, group_doc, test_case, errors) return test_doc def _update_test_group_doc_from_json(group_doc, group_dict, errors): """Update a TestGroupDocument from the provided test dictionary. This function does not return anything, the TestGroupDocument passed is updated from the values found in the provided JSON object. :param group_doc: The TestGroupDocument to update. :type group_doc: `models.test_group.TestGroupDocument`.
def test_name(self): test_case = mtcase.TestCaseDocument("foo") self.assertEqual("foo", test_case.name)