diff --git a/backend/test/integration/test_account.py b/backend/test/integration/test_account.py index cb637b0d..e1386ed9 100644 --- a/backend/test/integration/test_account.py +++ b/backend/test/integration/test_account.py @@ -1,4 +1,5 @@ import json, os +from uuid import uuid4 from appointment.database.models import ExternalConnectionType from defines import auth_headers, TEST_USER_ID @@ -6,8 +7,7 @@ class TestAccount: def test_account_get_external_connections(self, with_client, make_external_connections): # add a couple of external connections to our test user - username = 'username' - type_id = json.dumps(['url', username]) + type_id = str(uuid4()) zoom_ec = make_external_connections(TEST_USER_ID, type=ExternalConnectionType.zoom, type_id=type_id) assert zoom_ec.type_id == type_id google_ec = make_external_connections(TEST_USER_ID, type=ExternalConnectionType.google, type_id=type_id) @@ -44,7 +44,7 @@ def test_account_available_emails(self, with_client, make_external_connections): assert email_list_ret == user_email_list # now add another email/name via a google connection - type_id = json.dumps(['url', test_user_email]) + type_id = str(uuid4()) google_ec = make_external_connections(TEST_USER_ID, type=ExternalConnectionType.google, type_id=type_id) user_email_list.append(google_ec.name) diff --git a/backend/test/integration/test_appointment.py b/backend/test/integration/test_appointment.py index 7043d07a..bb4c126b 100644 --- a/backend/test/integration/test_appointment.py +++ b/backend/test/integration/test_appointment.py @@ -20,7 +20,6 @@ def list_events(self, start, end): end = dateutil.parser.parse(end) from appointment.database import schemas - print('list events!') return [ schemas.Event( title=generated_appointment.title, @@ -36,7 +35,6 @@ def list_events(self, start, end): monkeypatch.setattr(CalDavConnector, 'list_events', list_events) path = f'/rmt/cal/{generated_appointment.calendar_id}/' + DAY1 + '/' + DAY3 - print(f'>>> {path}') response = with_client.get(path, headers=auth_headers) assert response.status_code == 200, response.text data = response.json() @@ -49,7 +47,6 @@ def test_get_remote_caldav_events_inavlid_calendar(self, with_client, make_appoi generated_appointment = make_appointment() path = f'/rmt/cal/{generated_appointment.calendar_id + 999}/' + DAY1 + '/' + DAY3 - print(f'>>> {path}') response = with_client.get(path, headers=auth_headers) assert response.status_code == 404, response.text data = response.json() diff --git a/backend/test/integration/test_auth.py b/backend/test/integration/test_auth.py index 088bc0d7..50084fb7 100644 --- a/backend/test/integration/test_auth.py +++ b/backend/test/integration/test_auth.py @@ -1,7 +1,6 @@ -import json -import os -import secrets +import os, json, secrets from datetime import timedelta +from uuid import uuid4 from unittest.mock import patch from appointment.dependencies import auth @@ -567,8 +566,7 @@ def test_disconnect(self, with_db, with_client, make_external_connections, make_ class TestGoogle: def test_disconnect(self, with_db, with_client, make_external_connections, make_google_calendar): """Ensure we remove the external google connection and any related calendars""" - username = 'username' - type_id = json.dumps(['url', username]) + type_id = str(uuid4()) ec = make_external_connections(TEST_USER_ID, type=models.ExternalConnectionType.google, type_id=type_id) calendar = make_google_calendar(subscriber_id=TEST_USER_ID) diff --git a/backend/test/integration/test_general.py b/backend/test/integration/test_general.py index 97b23015..71e13e08 100644 --- a/backend/test/integration/test_general.py +++ b/backend/test/integration/test_general.py @@ -1,4 +1,4 @@ -import os +import os, pytest from defines import DAY1, DAY5, auth_headers @@ -29,76 +29,51 @@ def test_health_for_locale(self, with_client): assert response.status_code == 200 assert response.json() == 'Zustand in Ordnung' - def test_access_without_authentication_token(self, with_client): - # response = client.get("/login") - # assert response.status_code == 401 - response = with_client.get('/me') - assert response.status_code == 401 - response = with_client.put('/me') - assert response.status_code == 401 - response = with_client.get('/me/calendars') - assert response.status_code == 401 - response = with_client.get('/me/appointments') - assert response.status_code == 401 - response = with_client.get('/me/signature') - assert response.status_code == 401 - response = with_client.post('/me/signature') - assert response.status_code == 401 - response = with_client.post('/cal') - assert response.status_code == 401 - response = with_client.get('/cal/1') - assert response.status_code == 401 - response = with_client.put('/cal/1') - assert response.status_code == 401 - response = with_client.post('/cal/1/connect') - assert response.status_code == 401 - response = with_client.delete('/cal/1') - assert response.status_code == 401 - response = with_client.post('/caldav/auth') - assert response.status_code == 401 - response = with_client.post('/caldav/disconnect') - assert response.status_code == 401 - response = with_client.post('/rmt/calendars') - assert response.status_code == 401 - response = with_client.get('/rmt/cal/1/' + DAY1 + '/' + DAY5) - assert response.status_code == 401 - response = with_client.post('/rmt/sync') - assert response.status_code == 401 - response = with_client.get('/account/available-emails') - assert response.status_code == 401 - response = with_client.get('/account/download') - assert response.status_code == 401 - response = with_client.get('/account/external-connections/') - assert response.status_code == 401 - response = with_client.delete('/account/delete') - assert response.status_code == 401 - response = with_client.get('/google/auth') - assert response.status_code == 401 - response = with_client.post('/google/disconnect') - assert response.status_code == 401 - response = with_client.post('/schedule') - assert response.status_code == 401 - response = with_client.get('/schedule') - assert response.status_code == 401 - response = with_client.get('/schedule/0') - assert response.status_code == 401 - response = with_client.put('/schedule/0') - assert response.status_code == 401 - response = with_client.get('/invite') - assert response.status_code == 401 - response = with_client.post('/invite/generate/1') - assert response.status_code == 401 - response = with_client.put('/invite/revoke/1') - assert response.status_code == 401 - response = with_client.get('/subscriber') - assert response.status_code == 401 - response = with_client.put('/subscriber/enable/someemail@email.com') - assert response.status_code == 401 - response = with_client.put('/subscriber/disable/someemail@email.com') - assert response.status_code == 401 - response = with_client.post('/subscriber/setup') - assert response.status_code == 401 - response = with_client.post('/waiting-list/invite') + @pytest.mark.parametrize('api_method, api_route', [ + ('get', '/me'), + ('put', '/me'), + ('get', '/me/calendars'), + ('get', '/me/appointments'), + ('get', '/me/signature'), + ('post', '/me/signature'), + ('post', '/cal'), + ('get', '/cal/1'), + ('put', '/cal/1'), + ('post', '/cal/1/connect'), + ('delete', '/cal/1'), + ('post', '/caldav/auth'), + ('post', '/caldav/disconnect'), + ('post', '/rmt/calendars'), + ('get', '/rmt/cal/1/' + DAY1 + '/' + DAY5), + ('post', '/rmt/sync'), + ('get', '/account/available-emails'), + ('get', '/account/download'), + ('get', '/account/external-connections/'), + ('delete', '/account/delete'), + ('get', '/google/auth'), + ('post', '/google/disconnect'), + ('post', '/schedule'), + ('get', '/schedule'), + ('get', '/schedule/0'), + ('put', '/schedule/0'), + ('get', '/invite'), + ('post', '/invite/generate/1'), + ('put', '/invite/revoke/1'), + ('get', '/subscriber'), + ('put', '/subscriber/enable/someemail@email.com'), + ('put', '/subscriber/disable/someemail@email.com'), + ('post', '/subscriber/setup'), + ('post', '/waiting-list/invite'), + ]) + def test_access_without_authentication_token(self, with_client, api_method, api_route): + if api_method == 'post': + response = with_client.post(f'{api_route}') + elif api_method == 'get': + response = with_client.get(f'{api_route}') + elif api_method == 'put': + response = with_client.put(f'{api_route}') + else: + response = with_client.delete(f'{api_route}') assert response.status_code == 401 def test_send_feedback(self, with_client): diff --git a/backend/test/integration/test_invite.py b/backend/test/integration/test_invite.py index f1b39966..6d6c0747 100644 --- a/backend/test/integration/test_invite.py +++ b/backend/test/integration/test_invite.py @@ -5,6 +5,8 @@ from appointment.database.models import InviteStatus class TestInvite: + today = today = datetime.today().date() + def test_send_invite_email_requires_admin(self, with_db, with_client): """Ensures send_invite_email requires an admin user""" @@ -109,12 +111,13 @@ def test_get_all_invites(self, with_db, with_client, make_invite): assert response.status_code == 200, response.text invite_list = response.json() assert len(invite_list) == 2 - today = datetime.today().strftime('%Y-%m-%d') + assert invite_list[0]['code'] != invite_list[1]['code'] + for next_invite in invite_list: assert next_invite['owner_id'] == TEST_USER_ID - assert today in next_invite['time_created'] assert next_invite['code'] is not None - assert invite_list[0]['code'] != invite_list[1]['code'] + date_created = datetime.fromisoformat(next_invite['time_created']).date() + assert date_created == self.today def test_generate_invites(self, with_client): """Ensures we can generate new invites""" @@ -125,11 +128,12 @@ def test_generate_invites(self, with_client): assert response.status_code == 200, response.text invite_list = response.json() assert len(invite_list) == 5 - today = datetime.today().strftime('%Y-%m-%d') + for next_invite in invite_list: - assert today in next_invite['time_created'] assert next_invite['status'] == InviteStatus.active.value assert next_invite['code'] is not None + date_created = datetime.fromisoformat(next_invite['time_created']).date() + assert date_created == self.today response = with_client.get( '/invite', diff --git a/backend/test/integration/test_subscriber.py b/backend/test/integration/test_subscriber.py index 77c440b2..c71a372f 100644 --- a/backend/test/integration/test_subscriber.py +++ b/backend/test/integration/test_subscriber.py @@ -91,8 +91,10 @@ def test_disable_enable_subscriber(self, with_client, make_basic_subscriber): data = response.json() subscriber_ret = data[len(data) -1] assert subscriber_ret['time_deleted'] is not None - today = datetime.today().strftime('%Y-%m-%d') - assert today in subscriber_ret['time_deleted'] + + today = today = datetime.today().date() + date_deleted = datetime.fromisoformat(subscriber_ret['time_deleted']).date() + assert date_deleted == today # attempt to disable same subscriber again, expect fail response = with_client.put(