Skip to content

Commit 5e2ed70

Browse files
committed
More fixing tests
1 parent 297d87f commit 5e2ed70

16 files changed

+64
-70
lines changed

.coveragerc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[run]
2+
branch = True
3+
omit =
4+
*test*
5+
*/__init__.py

Makefile

+16-24
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ GIT_COMMIT:=$$(git rev-parse --short HEAD)
2626
GIT_BRANCH:=$$(if [[ -n $$(git branch --show-current) ]]; then git branch --show-current; else git branch -a --contains $$(git rev-parse --short HEAD) | sed '/HEAD/d' | sed 's/remotes\/origin\///g' | sed 's/\*//g' | sed 's/ *//g' | awk '!_[$$0]++'; fi)
2727
GIT_TAG:=$$(git describe --exact-match --tags --abbrev=0 2>/dev/null)
2828
IMAGE_NAME:=flowminder/$(APP_NAME):$$(TAG=$(GIT_TAG) && [[ -n $$TAG ]] && echo $$TAG || echo $(GIT_COMMIT))
29-
IMAGE_NAME_DB:=$(subst $(APP_NAME),$(APP_NAME_DB),$(IMAGE_NAME))
3029
IMAGE_NAME_TEST:=$(subst $(APP_NAME),$(APP_NAME_TEST),$(IMAGE_NAME))
3130
PACKAGE_NAME:=$(subst -,_,$(APP_NAME))
3231
APP_DIR:=$(CONTAINER_USER)/$(PACKAGE_NAME)
@@ -51,7 +50,6 @@ else
5150
RELOAD:=
5251
IMAGE_NAME_ACTUAL:=$(IMAGE_NAME)
5352
endif
54-
IMAGE_NAME_DB_ACTUAL:=$(subst $(APP_NAME),$(APP_NAME_DB),$(IMAGE_NAME_ACTUAL))
5553
IMAGE_NAME_TEST_ACTUAL:=$(subst $(APP_NAME),$(APP_NAME_TEST),$(IMAGE_NAME_ACTUAL))
5654

5755
# set flag for docker cache
@@ -91,7 +89,6 @@ else
9189
endif
9290

9391
# Don't print verbose output from make target - only print output of commands.
94-
.SILENT:
9592

9693
# Targets #####################################################################
9794

@@ -165,28 +162,23 @@ build: --clean --codegen
165162
-t $(IMAGE_NAME_DB) $(subst $(APP_NAME),$(APP_NAME_DB),$(DOCKER_LATEST_TAG)) .
166163
echo "Done. Built docker images \"$(IMAGE_NAME)\", \"$(IMAGE_NAME_TEST)\" and \"$(IMAGE_NAME_DB)\" for API version $(API_VERSION)."
167164

168-
test:
169-
$(eval CONTAINER_NAME:=$(CONTAINER_NAME)_test)
170-
$(eval CONTAINER_NAME_DB:=$(CONTAINER_NAME_DB)_test)
171-
$(eval SERVER_PORT_HOST:=$(shell echo $$(($(SERVER_PORT_HOST)+1))))
172-
$(eval DB_PORT_HOST:=$(shell echo $$(($(DB_PORT_HOST)+1))))
173-
export IMAGE_NAME_DB_ACTUAL=$(IMAGE_NAME_DB_ACTUAL); \
174-
docker compose -p $(APP_NAME_TEST) --env-file ./.env up -d --always-recreate-deps db
165+
run-db:
166+
docker compose -f docker-compose-mysql.yml --env-file ./development_env up -d --always-recreate-deps db
175167
while [ $$(docker inspect --format "{{json .State.Health.Status }}" $(CONTAINER_NAME_DB)) != "\"healthy\"" ]; do echo "Waiting for db..."; sleep 1; done
176-
export IMAGE_NAME_ACTUAL=$(IMAGE_NAME_TEST_ACTUAL); \
177-
docker compose -p $(APP_NAME_TEST) --env-file ./.env run web \
178-
"python -m pytest $(SELECTED_TESTS) \
179-
--disable-pytest-warnings -p no:warnings -vvvv \
180-
-o log_cli=false --show-capture=all \
181-
--cov-config=/home/$(APP_DIR)/.coveragerc \
182-
--cov=$(PACKAGE_NAME) \
183-
--cov-report term-missing \
184-
--cov-report xml:/home/$(APP_DIR)/test_results/coverage.xml \
185-
--junit-xml=/home/$(APP_DIR)/test_results/results.xml \
186-
/home/$(APP_DIR)/src-generated/tests /home/$(APP_DIR)/src-generated/src/$(PACKAGE_NAME)/impl/tests"; \
187-
ERR=$$?; \
188-
docker compose -p $(APP_NAME_TEST) down ;\
189-
exit $$ERR
168+
169+
test: run-db
170+
source venv/bin/activate; python -m pytest $(SELECTED_TESTS) \
171+
--disable-pytest-warnings -p no:warnings -vvvv \
172+
-o log_cli=false --show-capture=all \
173+
--cov-config=.coveragerc \
174+
--cov=$(PACKAGE_NAME) \
175+
--cov-report term-missing \
176+
--cov-report xml:./test_results/coverage.xml \
177+
--junit-xml=./test_results/results.xml \
178+
tests; \
179+
ERR=$$?; \
180+
docker compose -f docker-compose-mysql.yml down ;\
181+
exit $$ERR
190182

