def test_add_family_bad_data_delivery( cli_runner: CliRunner, base_context: CGConfig, helpers: StoreHelpers ): """Test to add a case using only the required arguments""" # GIVEN a database with a customer and an panel # WHEN adding a case without data delivery disk_store: Store = base_context.status_db customer: models.Customer = helpers.ensure_customer(store=disk_store) customer_id = customer.internal_id panel: models.Panel = helpers.ensure_panel(store=disk_store) panel_id = panel.name name = "case_name" non_existing_data_delivery = "aws" result = cli_runner.invoke( add, [ "case", "--panel", panel_id, "--analysis", CLI_OPTION_ANALYSIS, "--data-delivery", non_existing_data_delivery, customer_id, name, ], obj=base_context, ) # THEN it should not be added assert result.exit_code != 0 assert disk_store.Family.query.count() == 0
def test_add_family_bad_panel(cli_runner: CliRunner, base_context: CGConfig, helpers: StoreHelpers): """Test to add a case using a non-existing panel""" # GIVEN a database with a customer disk_store: Store = base_context.status_db # WHEN adding a case customer: models.Customer = helpers.ensure_customer(store=disk_store) customer_id = customer.internal_id panel_id = "dummy_panel" name = "dummy_name" result = cli_runner.invoke( add, [ "family", "--panel", panel_id, "--analysis", CLI_OPTION_ANALYSIS, "--data-delivery", CLI_OPTION_DELIVERY, customer_id, name, ], obj=base_context, ) # THEN it should complain about missing panel instead of adding a case assert result.exit_code == 1 assert disk_store.Family.query.count() == 0
def test_add_family_priority(cli_runner: CliRunner, base_context: CGConfig, helpers: StoreHelpers): """Test that the added case get the priority we send in""" # GIVEN a database with a customer and an panel disk_store: Store = base_context.status_db # WHEN adding a case customer: models.Customer = helpers.ensure_customer(store=disk_store) customer_id = customer.internal_id panel: models.Panel = helpers.ensure_panel(store=disk_store) panel_id = panel.name name = "case_name" priority = "priority" result = cli_runner.invoke( add, [ "family", "--panel", panel_id, "--priority", priority, "--analysis", CLI_OPTION_ANALYSIS, "--data-delivery", CLI_OPTION_DELIVERY, customer_id, name, ], obj=base_context, ) # THEN it should be added assert result.exit_code == 0 assert disk_store.Family.query.count() == 1 assert disk_store.Family.query.first().priority_human == priority
def test_add_sample_required(cli_runner: CliRunner, base_context: CGConfig, helpers: StoreHelpers): # GIVEN a database with a customer and an application disk_store: Store = base_context.status_db sex = "male" application_tag = "dummy_tag" helpers.ensure_application(store=disk_store, tag=application_tag) helpers.ensure_application_version(store=disk_store, application_tag=application_tag) customer: models.Customer = helpers.ensure_customer(store=disk_store) customer_id = customer.internal_id name = "sample_name" # WHEN adding a sample result = cli_runner.invoke( add, [ "sample", "--sex", sex, "--application", application_tag, customer_id, name, ], obj=base_context, ) # THEN it should be added assert result.exit_code == 0 assert disk_store.Sample.query.count() == 1 assert disk_store.Sample.query.first().name == name assert disk_store.Sample.query.first().sex == sex
def test_add_family_required(cli_runner: CliRunner, base_context: CGConfig, helpers: StoreHelpers): """Test to add a case using only the required arguments""" # GIVEN a database with a customer and an panel disk_store: Store = base_context.status_db customer: models.Customer = helpers.ensure_customer(store=disk_store) customer_id = customer.internal_id panel: models.Panel = helpers.ensure_panel(store=disk_store) panel_id = panel.name name = "case_name" # WHEN adding a panel result = cli_runner.invoke( add, [ "family", "--panel", panel_id, "--analysis", CLI_OPTION_ANALYSIS, "--data-delivery", CLI_OPTION_DELIVERY, customer_id, name, ], obj=base_context, ) # THEN it should be added assert result.exit_code == 0 assert disk_store.Family.query.count() == 1 assert disk_store.Family.query.first().name == name assert disk_store.Family.query.first().panels == [panel_id]
def test_add_sample_bad_application(cli_runner: CliRunner, base_context: CGConfig, helpers: StoreHelpers): # GIVEN a database with a customer disk_store: Store = base_context.status_db # WHEN adding a sample sex = "male" application = "dummy_application" customer: models.Customer = helpers.ensure_customer(store=disk_store) customer_id = customer.internal_id name = "dummy_name" result = cli_runner.invoke( add, [ "sample", "--sex", sex, "--application", application, customer_id, name, ], obj=base_context, ) # THEN it should complain about missing application instead of adding a sample assert result.exit_code == 1 assert disk_store.Sample.query.count() == 0
def test_validate_case_name(rml_order_to_submit: dict, base_store: Store, helpers: StoreHelpers): # GIVEN pool order with a case already all in the database order: OrderIn = OrderIn.parse_obj(rml_order_to_submit, OrderType.RML) sample: RmlSample customer: models.Customer = helpers.ensure_customer( store=base_store, customer_id=order.customer) for sample in order.samples: case = helpers.ensure_case( store=base_store, name=PoolSubmitter.create_case_name(ticket=order.ticket, pool_name=sample.pool), customer=customer, data_analysis=Pipeline.FLUFFY, data_delivery=DataDelivery.STATINA, ) base_store.add_commit(case)
def test_get_family_by_name(cli_runner: CliRunner, base_context: CGConfig, helpers: StoreHelpers): # GIVEN A database with a customer in it status_db: Store = base_context.status_db customer: models.Customer = helpers.ensure_customer(store=status_db) customer_id = customer.internal_id # WHEN trying to get a non-existing case by name result = cli_runner.invoke( get, [ "family", "-c", customer_id, "-n", "dummy-case-name", ], obj=base_context, ) # THEN it should not crash assert result.exit_code == 0
def test_add_sample_downsampled( cli_runner, base_context: CGConfig, disk_store: Store, application_tag: str, helpers: StoreHelpers, ): # GIVEN a database with a customer and an application helpers.ensure_application(store=disk_store, tag=application_tag) helpers.ensure_application_version(store=disk_store, application_tag=application_tag) customer: models.Customer = helpers.ensure_customer(store=disk_store) customer_id = customer.internal_id sex = "male" name = "sample_name" downsampled_to = "123" # WHEN adding a sample result = cli_runner.invoke( add, [ "sample", "--sex", sex, "--application", application_tag, "--downsampled", downsampled_to, customer_id, name, ], obj=base_context, ) # THEN it should be added assert result.exit_code == 0 assert disk_store.Sample.query.count() == 1 assert str( disk_store.Sample.query.first().downsampled_to) == downsampled_to
def fixture_rna_store( base_store: Store, helpers: StoreHelpers, rna_case_id: str, dna_case_id: str, ) -> Store: """Populate store with an rna case that is connected to a dna case via sample.subject_id""" store: Store = base_store # an existing RNA case with related sample rna_case = helpers.ensure_case( store=store, name="rna_case", customer=helpers.ensure_customer(store=store), data_analysis=Pipeline.MIP_RNA, data_delivery=DataDelivery.SCOUT, ) rna_case.internal_id = rna_case_id rna_sample_son = helpers.add_sample(store=store, name="rna_son", subject_id="son") rna_sample_daughter = helpers.add_sample( store=store, name="rna_daughter", subject_id="daughter" ) rna_sample_mother = helpers.add_sample(store=store, name="rna_mother", subject_id="mother") rna_sample_father = helpers.add_sample(store=store, name="rna_father", subject_id="father") helpers.add_relationship( store=store, sample=rna_sample_son, case=rna_case, mother=rna_sample_mother, father=rna_sample_father, status="affected", ) helpers.add_relationship( store=store, sample=rna_sample_daughter, case=rna_case, mother=rna_sample_mother, father=rna_sample_father, status="unaffected", ) helpers.add_relationship( store=store, sample=rna_sample_mother, case=rna_case, status="unaffected" ) helpers.add_relationship( store=store, sample=rna_sample_father, case=rna_case, status="affected" ) for link in rna_case.links: link.sample.internal_id = link.sample.name # an existing DNA case with related sample dna_case = helpers.ensure_case( store=store, name="dna_case", customer=helpers.ensure_customer(store=store), data_analysis=Pipeline.MIP_DNA, data_delivery=DataDelivery.SCOUT, ) dna_case.internal_id = dna_case_id dna_sample_son = helpers.add_sample(store=store, name="dna_son", subject_id="son") dna_sample_daughter = helpers.add_sample( store=store, name="dna_daughter", subject_id="daughter" ) dna_sample_mother = helpers.add_sample(store=store, name="dna_mother", subject_id="mother") dna_sample_father = helpers.add_sample(store=store, name="dna_father", subject_id="father") helpers.add_relationship( store=store, sample=dna_sample_son, case=dna_case, mother=dna_sample_mother, father=dna_sample_father, status="affected", ) helpers.add_relationship( store=store, sample=dna_sample_daughter, case=dna_case, mother=dna_sample_mother, father=dna_sample_father, status="unaffected", ) helpers.add_relationship( store=store, sample=dna_sample_mother, case=dna_case, status="unaffected" ) helpers.add_relationship( store=store, sample=dna_sample_father, case=dna_case, status="affected" ) for link in dna_case.links: link.sample.internal_id = link.sample.name store.commit() return store