def test_rhd_should_pass_data_file_to_hooks(hooks_dir, env_dump, mkstemp_path, var_name, hook_type): hooks._runHooksDir(None, hooks_dir.basename, hookType=hook_type) with open(env_dump, "rb") as f: env = pickle.load(f) assert env[var_name] == mkstemp_path
def test_rhd_should_assemble_environment_for_hooks(hooks_dir, env_dump, vmconf, params, expected): hooks._runHooksDir(u"", hooks_dir.basename, vmconf, params=params) with open(env_dump, "rb") as f: env = pickle.load(f) for k, v in expected.items(): assert env[k] == v
def test_deviceVmConfProperties(self): with self._deviceCustomPropertiesTestFile() as dirName: vmconf = {'custom': {'customProperty': ' rocks more!'}} result = hooks._runHooksDir("oVirt", dirName, params={'customProperty': ' rocks!'}, vmconf=vmconf) self.assertEqual(result, "oVirt rocks more!")
def test_deviceVmConfProperties(self): with self._deviceCustomPropertiesTestFile() as dirName: vmconf = { 'custom': { 'customProperty': ' rocks more!'}} result = hooks._runHooksDir("oVirt", dirName, params={'customProperty': ' rocks!'}, vmconf=vmconf) self.assertEqual(result, "oVirt rocks more!")
def test_runHooksDir(self): # Add an unicode value to the environment variables # to test whether the utf-8 recoding works properly os.environ["FAKE_GERRIT_USERNAME"] = "******" with self.tempScripts() as (dirName, scripts): Q = 3 DOMXML = "algo" expectedResult = DOMXML for n in range(Q): expectedResult = expectedResult + str(n) res = hooks._runHooksDir(DOMXML, dirName) self.assertEqual(expectedResult, res)
def test_runHooksDir(self): # Add an unicode value to the environment variables # to test whether the utf-8 recoding works properly os.environ["FAKE_GERRIT_USERNAME"] = "******" with self.tempScripts() as (dirName, scripts): Q = 3 DOMXML = "algo" expectedResult = DOMXML for n in range(Q): expectedResult = expectedResult + str(n) res = hooks._runHooksDir(DOMXML, dirName) self.assertEqual(expectedResult, res)
def test_deviceCustomProperties(self): with self._deviceCustomPropertiesTestFile() as dirName: result = hooks._runHooksDir("oVirt", dirName, params={'customProperty': ' rocks!'}) self.assertEqual(result, "oVirt rocks!")
def test_rhd_should_raise_hook_errors(hooks_dir, error): with pytest.raises(exception.HookError) as e: hooks._runHooksDir(u"", hooks_dir.basename) for err in error: assert err in str(e.value)
def test_emptyDir(self): with namedTemporaryDir() as dirName: DOMXML = "algo" self.assertEqual(DOMXML, hooks._runHooksDir(DOMXML, dirName))
def test_rhd_should_make_import_hooking_possible(hooks_dir, hooking_client): hooks._runHooksDir(u"", hooks_dir.basename)
def test_rhd_should_report_hook_stderr(caplog, hooks_dir): caplog.set_level(logging.INFO) hooks._runHooksDir(u"", hooks_dir.basename) assert "1.sh" in "".join(msg for _, lvl, msg in caplog.record_tuples if lvl == logging.INFO)
def test_rhd_should_return_unmodified_data_when_no_hooks(hooks_dir): assert hooks._runHooksDir(u"algo", hooks_dir.basename) == u"algo"
def test_rhd_should_report_invalid_hook_error_codes(caplog, hooks_dir): hooks._runHooksDir(u"", hooks_dir.basename, raiseError=False) assert "111" in "".join(msg for (_, lvl, msg) in caplog.record_tuples if lvl == logging.WARNING)
def test_rhd_should_handle_json_data(dummy_hook, hooks_dir, data, expected): result = hooks._runHooksDir(data, hooks_dir.basename, hookType=hooks._JSON_HOOK) assert result == expected
def test_emptyDir(self): with namedTemporaryDir() as dirName: DOMXML = "algo" self.assertEqual(DOMXML, hooks._runHooksDir(DOMXML, dirName))
def test_rhd_should_run_hooks_in_order(hooks_dir): assert hooks._runHooksDir(u"", hooks_dir.basename) == u"1.sh\n2.sh\n3.sh\n"
def test_rhd_should_run_a_hook(hooks_dir): assert hooks._runHooksDir(u"123", hooks_dir.basename) == u"123myhook.sh\n"
def test_rhd_should_handle_hook_errors(hooks_dir, expected): assert hooks._runHooksDir(u"", hooks_dir.basename, raiseError=False) == \ expected
def test_deviceCustomProperties(self): with self._deviceCustomPropertiesTestFile() as dirName: result = hooks._runHooksDir("oVirt", dirName, params={'customProperty': ' rocks!'}) self.assertEqual(result, "oVirt rocks!")