191183
clear:
192184
$(info Clearing old containers...)

flowkit_ui_backend/apis/accounts_api.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
response_class=ORJSONResponse,
6060
)
6161
async def delete_user(
62-
uid: str = Path(None, description="The user ID"),
62+
uid: str = Path(description="The user ID"),
6363
token_auth0: TokenModel = Security(get_token_auth0, scopes=["profile"]),
6464
request: Request = None,
6565
) -> None:
@@ -139,7 +139,7 @@ async def delete_user(
139139
response_class=ORJSONResponse,
140140
)
141141
async def get_user(
142-
uid: str = Path(None, description="The user ID"),
142+
uid: str = Path(description="The user ID"),
143143
token_auth0: TokenModel = Security(get_token_auth0, scopes=["profile"]),
144144
request: Request = None,
145145
) -> UserMetadata:
@@ -218,7 +218,7 @@ async def get_user(
218218
response_class=ORJSONResponse,
219219
)
220220
async def reset_password(
221-
email: str = Path(None, description="The user's email address"),
221+
email: str = Path(description="The user's email address"),
222222
token_auth0: TokenModel = Security(get_token_auth0, scopes=["profile"]),
223223
request: Request = None,
224224
) -> None:
@@ -295,7 +295,7 @@ async def reset_password(
295295
response_class=ORJSONResponse,
296296
)
297297
async def update_user(
298-
uid: str = Path(None, description="The user ID"),
298+
uid: str = Path(description="The user ID"),
299299
user_metadata: UserMetadata = Body(None, description="The user to update"),
300300
token_auth0: TokenModel = Security(get_token_auth0, scopes=["profile"]),
301301
request: Request = None,

flowkit_ui_backend/apis/data_api.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
response_class=ORJSONResponse,
7373
)
7474
async def get_category(
75-
category_id: str = Path(None, description="The category ID", max_length=255),
75+
category_id: str = Path(description="The category ID", max_length=255),
7676
token_auth0: TokenModel = Security(get_token_auth0, scopes=["read:free_data"]),
7777
request: Request = None,
7878
) -> Category:
@@ -148,7 +148,7 @@ async def get_category(
148148
response_class=ORJSONResponse,
149149
)
150150
async def get_indicator(
151-
indicator_id: str = Path(None, description="The indicator ID", max_length=255),
151+
indicator_id: str = Path(description="The indicator ID", max_length=255),
152152
token_auth0: TokenModel = Security(get_token_auth0, scopes=["read:free_data"]),
153153
request: Request = None,
154154
) -> Indicator:
@@ -224,7 +224,7 @@ async def get_indicator(
224224
response_class=ORJSONResponse,
225225
)
226226
async def get_indicators_for_category(
227-
category_id: str = Path(None, description="The category ID", max_length=255),
227+
category_id: str = Path(description="The category ID", max_length=255),
228228
token_auth0: TokenModel = Security(get_token_auth0, scopes=["read:free_data"]),
229229
request: Request = None,
230230
) -> Indicators:
@@ -302,7 +302,7 @@ async def get_indicators_for_category(
302302
response_class=ORJSONResponse,
303303
)
304304
async def get_spatial_resolution(
305-
srid: int = Path(None, description="The spatial resolution ID", ge=1),
305+
srid: int = Path(description="The spatial resolution ID", ge=1),
306306
token_auth0: TokenModel = Security(get_token_auth0, scopes=["read:free_data"]),
307307
request: Request = None,
308308
) -> SpatialResolution:
@@ -380,7 +380,7 @@ async def get_spatial_resolution(
380380
response_class=ORJSONResponse,
381381
)
382382
async def get_spatial_resolutions_for_category(
383-
category_id: str = Path(None, description="The category ID", max_length=255),
383+
category_id: str = Path(description="The category ID", max_length=255),
384384
token_auth0: TokenModel = Security(get_token_auth0, scopes=["read:free_data"]),
385385
request: Request = None,
386386
) -> SpatialResolutions:
@@ -458,7 +458,7 @@ async def get_spatial_resolutions_for_category(
458458
response_class=ORJSONResponse,
459459
)
460460
async def get_temporal_resolution(
461-
trid: int = Path(None, description="The temporal resolution ID", ge=1),
461+
trid: int = Path(description="The temporal resolution ID", ge=1),
462462
token_auth0: TokenModel = Security(get_token_auth0, scopes=["read:free_data"]),
463463
request: Request = None,
464464
) -> TemporalResolution:
@@ -536,7 +536,7 @@ async def get_temporal_resolution(
536536
response_class=ORJSONResponse,
537537
)
538538
async def get_temporal_resolutions_for_category(
539-
category_id: str = Path(None, description="The category ID", max_length=255),
539+
category_id: str = Path(description="The category ID", max_length=255),
540540
token_auth0: TokenModel = Security(get_token_auth0, scopes=["read:free_data"]),
541541
request: Request = None,
542542
) -> TemporalResolutions:
@@ -618,10 +618,10 @@ async def get_temporal_resolutions_for_category(
618618
response_class=ORJSONResponse,
619619
)
620620
async def get_time_range(
621-
category_id: str = Path(None, description="The category ID", max_length=255),
622-
indicator_id: str = Path(None, description="The indicator ID", max_length=255),
623-
srid: int = Path(None, description="The spatial resolution ID", ge=1),
624-
trid: int = Path(None, description="The temporal resolution ID", ge=1),
621+
category_id: str = Path(description="The category ID", max_length=255),
622+
indicator_id: str = Path(description="The indicator ID", max_length=255),
623+
srid: int = Path(description="The spatial resolution ID", ge=1),
624+
trid: int = Path(description="The temporal resolution ID", ge=1),
625625
token_auth0: TokenModel = Security(get_token_auth0, scopes=["read:free_data"]),
626626
request: Request = None,
627627
) -> TimeRange:

