Exemplo n.º 1
0
    def test_set_name_setter(self):
        test_set = mtset.TestSetDocument("name", "test_suite_id", "1.0")

        def test_name_setter(value):
            test_set.name = value

        test_name_setter("foo")
        self.assertEqual("foo", test_set.name)
Exemplo n.º 2
0
    def test_set_defects_setter(self):
        test_set = mtset.TestSetDocument("name", "test_suite_id", "1.0")

        def test_defects_setter(value):
            test_set.defects = value

        test_defects_setter([])
        self.assertListEqual([], test_set.defects)
        test_defects_setter({"foo": "bar"})
        self.assertListEqual([{"foo": "bar"}], test_set.defects)
        test_defects_setter([{"baz": "foo"}])
        self.assertListEqual([{
            "foo": "bar"
        }, {
            "baz": "foo"
        }], test_set.defects)
Exemplo n.º 3
0
    def test_set_doc_test_case_setter(self):
        test_set = mtset.TestSetDocument("name", "test_suite_id", "1.0")

        def test_case_setter(value):
            test_set.test_case = value

        self.assertRaises(ValueError, test_case_setter, {"foo": "bar"})
        self.assertRaises(ValueError, test_case_setter, "foo")

        test_case_setter([])
        self.assertListEqual([], test_set.test_case)
        test_case_setter(())
        self.assertListEqual([], test_set.test_case)
        test_case_setter(None)
        self.assertListEqual([], test_set.test_case)
        test_case_setter("")
        self.assertListEqual([], test_set.test_case)
Exemplo n.º 4
0
    def test_set_doc_parameters_setter(self):
        test_set = mtset.TestSetDocument("name", "test_suite_id", "1.0")

        def parameters_setter(value):
            test_set.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_set.parameters)
        parameters_setter(())
        self.assertDictEqual({}, test_set.parameters)
        parameters_setter(None)
        self.assertDictEqual({}, test_set.parameters)
        parameters_setter("")
        self.assertDictEqual({}, test_set.parameters)
Exemplo n.º 5
0
    def test_set_doc_to_dict(self):
        test_set = mtset.TestSetDocument("name", "test_suite_id", "1.0")

        test_set.created_on = "now"
        test_set.definition_uri = "scheme://authority/path"
        test_set.id = "id"
        test_set.metadata = {"foo": "bar"}
        test_set.parameters = {"param": "value"}
        test_set.test_case = [{"foo": "bar"}]
        test_set.time = 10
        test_set.vcs_commit = "commit_sha"
        test_set.version = "1.1"
        test_set.test_suite_id = "another_id"
        test_set.test_job_url = "http://test.executor"
        test_set.test_job_path = "test/path/12345"
        test_set.test_job_id = "12345"
        test_set.test_suite_name = "suite-name"

        expected = {
            "_id": "id",
            "created_on": "now",
            "defects": [],
            "definition_uri": "scheme://authority/path",
            "metadata": {
                "foo": "bar"
            },
            "name": "name",
            "parameters": {
                "param": "value"
            },
            "test_case": [{
                "foo": "bar"
            }],
            "test_job_id": "12345",
            "test_job_path": "test/path/12345",
            "test_job_url": "http://test.executor",
            "test_suite_id": "another_id",
            "test_suite_name": "suite-name",
            "time": 10,
            "vcs_commit": "commit_sha",
            "version": "1.1"
        }

        self.assertDictEqual(expected, test_set.to_dict())
Exemplo n.º 6
0
 def test_set_doc_valid_instance(self):
     test_set = mtset.TestSetDocument("name", "test_suite_id", "1.0")
     self.assertIsInstance(test_set, mbase.BaseDocument)
     self.assertEqual(test_set.collection, "test_set")
Exemplo n.º 7
0
def import_and_save_test_sets(test_cases, test_sets,
                              tsu_id, tsu_name,
                              database, errors):
    """Parse the test set report from a JSON object.

    This function parses the test cases reports to find the distinct
    test set names. It creates database entries for each unique set name.
    The test_sets dict is updated accordingly with the IDs of created test
    sets. An operation code is returned for success / error.


    :param test_cases: The JSON object.
    :type test_cases: dict
    :param test_sets: Where to store the test sets references (name & ID).
    :type test_sets: dict
    :param tsu_id: The related test suite ID.
    :type tsu_id: str
    :param tsu_name: The related test suite name.
    :type tsu_name: str
    :param database: The database connection.
    :param errors: Where to store the errors.
    :type errors: dict
    :return the operation code (201 if the save has
    success, 500 in case of an error).
    """
    ret_code = 500
    # Python set(): unordered collections of unique elements
    test_sets_set = set()

    if not test_cases:
        return ret_code
    if not tsu_id or not tsu_name:
        return ret_code

    for test_case in test_cases:
        test_sets_set.add(test_case["set"])

    for test_set_name in test_sets_set:
        test_set_doc = mtest_set.TestSetDocument(
            name=test_set_name,
            test_suite_id=tsu_id)
        test_set_doc.test_suite_name = tsu_name
        test_set_doc.created_on = datetime.datetime.now(
            tz=bson.tz_util.utc)
        if test_set_doc:
            ret_code, test_set_doc_id = \
                save_or_update(test_set_doc, SPEC_TEST_SET,
                               models.TEST_SET_COLLECTION,
                               database, errors)
            # Each test set name = test set id
            test_sets[test_set_name] = test_set_doc_id

            if ret_code == 500:
                err_msg = (
                    "Error saving test set report in the database "
                    "for test suite '%s (%s)'" %
                    (
                        tsu_name,
                        tsu_id,
                    )
                )
                ERR_ADD(errors, ret_code, err_msg)
                return ret_code
            else:
                # Test set imported successfully, update test suite
                tests_import.update_test_suite_add_test_set_id(
                    test_set_doc_id, tsu_id, tsu_name,
                    taskc.app.conf.db_options,
                    taskc.app.conf.mail_options)

        else:
            return 500
    return ret_code