def test_validate(self, stc):
     plLogger = PLLogger.GetLogger('methodology')
     plLogger.LogInfo("test_validate.begin")
     ctor = CScriptableCreator()
     cmd = ctor.CreateCommand(PKG + ".CreateMethodologyTestCaseCommand")
     CreateCmd.get_this_cmd = MagicMock(return_value=cmd)
     res = CreateCmd.validate('{"methodology_key" : "a", "display_name" : "b"}')
     assert res == ""
     res = CreateCmd.validate('{"methodology_key" : "vvvv"}')
     assert res != ""
     return
    def test_create_test_case(self, stc):
        plLogger = PLLogger.GetLogger('methodology')
        plLogger.LogInfo("test_create_test_case.begin")
        ctor = CScriptableCreator()
        meth_name = "TestMeth_CreateTestCase"
        meth_key = "UNITTEST_CREATEMETH"
        meth_description = "Test CreateTestCase Methodology Description"
        test_case_name = "CreateTestCase_Name"

        # Defaults
        copy_count = 20

        TestCreateTestCase.make_fake_test_pkg(copy_count,
                                              "UnitTestFakeMeth",
                                              meth_name, meth_key,
                                              meth_description)
        test_meth_obj = meth_man_utils.get_stm_methodology_from_key(meth_key)
        assert test_meth_obj is not None

        # Change the defaults in "original" meta by setting TestCaseName to test_case_name and
        # TestCaseDescription to test_case_description
        cmd = ctor.CreateCommand(PKG + ".CreateMethodologyTestCaseCommand")

        # Mock get_this_cmd to call run() directly
        CreateCmd.get_this_cmd = MagicMock(return_value=cmd)
        res = CreateCmd.run('{"methodology_key" : "' + meth_key + '",' +
                            '"display_name" : "' + test_case_name + '"}')
        assert res is True
        tc_key = cmd.Get("TestCaseKey")
        assert tc_key is not None
        assert tc_key == meth_key + "-1"
        tc_obj = meth_man_utils.get_stm_testcase_from_key(test_meth_obj, tc_key)
        assert tc_obj is not None
        assert tc_obj.IsTypeOf("StmTestCase")

        # Check the meta file exists
        install_dir = meth_man_utils.get_test_case_dir(meth_key, tc_key)
        assert install_dir
        meta_json_file_path = os.path.join(install_dir, mgr_const.MM_META_JSON_FILE_NAME)
        assert meta_json_file_path
        assert os.path.isfile(meta_json_file_path)

        j = ""
        plLogger.LogDebug('meta.json is at ' + meta_json_file_path)
        with open(meta_json_file_path, "r") as f:
            j = f.read()
            plLogger.LogDebug('meta.json content includes: "' + j + '"')
        err_str, meta = json_utils.load_json(j)
        assert err_str == ""
        assert meta is not None
        assert 'test_case_key' in meta
        assert meta['test_case_key'] == tc_key
        assert 'display_name' in meta
        assert meta['display_name'] == test_case_name

        cmd = ctor.CreateCommand(PKG + ".DeleteTestCaseCommand")
        cmd.Set("StmTestCase", tc_obj.GetObjectHandle())
        cmd.Execute()
        cmd.MarkDelete()

        cmd = ctor.CreateCommand(PKG + ".DeleteMethodologyCommand")
        cmd.Set("StmMethodology", test_meth_obj.GetObjectHandle())
        cmd.Execute()
        cmd.MarkDelete()

        plLogger.LogInfo("end")