flowkit_ui_backend/apis/maintenance_api.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ async def create_temporal_resolution(
781781
response_class=ORJSONResponse,
782782
)
783783
async def delete_category(
784-
category_id: str = Path(None, description="The category ID", max_length=255),
784+
category_id: str = Path(description="The category ID", max_length=255),
785785
token_auth0: TokenModel = Security(get_token_auth0, scopes=["admin"]),
786786
request: Request = None,
787787
) -> None:
@@ -860,7 +860,7 @@ async def delete_category(
860860
response_class=ORJSONResponse,
861861
)
862862
async def delete_data_provider(
863-
dpid: int = Path(None, description="The data provider ID"),
863+
dpid: int = Path(description="The data provider ID"),
864864
token_auth0: TokenModel = Security(get_token_auth0, scopes=["admin"]),
865865
request: Request = None,
866866
) -> None:
@@ -1019,7 +1019,7 @@ async def delete_dataset(
10191019
response_class=ORJSONResponse,
10201020
)
10211021
async def delete_indicator(
1022-
indicator_id: str = Path(None, description="The indicator ID", max_length=255),
1022+
indicator_id: str = Path(description="The indicator ID", max_length=255),
10231023
token_auth0: TokenModel = Security(get_token_auth0, scopes=["admin"]),
10241024
request: Request = None,
10251025
) -> None:
@@ -1255,7 +1255,7 @@ async def delete_setup(
12551255
response_class=ORJSONResponse,
12561256
)
12571257
async def delete_spatial_resolution(
1258-
srid: int = Path(None, description="The spatial resolution ID", ge=1),
1258+
srid: int = Path(description="The spatial resolution ID", ge=1),
12591259
token_auth0: TokenModel = Security(get_token_auth0, scopes=["admin"]),
12601260
request: Request = None,
12611261
) -> None:
@@ -1334,7 +1334,7 @@ async def delete_spatial_resolution(
13341334
response_class=ORJSONResponse,
13351335
)
13361336
async def delete_temporal_resolution(
1337-
trid: int = Path(None, description="The temporal resolution ID", ge=1),
1337+
trid: int = Path(description="The temporal resolution ID", ge=1),
13381338
token_auth0: TokenModel = Security(get_token_auth0, scopes=["admin"]),
13391339
request: Request = None,
13401340
) -> None:
@@ -1489,7 +1489,7 @@ async def replace_setup(
14891489
response_class=ORJSONResponse,
14901490
)
14911491
async def update_category(
1492-
category_id: str = Path(None, description="The category ID", max_length=255),
1492+
category_id: str = Path(description="The category ID", max_length=255),
14931493
category: Category = Body(None, description="The new resource"),
14941494
token_auth0: TokenModel = Security(get_token_auth0, scopes=["admin"]),
14951495
request: Request = None,
@@ -1569,7 +1569,7 @@ async def update_category(
15691569
response_class=ORJSONResponse,
15701570
)
15711571
async def update_data_provider(
1572-
dpid: int = Path(None, description="The data provider ID"),
1572+
dpid: int = Path(description="The data provider ID"),
15731573
data_provider: DataProvider = Body(None, description="The new resource"),
15741574
token_auth0: TokenModel = Security(get_token_auth0, scopes=["write:data"]),
15751575
request: Request = None,
@@ -1727,7 +1727,7 @@ async def update_dataset(
17271727
response_class=ORJSONResponse,
17281728
)
17291729
async def update_indicator(
1730-
indicator_id: str = Path(None, description="The indicator ID", max_length=255),
1730+
indicator_id: str = Path(description="The indicator ID", max_length=255),
17311731
indicator: Indicator = Body(None, description="The new resource"),
17321732
token_auth0: TokenModel = Security(get_token_auth0, scopes=["admin"]),
17331733
request: Request = None,
@@ -1886,7 +1886,7 @@ async def update_setup(
18861886
response_class=ORJSONResponse,
18871887
)
18881888
async def update_spatial_resolution(
1889-
srid: int = Path(None, description="The spatial resolution ID", ge=1),
1889+
srid: int = Path(description="The spatial resolution ID", ge=1),
18901890
spatial_resolution: SpatialResolution = Body(None, description="The new resource"),
18911891
token_auth0: TokenModel = Security(get_token_auth0, scopes=["admin"]),
18921892
request: Request = None,
@@ -1969,7 +1969,7 @@ async def update_spatial_resolution(
19691969
response_class=ORJSONResponse,
19701970
)
19711971
async def update_temporal_resolution(
1972-
trid: int = Path(None, description="The temporal resolution ID", ge=1),
1972+
trid: int = Path(description="The temporal resolution ID", ge=1),
19731973
temporal_resolution: TemporalResolution = Body(
19741974
None, description="The new resource"
19751975
),

flowkit_ui_backend/impl/accounts_api_impl.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
from dotenv import load_dotenv
1212
from flowkit_ui_backend.models.extra_models import TokenModel
1313
from flowkit_ui_backend.models.user_metadata import UserMetadata
14-
from auth0.v3.asyncify import asyncify
15-
from auth0.v3.management import Auth0
16-
from auth0.v3.authentication import GetToken
14+
from auth0.asyncify import asyncify
15+
from auth0.management import Auth0
16+
from auth0.authentication import GetToken
1717

1818
load_dotenv()
1919

flowkit_ui_backend/impl/data_api_impl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ async def run_query(
319319

320320
# support getting mdids only
321321
if query_parameters.mdids_only is True:
322-
return QueryResult(mdids=[m.mdid for m in metadata])
322+
return QueryResult(mdids=[f"{m.mdid}" for m in metadata])
323323

324324
logger.debug(f"Found metadata objects, now getting data...", num=len(metadata))
325325

flowkit_ui_backend/impl/general_api_impl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async def heartbeat(pool: Pool) -> Heartbeat:
5858
heartbeat = Heartbeat(
5959
api_version=os.getenv("API_VERSION"),
6060
api_version_url_appendix=os.getenv("API_VERSION_URL_APPENDIX"),
61-
datetime=f"{datetime.datetime.utcnow().isoformat()}Z",
61+
datetime=datetime.datetime.utcnow(),
6262
docker_image=os.getenv("IMAGE_NAME"),
6363
git_branch=os.getenv("GIT_BRANCH"),
6464
git_commit=os.getenv("GIT_COMMIT"),

flowkit_ui_backend/security_api.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66
import os
77
import structlog
88
from typing import List, Optional
9-
from auth0.v3.authentication.async_token_verifier import (
10-
AsyncAsymmetricSignatureVerifier,
11-
)
12-
139

10+
from auth0.authentication.async_token_verifier import AsyncAsymmetricSignatureVerifier
1411
from fastapi import Depends, Security # noqa: F401
1512
from fastapi.openapi.models import OAuthFlowImplicit, OAuthFlows # noqa: F401
1613
from fastapi.security import ( # noqa: F401

setup.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ version = 1.3.0
44
description = A REST API for managing and postprocessing Flowkit data
55
long_description = file: README.md
66
keywords = OpenAPI FlowKitUI Backend
7-
python_requires = >= 3.7.*
7+
python_requires = >= 3.8.*
88
classifiers =
99
Operating System :: OS Independent
1010
Programming Language :: Python :: 3
11-
Programming Language :: Python :: 3.7
11+
Programming Language :: Python :: 3.8
1212

1313
[options]
1414
install_requires = fastapi[all]

0 commit comments

Comments
 (0)