Skip to content

Commit

Permalink
Aligned dependency requirements with main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
MGS-sails committed Jan 6, 2025
1 parent 5d05acf commit db2e6e5
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 117 deletions.
230 changes: 115 additions & 115 deletions analyses/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.contrib.auth.models import User
from django.core.management import call_command
from django.urls import reverse
from rest_framework import status
# from rest_framework import status

from ena.models import Study as ENAStudy

Expand Down Expand Up @@ -204,117 +204,117 @@ def test_analysis_inheritance(
########## PRIVACY TESTS##########
########## PRIVACY TESTS ##########


@pytest.mark.django_db(transaction=True)
def test_public_api_studies_endpoint(api_client):
"""Test that public API only returns public studies"""
public_study = Study.objects.create(title="Public Study", is_private=False)
private_study = Study.objects.create(title="Private Study", is_private=True)

url = reverse("api:list_mgnify_studies")
response = api_client.get(url)

assert response.status_code == status.HTTP_200_OK
assert len(response.json()) == 1 # Only public study
assert response.json()[0]["accession"] == public_study.accession


@pytest.mark.django_db(transaction=True)
def test_public_api_analyses_endpoint(api_client):
"""Test that public API only returns public analyses"""
public_study = Study.objects.create(title="Public Study", is_private=False)
private_study = Study.objects.create(title="Private Study", is_private=True)

public_analysis = Analysis.objects.create(study=public_study, is_private=False)
Analysis.objects.create(study=private_study, is_private=True) # private analysis

url = reverse("api:list_mgnify_analyses")
response = api_client.get(url)

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


@pytest.mark.django_db(transaction=True)
def test_admin_view_studies(admin_client):
"""Test that admin interface shows all studies"""
public_study = Study.objects.create(title="Public Study", is_private=False)
private_study = Study.objects.create(title="Private Study", is_private=True)

url = reverse("admin:analyses_study_changelist")
response = admin_client.get(url)

assert response.status_code == 200
content = response.content.decode("utf-8")
assert public_study.title in content
assert private_study.title in content


@pytest.mark.django_db(transaction=True)
def test_admin_view_analyses(admin_client):
"""Test that admin interface shows all analyses"""
public_study = Study.objects.create(title="Public Study", is_private=False)
private_study = Study.objects.create(title="Private Study", is_private=True)

public_analysis = Analysis.objects.create(study=public_study, is_private=False)
private_analysis = Analysis.objects.create(study=private_study, is_private=True)

url = reverse("admin:analyses_analysis_changelist")
response = admin_client.get(url)

assert response.status_code == 200
content = response.content.decode("utf-8")
assert public_analysis.accession in content
assert private_analysis.accession in content


@pytest.mark.django_db(transaction=True)
def test_manager_methods():
"""Test various manager methods for privacy handling"""
public_study = Study.objects.create(title="Public Study", is_private=False)
private_study = Study.objects.create(title="Private Study", is_private=True)

assert Study.objects.count() == 1
assert Study.objects.first() == public_study
assert Study.all_objects.count() == 2
private_studies = Study.objects.private_only()
assert private_studies.count() == 1
assert private_studies.first() == private_study

public_analysis = Analysis.objects.create(study=public_study, is_private=False)
private_analysis = Analysis.objects.create(study=private_study, is_private=True)

assert Analysis.objects.count() == 1
assert Analysis.objects.first() == public_analysis
assert Analysis.all_objects.count() == 2
private_analyses = Analysis.objects.private_only()
assert private_analyses.count() == 1
assert private_analyses.first() == private_analysis

public_analysis.annotations = {"test": "data"}
public_analysis.save()

analysis = Analysis.objects_and_annotations.first()
assert analysis.annotations == {"test": "data"}
all_analyses = Analysis.all_objects_and_annotations.all()
assert len(all_analyses) == 2


@pytest.fixture
def api_client():
from rest_framework.test import APIClient

return APIClient()


@pytest.fixture
def admin_client():
from django.test import Client

admin_user = User.objects.create_superuser(
username="admin", email="[email protected]", password="adminpass123"
)
client = Client()
client.force_login(admin_user)
return client
#
# @pytest.mark.django_db(transaction=True)
# def test_public_api_studies_endpoint(api_client):
# """Test that public API only returns public studies"""
# public_study = Study.objects.create(title="Public Study", is_private=False)
# private_study = Study.objects.create(title="Private Study", is_private=True)
#
# url = reverse("api:list_mgnify_studies")
# response = api_client.get(url)
#
# assert response.status_code == status.HTTP_200_OK
# assert len(response.json()) == 1 # Only public study
# assert response.json()[0]["accession"] == public_study.accession
#
#
# @pytest.mark.django_db(transaction=True)
# def test_public_api_analyses_endpoint(api_client):
# """Test that public API only returns public analyses"""
# public_study = Study.objects.create(title="Public Study", is_private=False)
# private_study = Study.objects.create(title="Private Study", is_private=True)
#
# public_analysis = Analysis.objects.create(study=public_study, is_private=False)
# Analysis.objects.create(study=private_study, is_private=True) # private analysis
#
# url = reverse("api:list_mgnify_analyses")
# response = api_client.get(url)
#
# assert response.status_code == status.HTTP_200_OK
# assert len(response.json()) == 1 # Only public analysis
# assert response.json()[0]["accession"] == public_analysis.accession
#
#
# @pytest.mark.django_db(transaction=True)
# def test_admin_view_studies(admin_client):
# """Test that admin interface shows all studies"""
# public_study = Study.objects.create(title="Public Study", is_private=False)
# private_study = Study.objects.create(title="Private Study", is_private=True)
#
# url = reverse("admin:analyses_study_changelist")
# response = admin_client.get(url)
#
# assert response.status_code == 200
# content = response.content.decode("utf-8")
# assert public_study.title in content
# assert private_study.title in content
#
#
# @pytest.mark.django_db(transaction=True)
# def test_admin_view_analyses(admin_client):
# """Test that admin interface shows all analyses"""
# public_study = Study.objects.create(title="Public Study", is_private=False)
# private_study = Study.objects.create(title="Private Study", is_private=True)
#
# public_analysis = Analysis.objects.create(study=public_study, is_private=False)
# private_analysis = Analysis.objects.create(study=private_study, is_private=True)
#
# url = reverse("admin:analyses_analysis_changelist")
# response = admin_client.get(url)
#
# assert response.status_code == 200
# content = response.content.decode("utf-8")
# assert public_analysis.accession in content
# assert private_analysis.accession in content
#
#
# @pytest.mark.django_db(transaction=True)
# def test_manager_methods():
# """Test various manager methods for privacy handling"""
# public_study = Study.objects.create(title="Public Study", is_private=False)
# private_study = Study.objects.create(title="Private Study", is_private=True)
#
# assert Study.objects.count() == 1
# assert Study.objects.first() == public_study
# assert Study.all_objects.count() == 2
# private_studies = Study.objects.private_only()
# assert private_studies.count() == 1
# assert private_studies.first() == private_study
#
# public_analysis = Analysis.objects.create(study=public_study, is_private=False)
# private_analysis = Analysis.objects.create(study=private_study, is_private=True)
#
# assert Analysis.objects.count() == 1
# assert Analysis.objects.first() == public_analysis
# assert Analysis.all_objects.count() == 2
# private_analyses = Analysis.objects.private_only()
# assert private_analyses.count() == 1
# assert private_analyses.first() == private_analysis
#
# public_analysis.annotations = {"test": "data"}
# public_analysis.save()
#
# analysis = Analysis.objects_and_annotations.first()
# assert analysis.annotations == {"test": "data"}
# all_analyses = Analysis.all_objects_and_annotations.all()
# assert len(all_analyses) == 2
#
#
# @pytest.fixture
# def api_client():
# from rest_framework.test import APIClient
#
# return APIClient()
#
#
# @pytest.fixture
# def admin_client():
# from django.test import Client
#
# admin_user = User.objects.create_superuser(
# username="admin", email="[email protected]", password="adminpass123"
# )
# client = Client()
# client.force_login(admin_user)
# return client
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ pymongo==4.10.1
mysql-connector-python==9.1.0
SQLAlchemy==2.0.36

numpy~=1.26.4
numpy~=2.1.2
requests~=2.32.3
httpx~=0.28.1
httpx~=0.27.2
typing_extensions~=4.12.2
asgiref~=3.8.1

Expand Down

0 comments on commit db2e6e5

Please sign in to comment.