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

Fix add_job cli command #679

Merged
merged 1 commit into from
Nov 15, 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
13 changes: 10 additions & 3 deletions jobrunner/cli/add_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import argparse
import dataclasses
import pprint
import sys
import textwrap
from pathlib import Path
from urllib.parse import urlparse
Expand Down Expand Up @@ -36,6 +37,7 @@ def main(
requested_actions=actions,
force_run_dependencies=force_run_dependencies,
cancelled_actions=[],
codelists_ok=True,
)
)
print("Submitting JobRequest:\n")
Expand All @@ -46,6 +48,8 @@ def main(
for job in jobs:
display_obj(job)

return job_request, jobs


def display_obj(obj):
if hasattr(obj, "asdict"):
Expand All @@ -57,7 +61,10 @@ def display_obj(obj):
print()


def run():
def run(argv=None):
if argv is None:
argv = sys.argv[1:]

configure_logging()
parser = argparse.ArgumentParser(description=__doc__.partition("\n\n")[0])
parser.add_argument("repo_url", help="URL (or local path) of git repository")
Expand All @@ -82,8 +89,8 @@ def run():
)
parser.add_argument("-f", "--force-run-dependencies", action="store_true")

args = parser.parse_args()
main(**vars(args))
args = parser.parse_args(argv)
return main(**vars(args))


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion jobrunner/create_or_update_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def create_jobs(job_request):


def validate_job_request(job_request):
if config.ALLOWED_GITHUB_ORGS:
# http prefix allows local git repos, useful for tests
if job_request.repo_url.startswith("http") and config.ALLOWED_GITHUB_ORGS:
validate_repo_url(job_request.repo_url, config.ALLOWED_GITHUB_ORGS)
if not job_request.requested_actions:
raise JobRequestError("At least one action must be supplied")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dynamic_context = "test_function"
source = ["jobrunner"]

[tool.coverage.report]
fail_under = 80
fail_under = 82
show_missing = true
skip_covered = true

Expand Down
14 changes: 14 additions & 0 deletions tests/cli/test_add_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from jobrunner.cli import add_job
from jobrunner.lib import database
from jobrunner.models import Job


def test_add_job(tmp_work_dir, db, test_repo):
job_request, jobs = add_job.run([str(test_repo.path), "generate_dataset"])

assert len(jobs) == 1
assert jobs[0].action == "generate_dataset"

db_jobs = database.find_where(Job, job_request_id=job_request.id)
assert len(db_jobs) == 1
assert db_jobs[0].action == "generate_dataset"