Skip to content

Commit

Permalink
tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrOertlin committed Sep 3, 2024
1 parent d25acab commit 843f5fe
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 295 deletions.
24 changes: 15 additions & 9 deletions cg/cli/deliver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
type=click.Choice(PIPELINE_ANALYSIS_OPTIONS),
required=True,
)
TICKET_ID_ARG = click.argument("ticket", type=str, required=True)
TICKET_ID_ARG = click.option("-t", "--ticket", type=str, required=True)


@click.group(context_settings=CLICK_CONTEXT_SETTINGS)
Expand All @@ -38,9 +38,9 @@ def deliver():


@deliver.command(name="rsync")
@DRY_RUN
@TICKET_ID_ARG
@click.pass_obj
@TICKET_ID_ARG
@DRY_RUN
def rsync(context: CGConfig, ticket: str, dry_run: bool):
"""The folder generated using the "cg deliver analysis" command will be
rsynced with this function to the customers inbox on the delivery server
Expand All @@ -55,15 +55,15 @@ def rsync(context: CGConfig, ticket: str, dry_run: bool):


@deliver.command(name="case")
@click.pass_obj
@click.option(
"-c",
"--case-id",
required=True,
help="Deliver the files for a specific case",
)
@click.pass_obj
@DRY_RUN
def deliver_analysis(
def deliver_case(
context: CGConfig,
case_id: str,
dry_run: bool,
Expand All @@ -77,6 +77,9 @@ def deliver_analysis(
hk_api=context.housekeeper_api,
)
case: Case = context.status_db.get_case_by_internal_id(internal_id=case_id)
if not case:
LOG.error(f"Could not find case with id {case_id}")
return
delivery_service: DeliverFilesService = service_builder.build_delivery_service(
delivery_type=case.data_delivery,
workflow=case.workflow,
Expand All @@ -94,8 +97,8 @@ def deliver_analysis(


@deliver.command(name="ticket")
@TICKET_ID_ARG
@click.pass_obj
@TICKET_ID_ARG
@DRY_RUN
def deliver_ticket(
context: CGConfig,
Expand All @@ -110,10 +113,13 @@ def deliver_ticket(
store=context.status_db,
hk_api=context.housekeeper_api,
)
case: Case = context.status_db.get_cases_by_ticket_id(ticket_id=ticket)[0]
cases: list[Case] = context.status_db.get_cases_by_ticket_id(ticket_id=ticket)
if not cases:
LOG.error(f"Could not find case connected to ticket {ticket}")
return
delivery_service: DeliverFilesService = service_builder.build_delivery_service(
delivery_type=case.data_delivery,
workflow=case.workflow,
delivery_type=cases[0].data_delivery,
workflow=cases[0].workflow,
)
delivery_service.deliver_files_for_ticket(ticket_id=ticket, delivery_base_path=Path(inbox))
tb_api: TrailblazerAPI = context.trailblazer_api
Expand Down
1 change: 1 addition & 0 deletions cg/constants/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
EXIT_SUCCESS = 0
EXIT_WARNING = 8
EXIT_FAIL = 1
EXIT_PARSE_ERROR = 2
80 changes: 5 additions & 75 deletions tests/cli/deliver/test_deliver_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from cg.cli.deliver.base import deliver as deliver_cmd
from cg.constants import EXIT_SUCCESS
from cg.meta.deliver import DeliverTicketAPI
from cg.models.cg_config import CGConfig


Expand All @@ -29,12 +28,10 @@ def test_run_deliver_analysis_help(cli_runner: CliRunner, base_context: CGConfig
# GIVEN a context with store and housekeeper information

# WHEN running cg deliver help
result = cli_runner.invoke(deliver_cmd, ["analysis", "--help"], obj=base_context)
result = cli_runner.invoke(deliver_cmd, ["case", "--help"], obj=base_context)

# THEN assert the command exists without problems
assert result.exit_code == EXIT_SUCCESS
# THEN assert the information is printed
assert "Deliver analysis files to customer inbox" in result.output


def test_run_deliver_ticket_help(cli_runner: CliRunner, base_context: CGConfig):
Expand All @@ -45,87 +42,20 @@ def test_run_deliver_ticket_help(cli_runner: CliRunner, base_context: CGConfig):
# WHEN running cg deliver help
result = cli_runner.invoke(deliver_cmd, ["ticket", "--help"], obj=base_context)

# THEN assert the command exists without problems
assert result.exit_code == EXIT_SUCCESS
# THEN assert the information is printed
assert "Will first collect hard links" in result.output


def test_run_deliver_delivered_ticket(
cli_runner: CliRunner, cg_context: CGConfig, mocker, caplog, ticket_id
):
"""Test for when files are already delivered to customer inbox the HPC"""
caplog.set_level(logging.INFO)

# GIVEN a cli runner

# GIVEN uploading data to the delivery server is not needed
mocker.patch.object(DeliverTicketAPI, "check_if_upload_is_needed")
DeliverTicketAPI.check_if_upload_is_needed.return_value = False

# WHEN running cg deliver ticket
result = cli_runner.invoke(
deliver_cmd,
["ticket", "--dry-run", "--ticket", ticket_id, "--delivery-type", "fastq"],
obj=cg_context,
)

# THEN assert the command exists without problems
assert result.exit_code == EXIT_SUCCESS

# THEN assert that files are already delivered to the customer inbox on the HPC
assert "Files already delivered to customer inbox on the HPC" in caplog.text


def test_deliver_ticket_with_force_all_flag(
cli_runner: CliRunner, cg_context: CGConfig, mocker, caplog, ticket_id
):
"""Test that when the --force-all flag is used,
the files are delivered to the customer inbox on the HPC"""
caplog.set_level(logging.INFO)

# GIVEN a cli runner

# GIVEN uploading data to the delivery server is not needed
mocker.patch.object(DeliverTicketAPI, "check_if_upload_is_needed")
DeliverTicketAPI.check_if_upload_is_needed.return_value = False

# WHEN running cg deliver ticket with --force-all flag
cli_runner.invoke(
deliver_cmd,
[
"ticket",
"--dry-run",
"--ticket",
ticket_id,
"--delivery-type",
"fastq",
"--force-all",
],
obj=cg_context,
)

# THEN assert that the text is not present in the log
assert "Files already delivered to customer inbox on the HPC" not in caplog.text
assert "Delivering files to customer inbox on the HPC" in caplog.text


def test_run_deliver_ticket(cli_runner: CliRunner, cg_context: CGConfig, mocker, caplog, ticket_id):
def test_run_deliver_ticket(cli_runner: CliRunner, cg_context: CGConfig, ticket_id):
"""Test for delivering tu customer inbox"""
caplog.set_level(logging.INFO)

# GIVEN a cli runner

# GIVEN uploading data to the delivery server is needed
mocker.patch.object(DeliverTicketAPI, "check_if_upload_is_needed")
DeliverTicketAPI.check_if_upload_is_needed.return_value = True

# WHEN running cg deliver ticket
cli_runner.invoke(
result = cli_runner.invoke(
deliver_cmd,
["ticket", "--dry-run", "--ticket", ticket_id, "--delivery-type", "fastq"],
["ticket", "--dry-run", "--ticket", ticket_id],
obj=cg_context,
)

# THEN assert that files are delivered
assert "Delivering files to customer inbox on the HPC" in caplog.text
assert result.exit_code == EXIT_SUCCESS
3 changes: 0 additions & 3 deletions tests/cli/deliver/test_rsync_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,3 @@ def test_run_rsync_command_no_case(cg_context: CGConfig, cli_runner, helpers, ca

# THEN command failed successfully
assert result.exit_code != EXIT_SUCCESS

# THEN process generates error message that case cant be found
assert "Could not find any cases for ticket" in caplog.text
Loading

0 comments on commit 843f5fe

Please sign in to comment.