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

Tests dev #54

Merged
merged 16 commits into from
Dec 3, 2024
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
4 changes: 2 additions & 2 deletions .env-docker.dev
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FLASK_CONFIGURATION=development
POSTGRES_USER=postgres
POSTGRES_PASSWORD=annodb
POSTGRES_DB=annotation
POSTGRES_PASSWORD=postgres
POSTGRES_DB=test_aligned_volume

AUTH_URI=global.daf-apis.com/auth
STICKY_AUTH_URL=global.daf-apis.com/sticky_auth
3 changes: 3 additions & 0 deletions .github/workflows/annotationengine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,8 @@ jobs:

- name: Test with pytest
shell: bash -l {0}
env:
AUTH_DISABLED: true
run: |
python -c "import os; print('AUTH_DISABLED:', os.getenv('AUTH_DISABLED'), type(os.getenv('AUTH_DISABLED')))"
pytest
4 changes: 2 additions & 2 deletions annotationengine/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
def unhandled_exception(e):
status_code = 500
user_ip = str(request.remote_addr)
tb = traceback.format_exception(etype=type(e), value=e, tb=e.__traceback__)
tb = traceback.format_exception(e, value=e, tb=e.__traceback__)

current_app.logger.error(
{
Expand Down Expand Up @@ -317,7 +317,7 @@ def get(self, aligned_volume_name: str, table_name: str, **kwargs):
db = get_db(aligned_volume_name)
check_read_permission(db, table_name)
args = annotation_parser.parse_args()

annotation_ids = args["annotation_ids"]

md = db.database.get_table_metadata(table_name)
Expand Down
29 changes: 14 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
version: '3'
services:
db:
image: mdillon/postgis
image: postgis/postgis:13-master
restart: always
env_file:
- ./.env-docker.dev
Expand All @@ -21,19 +20,19 @@ services:
- 8080:8080
links:
- db
app:
image: 'app:tag'
build:
context: .
dockerfile: dev.Dockerfile
ports:
- 80:80
volumes:
- .:/app
env_file:
- ./.env-docker.dev
depends_on:
- db
# app:
# image: 'app:tag'
# build:
# context: .
# dockerfile: dev.Dockerfile
# ports:
# - 80:80
# volumes:
# - .:/app
# env_file:
# - ./.env-docker.dev
# depends_on:
# - db

volumes:
postgres_data:
Expand Down
15 changes: 14 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
# pytest.ini
[pytest]
addopts = -W error -p no:warnings
env =
C_FORCE_ROOT=true
AUTH_DISABLED=true
AUTH_DATABASE_NAME='test_auth'
USE_SENTINEL=False
USE_LOCAL_TEST_DB=False
TEST_MODE='DockerTestingConfig'
QUEUE_LENGTH_LIMIT=100
QUEUES_TO_THROTTLE="celery"
REDIS_HOST="memory://"
REDIS_PORT=""
REDIS_PASSWORD=""
addopts = -W error -p no:warnings
log_cli = true
log_cli_level = INFO
log_cli_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)
log_cli_date_format=%Y-%m-%d %H:%M:%S
testpaths = "test"
23 changes: 12 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile requirements.in
#
# This file was autogenerated by uv via the following command:
# uv pip compile requirements.in -o requirements.txt
alembic==1.7.6
# via dynamicannotationdb
aniso8601==9.0.1
# via flask-restx
appnope==0.1.4
# via ipython
attrs==21.4.0
# via
# caveclient
Expand Down Expand Up @@ -51,7 +49,9 @@ flask-accepts==0.18.4
flask-admin==1.6.0
# via -r requirements.in
flask-cors==3.0.10
# via -r requirements.in
# via
# -r requirements.in
# emannotationschemas
flask-marshmallow==0.14.0
# via -r requirements.in
flask-restx==0.5.1
Expand Down Expand Up @@ -104,7 +104,7 @@ marshmallow-sqlalchemy==0.27.0
# via -r requirements.in
matplotlib-inline==0.1.3
# via ipython
middle-auth-client==3.11.1
middle-auth-client==3.18.1
# via -r requirements.in
multiwrapper==0.1.1
# via -r requirements.in
Expand Down Expand Up @@ -160,6 +160,10 @@ requests==2.27.1
# -r requirements.in
# caveclient
# middle-auth-client
setuptools==75.3.0
# via
# ipython
# jsonschema
shapely==2.0.3
# via
# dynamicannotationdb
Expand Down Expand Up @@ -200,6 +204,3 @@ wrapt==1.13.3
# via deprecated
wtforms==3.0.1
# via flask-admin

# The following packages are considered to be unsafe in a requirements file:
# setuptools
1 change: 1 addition & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def app_config(client):

@pytest.fixture()
def modify_g(client):
g.auth_user = {"id": 1}
g.user = "test"
g.id = 1

Expand Down
5 changes: 3 additions & 2 deletions test/test_anno_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
def test_create_db(app_config, mocker):
with app_config.app_context():
db = get_db("test_aligned_volume")
logging.info(db.__dict__)
assert db.__dict__["aligned_volume"] == "test_aligned_volume"
logging.info(f"db.__dict__: {db.__dict__}")
assert "_aligned_volume" in db.__dict__
assert db.__dict__["_aligned_volume"] == "test_aligned_volume"
95 changes: 65 additions & 30 deletions test/test_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from flask import g
import json
import logging
import sys
Expand All @@ -7,7 +8,6 @@

aligned_volume_name = "test_aligned_volume"


class TestHealthEndpoint:
def test_health_endpoint(self, client):
url = "annotation/api/versions"
Expand Down Expand Up @@ -44,8 +44,7 @@ def test_post_table(self, client):
follow_redirects=True,
)
logging.info(response)
logging.info(f"RETURN VALUE {response}")
assert response.json == {}
assert response.json is None

