Skip to content

Commit

Permalink
Ran pre commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
MGS-sails committed Jan 7, 2025
1 parent 2524fbb commit 8576827
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
4 changes: 2 additions & 2 deletions analyses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from analyses.base_models.with_downloads_models import WithDownloadsModel
from emgapiv2.async_utils import anysync_property


# Some models associated with MGnify Analyses (MGYS, MGYA etc).


Expand Down Expand Up @@ -106,7 +105,8 @@ async def get_or_create_for_ena_study(self, ena_study_accession):
)
return study

class PublicStudyManager(BasePublicStudyManager, StudyManager):

class PublicStudyManager(BasePublicStudyManager, StudyManager):
"""
A custom manager that filters out private studies by default.
"""
Expand Down
27 changes: 13 additions & 14 deletions analyses/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@
from rest_framework import status

from ena.models import Study as ENAStudy

from .management.commands.import_v5_analysis import logger
from .models import (
Analysis,
Assembler,
Biome,
ComputeResourceHeuristic,
Run,
Study, )
from .models import Analysis, Assembler, Biome, ComputeResourceHeuristic, Run, Study


def create_analysis(is_private=False):
run = Run.objects.first()
return Analysis.objects.create(
study=run.study, run=run, ena_study=run.ena_study, sample=run.sample,
is_private=is_private
study=run.study,
run=run,
ena_study=run.ena_study,
sample=run.sample,
is_private=is_private,
)


Expand All @@ -38,12 +37,12 @@ def test_biome_lineage_path_generator():
assert Biome.lineage_to_path("root") == "root"
assert Biome.lineage_to_path("Root") == "root"
assert (
Biome.lineage_to_path("root:Host-associated:Human:Digestive system")
== "root.host_associated.human.digestive_system"
Biome.lineage_to_path("root:Host-associated:Human:Digestive system")
== "root.host_associated.human.digestive_system"
)
assert (
Biome.lineage_to_path("root:Host-associated:Human:Digestive system (bowel)")
== "root.host_associated.human.digestive_system_bowel"
Biome.lineage_to_path("root:Host-associated:Human:Digestive system (bowel)")
== "root.host_associated.human.digestive_system_bowel"
)


Expand Down Expand Up @@ -194,7 +193,7 @@ def test_biome_importer(httpx_mock):

@pytest.mark.django_db(transaction=True)
def test_analysis_inheritance(
raw_read_run,
raw_read_run,
):
for run in Run.objects.all():
analysis = Analysis.objects.create(
Expand Down
23 changes: 15 additions & 8 deletions emgapiv2/test_data_privacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
from rest_framework import status

from analyses.management.commands.import_v5_analysis import logger
from analyses.models import Run, Analysis, Study
from analyses.models import Analysis, Run, Study
from ena.models import Study as ENAStudy


def create_analysis(is_private=False):
run = Run.objects.first()
return Analysis.objects.create(
study=run.study, run=run, ena_study=run.ena_study, sample=run.sample,
is_private=is_private
study=run.study,
run=run,
ena_study=run.ena_study,
sample=run.sample,
is_private=is_private,
)


@pytest.mark.django_db(transaction=True)
def test_public_api_studies_endpoint(api_client):
"""Test that public API only returns public studies"""
Expand All @@ -28,7 +32,7 @@ def test_public_api_studies_endpoint(api_client):
response = api_client.get(url)

assert response.status_code == status.HTTP_200_OK
assert len(response.json()['items']) == 1 # Only public study
assert len(response.json()["items"]) == 1 # Only public study

assert response.json()["items"][0]["accession"] == public_study.accession

Expand All @@ -44,8 +48,8 @@ def test_public_api_analyses_endpoint(raw_read_run, api_client):

assert response.status_code == status.HTTP_200_OK
# Only public analysis should be returned
assert len(response.json()['items']) == 1
assert response.json()['items'][0]["accession"] == public_analysis.accession
assert len(response.json()["items"]) == 1
assert response.json()["items"][0]["accession"] == public_analysis.accession


@pytest.mark.django_db(transaction=True)
Expand Down Expand Up @@ -80,10 +84,12 @@ def test_admin_view_analyses(raw_read_run, admin_client):

@pytest.mark.django_db(transaction=True)
def test_study_manager_methods():
# def test_manager_methods(raw_read_run):
# def test_manager_methods(raw_read_run):
"""Test various manager methods for privacy handling"""
ena_study = ENAStudy.objects.create(accession="PRJ1", title="Project 1")
public_study = Study.objects.create(ena_study=ena_study, title="Public Study", is_private=False)
public_study = Study.objects.create(
ena_study=ena_study, title="Public Study", is_private=False
)
private_study = Study.objects.create(title="Private Study", is_private=True)

assert Study.objects.count() == 1
Expand All @@ -93,6 +99,7 @@ def test_study_manager_methods():
assert private_studies.count() == 1
assert private_studies.first() == private_study


@pytest.mark.django_db(transaction=True)
def test_manager_analysis_methods(raw_read_run):
public_analysis = create_analysis(is_private=False)
Expand Down

0 comments on commit 8576827

Please sign in to comment.