Skip to content

Commit df8bac5

Browse files
committed
test(exotaxoserver): newly tested endpoint
1 parent 4429546 commit df8bac5

File tree

6 files changed

+64
-8
lines changed

6 files changed

+64
-8
lines changed

QA/py/tests/api_wrappers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,6 @@ def api_check_job_failed(fastapi, job_id, expected_message):
8484
expected_message,
8585
), job_dict
8686
return rsp
87+
88+
89+
UPLOAD_FILE_URL = "/user_files/"

QA/py/tests/holes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from tests.credentials import USER_AUTH, CREATOR_AUTH
1111
from tests.test_classification import OBJECT_SET_SUMMARY_URL
1212
from tests.test_import import PLAIN_FILE_PATH, do_test_import
13-
from tests.test_import_simple import UPLOAD_FILE_URL
13+
from tests.api_wrappers import UPLOAD_FILE_URL
1414

1515
MYFILES_URL = "/my_files/{sub_path}"
1616
COMMON_FILES_URL = "/common_files/?path={sub_path}"

QA/py/tests/test_import.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from pathlib import Path
88

99
import pytest
10+
from starlette import status
11+
1012
from API_models.crud import *
1113

1214
# noinspection PyPackageRequirements
@@ -17,17 +19,15 @@
1719
from API_operations.CRUD.Projects import ProjectsService
1820
from API_operations.JsonDumper import JsonDumper
1921

20-
2122
# noinspection PyPackageRequirements
2223
from DB.Job import DBJobStateEnum
23-
from starlette import status
24-
2524
from tests.api_wrappers import (
2625
api_file_import,
2726
api_wait_for_stable_job,
2827
api_check_job_questions,
28+
UPLOAD_FILE_URL,
2929
)
30-
from tests.credentials import ADMIN_AUTH, ADMIN_USER_ID
30+
from tests.credentials import ADMIN_AUTH, ADMIN_USER_ID, CREATOR_USER_ID, CREATOR_AUTH
3131
from tests.jobs import (
3232
check_job_ok,
3333
check_job_errors,

QA/py/tests/test_import_simple.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@
2525
from tests.credentials import ADMIN_USER_ID, CREATOR_AUTH, CREATOR_USER_ID
2626
from tests.test_import import PLAIN_DIR, create_project, PLAIN_FILE_PATH
2727
from tests.jobs import check_job_ok
28-
from tests.api_wrappers import api_wait_for_stable_job
28+
from tests.api_wrappers import api_wait_for_stable_job, UPLOAD_FILE_URL
2929

3030
IMPORT_IMAGES_URL = "/simple_import/{project_id}?dry_run={dry_run}"
31-
UPLOAD_FILE_URL = "/user_files/"
3231

3332

3433
# @pytest.mark.skip()

QA/py/tests/test_my_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
api_file_import,
2121
api_wait_for_stable_job,
2222
api_check_job_errors,
23+
UPLOAD_FILE_URL,
2324
)
2425
from tests.test_import import (
2526
SHARED_DIR,
2627
V6_FILE,
2728
create_project,
2829
)
29-
from tests.test_import_simple import UPLOAD_FILE_URL
3030

3131
SEPARATOR = "/"
3232
DIRPATH = "XXX"

QA/py/tests/test_taxoserver.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
SEARCH_WORMS_URL = "/searchworms/{}"
1010
TAXA_FROM_CENTRAL_URL = "/taxa/pull_from_central"
11+
TAXON_PUT = "/taxon/central"
1112

1213
ACARTIA_RSP = [
1314
{
@@ -123,3 +124,56 @@ def test_pull_taxa_update_from_central(fastapi, mocker):
123124
rsp = fastapi.get(TAXA_FROM_CENTRAL_URL, headers=ADMIN_AUTH)
124125
# assert rsp.status_code == status.HTTP_200_OK
125126
assert rsp.json() == {"inserts": 0, "updates": 0, "error": None}
127+
128+
129+
def test_add_taxon_in_central(fastapi, mocker):
130+
# Mock the 'call' method of EcoTaxoServerClient
131+
mock_call = mocker.patch("providers.EcoTaxoServer.EcoTaxoServerClient.call")
132+
mock_response = mocker.Mock()
133+
mock_response.json.return_value = {"msg": "ok", "id": 789999}
134+
mock_call.return_value = mock_response
135+
136+
params = {
137+
"name": "NewTaxon",
138+
"parent_id": 1,
139+
"taxotype": "P",
140+
"creator_email": "creator@test.com",
141+
"source_desc": "Test source",
142+
"source_url": "http://test.com",
143+
}
144+
145+
rsp = fastapi.put(TAXON_PUT, params=params, headers=ADMIN_AUTH)
146+
147+
assert rsp.status_code == status.HTTP_200_OK
148+
assert rsp.json()["msg"] == "ok"
149+
150+
# Verify the mock was called correctly
151+
# The service adds 'creation_datetime' and 'taxostatus'
152+
called_args = mock_call.call_args
153+
assert called_args[0][0] == "/settaxon/"
154+
sent_params = called_args[0][1]
155+
assert sent_params["name"] == "NewTaxon"
156+
assert (
157+
sent_params["parent_id"] == "1"
158+
) # FastAPI Query params are strings in request.query_params
159+
assert sent_params["taxotype"] == "P"
160+
assert sent_params["creator_email"] == "creator@test.com"
161+
assert sent_params["taxostatus"] == "N"
162+
assert "creation_datetime" in sent_params
163+
164+
165+
def test_add_taxon_in_central_unauthorized(fastapi, mocker):
166+
# Mock the 'call' method of EcoTaxoServerClient
167+
mock_call = mocker.patch("providers.EcoTaxoServer.EcoTaxoServerClient.call")
168+
169+
params = {
170+
"name": "NewTaxonUnauthorized",
171+
"parent_id": 1,
172+
"taxotype": "P",
173+
"creator_email": "creator@test.com",
174+
}
175+
176+
# Unauthenticated call
177+
rsp = fastapi.put(TAXON_PUT, params=params)
178+
assert rsp.status_code == status.HTTP_403_FORBIDDEN
179+
assert mock_call.call_count == 0

0 commit comments

Comments
 (0)