def test_post_table_to_be_deleted(self, client):
logging.info(client)
Expand Down Expand Up @@ -83,10 +82,11 @@ def test_get_tables(self, client):
) as mock_aligned_volumes:
mock_aligned_volumes.return_value = aligned_volume_name
response = client.get(
url, content_type="application/json", follow_redirects=False
url, content_type="application/json",
follow_redirects=False
)
logging.info(response)

assert response.json == ["test_table", "test_table_to_delete"]


Expand All @@ -102,12 +102,13 @@ def test_get_table_metadata(self, client):
) as mock_aligned_volumes:
mock_aligned_volumes.return_value = aligned_volume_name

response = client.get(url, follow_redirects=False)
response = client.get(url,
follow_redirects=False
)
logging.info(response.json)

metadata = {
"table_name": "test_table",
"created": "2021-11-19T13:19:02.981200",
"id": 1,
"deleted": None,
"description": "Test description",
Expand All @@ -116,22 +117,30 @@ def test_get_table_metadata(self, client):
"valid": True,
"schema_type": "synapse",
"user_id": "1",
"notice_text": None,
"reference_table": None,
"voxel_resolution_x": 4.0,
"voxel_resolution_z": 40.0,
"read_permission": "PUBLIC",
"write_permission": "PRIVATE",
}
assert response.json == metadata
response_json = response.json
del response_json['created']
del response_json['last_modified']
assert response_json == metadata

def test_mark_table_to_delete(self, client):
def test_mark_table_to_delete(self, client, modify_g):

url = f"/annotation/api/v2/aligned_volume/{aligned_volume_name}/table/test_table_to_delete"

with mock.patch(
"annotationengine.api.check_aligned_volume"
) as mock_aligned_volumes:
mock_aligned_volumes.return_value = aligned_volume_name

response = client.delete(url, follow_redirects=False)
response = client.delete(url,
follow_redirects=False
)
logging.info(response.json)
assert response.json is True

Expand All @@ -143,13 +152,15 @@ def test_get_row_count(self, client):
"annotationengine.api.check_aligned_volume"
) as mock_aligned_volumes:
mock_aligned_volumes.return_value = aligned_volume_name
response = client.get(url, follow_redirects=False)
response = client.get(url,
follow_redirects=False
)
logging.info(response.json)
assert response.json == 0


