Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vdk-control-cli: Modify how data is written to job config.ini #2982

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,15 @@ def _get_value(self, section, key) -> Any:
def _set_value(self, section, key, value) -> bool:
success = False
if self._config_ini.has_option(section, key):
for line in fileinput.input(self._config_file, inplace=1):
if line.replace(" ", "").startswith(f"{key}="):
success = True
line = f"{key} = {value}\n"
sys.stdout.write(line)
with open(self._config_file) as config_file:
conf_lines = config_file.readlines()

with open(self._config_file, "w") as f:
for line in conf_lines:
if line.replace(" ", "").startswith(f"{key}="):
success = True
line = f"{key} = {value}\n"
f.write(line)
return success

def _get_contacts(self, key) -> List[str]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,46 @@ def test_create_only_local_flag(httpserver: PluginHTTPServer, tmpdir: LocalPath)
],
)

# created only locally would not try to contact REST API so it should succeeds.
# created only locally would not try to contact REST API, so it should succeed.
assert_click_status(result, 0)


def test_create_local_flag_check_generated_config_file(
httpserver: PluginHTTPServer, tmpdir: LocalPath
):
team_name = "test-team"
job_name = "test-job"
jobs_dir, rest_api_url = setup_create(
httpserver, tmpdir, 500, 500, job_name, team_name
)

runner = CliRunner()
result = runner.invoke(
create,
[
"-n",
"test-job",
"-t",
"team_name",
"-p",
jobs_dir,
"-u",
rest_api_url,
"--local",
],
)

# created only locally would not try to contact REST API, so it should succeed.
job_dir = os.path.join(jobs_dir, job_name)
assert_click_status(result, 0)
assert os.path.isdir(job_dir)
assert os.path.isfile(os.path.join(job_dir, "config.ini"))

# Verify that config.ini is not empty
with open(os.path.join(job_dir, "config.ini"), "rb") as f:
assert f.seek(0, 2) > 0


def test_create_with_empty_url(httpserver: PluginHTTPServer, tmpdir: LocalPath):
jobs_dir = tmpdir.mkdir("jobs")

Expand Down
Loading