Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
fix/more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
naknomum committed Dec 15, 2023
1 parent ea9a429 commit 06dd67d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
7 changes: 3 additions & 4 deletions tests/extensions/export/resources/test_export_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ def test_export_api(
resp = export_utils.export_search(
flask_app_client, researcher_2, query, 'sightings', 400
)
# TODO fix when encounters working
# now lets test encounter export too
# resp = export_utils.export_search(flask_app_client, admin_user, {}, 'encounters')
# assert resp.content_type == 'application/vnd.ms-excel'
# assert resp.content_length > 1000
resp = export_utils.export_search(flask_app_client, researcher_1, {}, 'encounters')
assert resp.content_type == 'application/vnd.ms-excel'
assert resp.content_length > 1000
export_utils.clear_files()


Expand Down
2 changes: 1 addition & 1 deletion tests/extensions/export/resources/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def export_search(
resp = test_utils.post_via_flask(
flask_app_client,
user,
'sightings:read',
f'{class_name}:read',
f'/api/v1/{class_name}/export',
data,
expected_status_code,
Expand Down
8 changes: 7 additions & 1 deletion tests/modules/sightings/resources/test_create_sighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_create_failures(flask_app_client, test_root, researcher_1, request):

@pytest.mark.skipif(module_unavailable('sightings'), reason='Sightings module disabled')
def test_create_and_modify_and_delete_sighting(
db, flask_app_client, researcher_1, test_root, staff_user, request
db, flask_app_client, researcher_1, researcher_2, test_root, staff_user, request
):
import tests.modules.site_settings.resources.utils as site_setting_utils
from app.modules.complex_date_time.models import Specificities
Expand Down Expand Up @@ -122,6 +122,12 @@ def test_create_and_modify_and_delete_sighting(
enc1_id = uuids['encounters'][1]
assert enc0_id is not None
assert enc1_id is not None
assert sighting.user_has_view_permission(researcher_1)
assert not sighting.user_has_view_permission(researcher_2)
viewers = sighting.viewer_guids()
assert str(researcher_1.guid) in viewers
assert not str(researcher_2.guid) in viewers
assert str(staff_user.guid) in viewers

sighting_utils.read_sighting(flask_app_client, researcher_1, sighting_id)

Expand Down
23 changes: 22 additions & 1 deletion tests/modules/sightings/resources/test_sighting_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,36 @@ def test_search(flask_app_client, researcher_1, request, test_root):
)['sighting']
# Force created sighting to be indexed in elasticsearch
Sighting.query.get(sighting_guid).index()
wait_for_elasticsearch_status(flask_app_client, researcher_1)

test_utils.get_list_via_flask(
resp = test_utils.get_list_via_flask(
flask_app_client,
researcher_1,
scopes='sightings:read',
path='/api/v1/sightings/search',
expected_status_code=200,
expected_fields=EXPECTED_KEYS,
)
assert len(resp.json) == 1
assert resp.json[0]['guid'] == str(sighting_guid)
assert resp.headers['X-Total-Count'] == '1'
# is -1 cuz query above was "atypical" .... meh
assert resp.headers['X-Viewable-Count'] == '-1'

resp = test_utils.post_via_flask(
flask_app_client,
researcher_1,
scopes='sightings:read',
path='/api/v1/sightings/search',
data={'bool': {'filter': [], 'must_not': []}},
expected_status_code=200,
response_200=EXPECTED_KEYS,
returns_list=True,
)
assert len(resp.json) == 1
assert resp.json[0]['guid'] == str(sighting_guid)
assert resp.headers['X-Total-Count'] == '1'
assert resp.headers['X-Viewable-Count'] == '1'


@pytest.mark.skipif(module_unavailable('sightings'), reason='Sightings module disabled')
Expand Down

0 comments on commit 06dd67d

Please sign in to comment.