Skip to content

Commit

Permalink
Post-review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rwood-moz committed Jan 22, 2025
1 parent 7044267 commit be56f28
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 89 deletions.
6 changes: 3 additions & 3 deletions backend/test/integration/test_account.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import json, os
from uuid import uuid4
from appointment.database.models import ExternalConnectionType
from defines import auth_headers, TEST_USER_ID


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)
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 0 additions & 3 deletions backend/test/integration/test_appointment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand All @@ -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()
Expand Down
8 changes: 3 additions & 5 deletions backend/test/integration/test_auth.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

Expand Down
117 changes: 46 additions & 71 deletions backend/test/integration/test_general.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
import os, pytest
from defines import DAY1, DAY5, auth_headers


Expand Down Expand Up @@ -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/[email protected]')
assert response.status_code == 401
response = with_client.put('/subscriber/disable/[email protected]')
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/[email protected]'),
('put', '/subscriber/disable/[email protected]'),
('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):
Expand Down
14 changes: 9 additions & 5 deletions backend/test/integration/test_invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down Expand Up @@ -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"""
Expand All @@ -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',
Expand Down
6 changes: 4 additions & 2 deletions backend/test/integration/test_subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit be56f28

Please sign in to comment.