class TestAnnotationsEndpoints:
def test_post_annotations(self, client):
def test_post_annotations(self, client, modify_g):

url = f"/annotation/api/v2/aligned_volume/{aligned_volume_name}/table/test_table/annotations"
data = {
Expand All @@ -158,6 +169,7 @@ def test_post_annotations(self, client):
"pre_pt": {"position": [31, 31, 0]},
"ctr_pt": {"position": [32, 32, 0]},
"post_pt": {"position": [33, 33, 0]},
"size": 1,
},
]
}
Expand All @@ -166,29 +178,43 @@ def test_post_annotations(self, client):
auth_user.id = 1

with mock.patch(
"annotationengine.api.check_aligned_volume"
"annotationengine.api.check_aligned_volume",
) as mock_aligned_volumes:
mock_aligned_volumes.return_value = aligned_volume_name

response = client.post(
url,
data=json.dumps(data),
content_type="application/json",
follow_redirects=False,
)
logging.info(response)
assert response.json == [1]
with mock.patch(
"annotationengine.api.trigger_supervoxel_lookup",
) as mock_trigger_supervoxel_lookup:
mock_trigger_supervoxel_lookup.return_value = None

response = client.post(
url,
data=json.dumps(data),
content_type="application/json",
follow_redirects=False,
)
logging.info(response)
assert response.json == [1]

def test_get_annotations(self, client):
url = f"/annotation/api/v2/aligned_volume/{aligned_volume_name}/table/test_table/annotations"
data = {"annotation_ids": [1]}
data = {"annotation_ids": "1"}
with mock.patch(
"annotationengine.api.check_aligned_volume"
) as mock_aligned_volumes:
mock_aligned_volumes.return_value = aligned_volume_name
response = client.get(url, data=json.dumps(data), follow_redirects=False)
response = client.get(url, query_string=data,
follow_redirects=False
)
logging.info(response)
assert response.json == [1]
logging.info(response.json)
logging.info(response.json[0])
assert response.json[0]["id"] == 1
assert response.json[0]["pre_pt_position"] == [31, 31, 0]
assert response.json[0]["ctr_pt_position"] == [32, 32, 0]
assert response.json[0]["post_pt_position"] == [33, 33, 0]
assert response.json[0]["valid"] == True
assert response.json[0]["superceded_id"] == None
assert response.json[0]["deleted"] == 'None'

def test_update_annotations(self, client):
url = f"/annotation/api/v2/aligned_volume/{aligned_volume_name}/table/test_table/annotations"
Expand All @@ -199,16 +225,23 @@ def test_update_annotations(self, client):
"pre_pt": {"position": [22, 22, 0]},
"ctr_pt": {"position": [32, 32, 0]},
"post_pt": {"position": [33, 33, 0]},
"size": 1,
},
]
}
with mock.patch(
"annotationengine.api.check_aligned_volume"
) as mock_aligned_volumes:
mock_aligned_volumes.return_value = aligned_volume_name
response = client.post(url, data=json.dumps(data), follow_redirects=False)
logging.info(response)
assert response.json == {1: 2}
with mock.patch(
"annotationengine.api.trigger_supervoxel_lookup",
) as mock_trigger_supervoxel_lookup:
mock_trigger_supervoxel_lookup.return_value = None
response = client.put(url, data=json.dumps(data),
follow_redirects=False
)
logging.info(response)
assert response.json == {'1': 2}

def test_delete_annotations(self, client):
url = f"/annotation/api/v2/aligned_volume/{aligned_volume_name}/table/test_table/annotations"
Expand All @@ -218,6 +251,8 @@ def test_delete_annotations(self, client):
"annotationengine.api.check_aligned_volume"
) as mock_aligned_volumes:
mock_aligned_volumes.return_value = aligned_volume_name
response = client.delete(url, data=json.dumps(data), follow_redirects=False)
response = client.delete(url, data=json.dumps(data),
follow_redirects=False
)
logging.info(response)
assert response.json == [2]
Loading
Loading