From f51a7ed336efdccec7b0d44caa5d381c60e0f6de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominic=20Le=CC=81tourneau?= Date: Wed, 11 Dec 2024 16:48:01 -0500 Subject: [PATCH] Refs #257, added with_urls --- .../service/ServiceQueryTestsInvitations.py | 169 ++++++++++------- .../API/user/UserQueryTestsInvitations.py | 170 +++++++++++------- .../test_ServiceQueryTestsInvitations.py | 38 +++- .../user/test_UserQueryTestsInvitations.py | 33 +++- 4 files changed, 272 insertions(+), 138 deletions(-) diff --git a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryTestsInvitations.py b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryTestsInvitations.py index 34ac52a1..d08a3a86 100644 --- a/teraserver/python/modules/FlaskModule/API/service/ServiceQueryTestsInvitations.py +++ b/teraserver/python/modules/FlaskModule/API/service/ServiceQueryTestsInvitations.py @@ -20,6 +20,7 @@ from opentera.db.models.TeraParticipant import TeraParticipant from opentera.db.models.TeraDevice import TeraDevice from opentera.db.models.TeraProject import TeraProject +from opentera.db.models.TeraService import TeraService # Parser definition(s) @@ -77,6 +78,7 @@ # Additional parameters get_parser.add_argument('with_uuids', type=bool, help="Include UUIDs in results", default=False) +get_parser.add_argument('with_urls', type=bool, help="Include URLs in results", default=False) post_parser = api.parser() @@ -109,6 +111,14 @@ def __init__(self, _api, *args, **kwargs): self.module = kwargs.get('flaskModule', None) self.test = kwargs.get('test', False) + self.server_hostname = self.module.config.server_config['hostname'] + self.server_port = self.module.config.server_config['port'] + if 'X_EXTERNALSERVER' in request.headers: + self.server_hostname = request.headers['X_EXTERNALSERVER'] + + if 'X_EXTERNALPORT' in request.headers: + self.server_port = request.headers['X_EXTERNALPORT'] + @api.doc(description='Get tests invitations information.', responses={200: 'Success - returns list of invitations', 400: 'Required parameter is missing', @@ -144,79 +154,84 @@ def get(self): # No arguments means we return all accessible invitations - if all(args[arg] is None or arg == 'with_uuids' for arg in args): + if all(args[arg] is None or arg in ['with_uuids', 'with_urls'] for arg in args): for invitation in accessible_invitations: invitations.append(invitation.to_json()) - return self._insert_uuids_to_invitations(invitations) if args['with_uuids'] else invitations - - # Go through all args and get the requested information - if args['id_test_invitation'] is not None: - for invitation in TeraTestInvitation.query.filter( - TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids)).filter_by( - id_test_invitation=args['id_test_invitation']).all(): - invitations.append(invitation.to_json()) - if args['test_invitation_key'] is not None: - for invitation in TeraTestInvitation.query.filter( - TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids)).filter_by( - test_invitation_key=args['test_invitation_key']).all(): - invitations.append(invitation.to_json()) - if args['user_uuid'] is not None: - user : TeraUser = TeraUser.get_user_by_uuid(args['user_uuid']) - if user: - args['id_user'] = user.id_user - if args['id_user'] is not None: - for invitation in TeraTestInvitation.query.filter(and_( - TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), - TeraTestInvitation.id_user == args['id_user'])).all(): - invitations.append(invitation.to_json()) - if args['participant_uuid'] is not None: - participant : TeraParticipant = TeraParticipant.get_participant_by_uuid(args['participant_uuid']) - if participant: - args['id_participant'] = participant.id_participant - if args['id_participant'] is not None: - for invitation in TeraTestInvitation.query.filter(and_( - TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), - TeraTestInvitation.id_participant == args['id_participant'])).all(): - invitations.append(invitation.to_json()) - if args['device_uuid'] is not None: - device : TeraDevice = TeraDevice.get_device_by_uuid(args['device_uuid']) - if device: - args['id_device'] = device.id_device - if args['id_device'] is not None: - for invitation in TeraTestInvitation.query.filter(and_( - TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), - TeraTestInvitation.id_device == args['id_device'])).all(): - invitations.append(invitation.to_json()) - if args['session_uuid'] is not None: - session : TeraSession = TeraSession.get_session_by_uuid(args['session_uuid']) - if session: - args['id_session'] = session.id_session - if args['id_session'] is not None: - for invitation in TeraTestInvitation.query.filter(and_( - TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), - TeraTestInvitation.id_session == args['id_session'])).all(): - invitations.append(invitation.to_json()) - if args['test_type_uuid'] is not None: - test_type : TeraTestType = TeraTestType.get_test_type_by_uuid(args['test_type_uuid']) - if test_type: - args['id_test_type'] = test_type.id_test_type - if args['id_test_type'] is not None: - for invitation in TeraTestInvitation.query.filter(and_( - TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), - TeraTestInvitation.id_test_type == args['id_test_type'])).all(): - invitations.append(invitation.to_json()) - if args['id_project'] is not None: - project : TeraProject = TeraProject.get_project_by_id(args['id_project']) - if project and project.id_project in service_access.get_accessible_projects_ids(): - for invitation in TeraTestInvitation.query.join(TeraParticipant, - TeraParticipant.id_participant == TeraTestInvitation.id_participant).filter( - TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), - TeraParticipant.id_project == project.id_project).all(): + else: + # Go through all args and get the requested information + if args['id_test_invitation'] is not None: + for invitation in TeraTestInvitation.query.filter( + TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids)).filter_by( + id_test_invitation=args['id_test_invitation']).all(): + invitations.append(invitation.to_json()) + if args['test_invitation_key'] is not None: + for invitation in TeraTestInvitation.query.filter( + TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids)).filter_by( + test_invitation_key=args['test_invitation_key']).all(): + invitations.append(invitation.to_json()) + if args['user_uuid'] is not None: + user : TeraUser = TeraUser.get_user_by_uuid(args['user_uuid']) + if user: + args['id_user'] = user.id_user + if args['id_user'] is not None: + for invitation in TeraTestInvitation.query.filter(and_( + TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), + TeraTestInvitation.id_user == args['id_user'])).all(): + invitations.append(invitation.to_json()) + if args['participant_uuid'] is not None: + participant : TeraParticipant = TeraParticipant.get_participant_by_uuid(args['participant_uuid']) + if participant: + args['id_participant'] = participant.id_participant + if args['id_participant'] is not None: + for invitation in TeraTestInvitation.query.filter(and_( + TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), + TeraTestInvitation.id_participant == args['id_participant'])).all(): + invitations.append(invitation.to_json()) + if args['device_uuid'] is not None: + device : TeraDevice = TeraDevice.get_device_by_uuid(args['device_uuid']) + if device: + args['id_device'] = device.id_device + if args['id_device'] is not None: + for invitation in TeraTestInvitation.query.filter(and_( + TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), + TeraTestInvitation.id_device == args['id_device'])).all(): invitations.append(invitation.to_json()) + if args['session_uuid'] is not None: + session : TeraSession = TeraSession.get_session_by_uuid(args['session_uuid']) + if session: + args['id_session'] = session.id_session + if args['id_session'] is not None: + for invitation in TeraTestInvitation.query.filter(and_( + TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), + TeraTestInvitation.id_session == args['id_session'])).all(): + invitations.append(invitation.to_json()) + if args['test_type_uuid'] is not None: + test_type : TeraTestType = TeraTestType.get_test_type_by_uuid(args['test_type_uuid']) + if test_type: + args['id_test_type'] = test_type.id_test_type + if args['id_test_type'] is not None: + for invitation in TeraTestInvitation.query.filter(and_( + TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), + TeraTestInvitation.id_test_type == args['id_test_type'])).all(): + invitations.append(invitation.to_json()) + if args['id_project'] is not None: + project : TeraProject = TeraProject.get_project_by_id(args['id_project']) + if project and project.id_project in service_access.get_accessible_projects_ids(): + for invitation in TeraTestInvitation.query.join(TeraParticipant, + TeraParticipant.id_participant == TeraTestInvitation.id_participant).filter( + TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), + TeraParticipant.id_project == project.id_project).all(): + + invitations.append(invitation.to_json()) - # Default without UUIDs - return self._insert_uuids_to_invitations(invitations) if args['with_uuids'] else invitations + if args['with_uuids']: + invitations = self._insert_uuids_to_invitations(invitations) + + if args['with_urls']: + invitations = self._insert_urls_to_invitations(invitations) + + return invitations @api.doc(description='Update/Create test invitation.', responses={501: 'Unable to update test from here - use service!'}) @@ -371,3 +386,21 @@ def _insert_uuids_to_invitations(self, invitations : list[dict]) -> list[dict]: invitation['test_type_uuid'] = test_type.test_type_uuid return invitations + + def _insert_urls_to_invitations(self, invitations : list[dict]) -> list[dict]: + """ + Add URLs to invitations + """ + for invitation in invitations: + test_type : TeraTestType = TeraTestType.get_test_type_by_id(invitation['id_test_type']) + + urls = test_type.get_service_urls(self.server_hostname, self.server_port) + + if test_type and urls['test_type_web_url'] is not None: + service : TeraService = TeraService.get_service_by_id(test_type.id_service) + if service: + invitation['test_invitation_url'] = f"{urls['test_type_web_url']}&invitation_key={invitation['test_invitation_key']}" + else: + invitation['test_invitation_url'] = None + + return invitations diff --git a/teraserver/python/modules/FlaskModule/API/user/UserQueryTestsInvitations.py b/teraserver/python/modules/FlaskModule/API/user/UserQueryTestsInvitations.py index ba37c10a..bbb5ad55 100644 --- a/teraserver/python/modules/FlaskModule/API/user/UserQueryTestsInvitations.py +++ b/teraserver/python/modules/FlaskModule/API/user/UserQueryTestsInvitations.py @@ -20,6 +20,8 @@ from opentera.db.models.TeraParticipant import TeraParticipant from opentera.db.models.TeraDevice import TeraDevice from opentera.db.models.TeraProject import TeraProject +from opentera.db.models.TeraService import TeraService + # Parser definition(s) # GET @@ -76,6 +78,7 @@ # Additional parameters get_parser.add_argument('with_uuids', type=bool, help="Include UUIDs in results", default=False) +get_parser.add_argument('with_urls', type=bool, help="Include URLs in results", default=False) post_parser = api.parser() @@ -111,6 +114,15 @@ def __init__(self, _api, *args, **kwargs): self.module = kwargs.get('flaskModule', None) self.test = kwargs.get('test', False) + self.server_hostname = self.module.config.server_config['hostname'] + self.server_port = self.module.config.server_config['port'] + if 'X_EXTERNALSERVER' in request.headers: + self.server_hostname = request.headers['X_EXTERNALSERVER'] + + if 'X_EXTERNALPORT' in request.headers: + self.server_port = request.headers['X_EXTERNALPORT'] + + @api.doc(description='Get tests invitations information.', responses={200: 'Success - returns list of invitations', 400: 'Required parameter is missing', @@ -145,79 +157,83 @@ def get(self): invitations : list[dict] = [] # No arguments means we return all accessible invitations - if all(args[arg] is None or arg == 'with_uuids' for arg in args): + if all(args[arg] is None or arg in ['with_uuids', 'with_urls'] for arg in args): for invitation in accessible_invitations: invitations.append(invitation.to_json()) - return self._insert_uuids_to_invitations(invitations) if args['with_uuids'] else invitations + else: + # Go through all args and get the requested information + if args['id_test_invitation'] is not None: + for invitation in TeraTestInvitation.query.filter( + TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids)).filter_by( + id_test_invitation=args['id_test_invitation']).all(): + invitations.append(invitation.to_json()) + if args['test_invitation_key'] is not None: + for invitation in TeraTestInvitation.query.filter( + TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids)).filter_by( + test_invitation_key=args['test_invitation_key']).all(): + invitations.append(invitation.to_json()) + if args['user_uuid'] is not None: + user : TeraUser = TeraUser.get_user_by_uuid(args['user_uuid']) + if user: + args['id_user'] = user.id_user + if args['id_user'] is not None: + for invitation in TeraTestInvitation.query.filter(and_( + TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), + TeraTestInvitation.id_user == args['id_user'])).all(): + invitations.append(invitation.to_json()) + if args['participant_uuid'] is not None: + participant : TeraParticipant = TeraParticipant.get_participant_by_uuid(args['participant_uuid']) + if participant: + args['id_participant'] = participant.id_participant + if args['id_participant'] is not None: + for invitation in TeraTestInvitation.query.filter(and_( + TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), + TeraTestInvitation.id_participant == args['id_participant'])).all(): + invitations.append(invitation.to_json()) + if args['device_uuid'] is not None: + device : TeraDevice = TeraDevice.get_device_by_uuid(args['device_uuid']) + if device: + args['id_device'] = device.id_device + if args['id_device'] is not None: + for invitation in TeraTestInvitation.query.filter(and_( + TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), + TeraTestInvitation.id_device == args['id_device'])).all(): + invitations.append(invitation.to_json()) + if args['session_uuid'] is not None: + session : TeraSession = TeraSession.get_session_by_uuid(args['session_uuid']) + if session: + args['id_session'] = session.id_session + if args['id_session'] is not None: + for invitation in TeraTestInvitation.query.filter(and_( + TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), + TeraTestInvitation.id_session == args['id_session'])).all(): + invitations.append(invitation.to_json()) + if args['test_type_uuid'] is not None: + test_type : TeraTestType = TeraTestType.get_test_type_by_uuid(args['test_type_uuid']) + if test_type: + args['id_test_type'] = test_type.id_test_type + if args['id_test_type'] is not None: + for invitation in TeraTestInvitation.query.filter(and_( + TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), + TeraTestInvitation.id_test_type == args['id_test_type'])).all(): + invitations.append(invitation.to_json()) + if args['id_project'] is not None: + project : TeraProject = TeraProject.get_project_by_id(args['id_project']) + if project and project.id_project in user_access.get_accessible_projects_ids(): + for invitation in TeraTestInvitation.query.join(TeraParticipant, + TeraParticipant.id_participant == TeraTestInvitation.id_participant).filter( + TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), + TeraParticipant.id_project == project.id_project).all(): - # Go through all args and get the requested information - if args['id_test_invitation'] is not None: - for invitation in TeraTestInvitation.query.filter( - TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids)).filter_by( - id_test_invitation=args['id_test_invitation']).all(): - invitations.append(invitation.to_json()) - if args['test_invitation_key'] is not None: - for invitation in TeraTestInvitation.query.filter( - TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids)).filter_by( - test_invitation_key=args['test_invitation_key']).all(): - invitations.append(invitation.to_json()) - if args['user_uuid'] is not None: - user : TeraUser = TeraUser.get_user_by_uuid(args['user_uuid']) - if user: - args['id_user'] = user.id_user - if args['id_user'] is not None: - for invitation in TeraTestInvitation.query.filter(and_( - TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), - TeraTestInvitation.id_user == args['id_user'])).all(): - invitations.append(invitation.to_json()) - if args['participant_uuid'] is not None: - participant : TeraParticipant = TeraParticipant.get_participant_by_uuid(args['participant_uuid']) - if participant: - args['id_participant'] = participant.id_participant - if args['id_participant'] is not None: - for invitation in TeraTestInvitation.query.filter(and_( - TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), - TeraTestInvitation.id_participant == args['id_participant'])).all(): - invitations.append(invitation.to_json()) - if args['device_uuid'] is not None: - device : TeraDevice = TeraDevice.get_device_by_uuid(args['device_uuid']) - if device: - args['id_device'] = device.id_device - if args['id_device'] is not None: - for invitation in TeraTestInvitation.query.filter(and_( - TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), - TeraTestInvitation.id_device == args['id_device'])).all(): - invitations.append(invitation.to_json()) - if args['session_uuid'] is not None: - session : TeraSession = TeraSession.get_session_by_uuid(args['session_uuid']) - if session: - args['id_session'] = session.id_session - if args['id_session'] is not None: - for invitation in TeraTestInvitation.query.filter(and_( - TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), - TeraTestInvitation.id_session == args['id_session'])).all(): - invitations.append(invitation.to_json()) - if args['test_type_uuid'] is not None: - test_type : TeraTestType = TeraTestType.get_test_type_by_uuid(args['test_type_uuid']) - if test_type: - args['id_test_type'] = test_type.id_test_type - if args['id_test_type'] is not None: - for invitation in TeraTestInvitation.query.filter(and_( - TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), - TeraTestInvitation.id_test_type == args['id_test_type'])).all(): - invitations.append(invitation.to_json()) - if args['id_project'] is not None: - project : TeraProject = TeraProject.get_project_by_id(args['id_project']) - if project and project.id_project in user_access.get_accessible_projects_ids(): - for invitation in TeraTestInvitation.query.join(TeraParticipant, - TeraParticipant.id_participant == TeraTestInvitation.id_participant).filter( - TeraTestInvitation.id_test_invitation.in_(accessible_invitations_ids), - TeraParticipant.id_project == project.id_project).all(): + invitations.append(invitation.to_json()) - invitations.append(invitation.to_json()) + if args['with_uuids']: + invitations = self._insert_uuids_to_invitations(invitations) + + if args['with_urls']: + invitations = self._insert_urls_to_invitations(invitations) - # Default without UUIDs - return self._insert_uuids_to_invitations(invitations) if args['with_uuids'] else invitations + return invitations @api.doc(description='Update/Create test invitation.', responses={501: 'Unable to update test from here - use service!'}) @@ -371,3 +387,21 @@ def _insert_uuids_to_invitations(self, invitations : list[dict]) -> list[dict]: invitation['test_type_uuid'] = test_type.test_type_uuid return invitations + + def _insert_urls_to_invitations(self, invitations : list[dict]) -> list[dict]: + """ + Add URLs to invitations + """ + for invitation in invitations: + test_type : TeraTestType = TeraTestType.get_test_type_by_id(invitation['id_test_type']) + + urls = test_type.get_service_urls(self.server_hostname, self.server_port) + + if test_type and urls['test_type_web_url'] is not None: + service : TeraService = TeraService.get_service_by_id(test_type.id_service) + if service: + invitation['test_invitation_url'] = f"{urls['test_type_web_url']}&invitation_key={invitation['test_invitation_key']}" + else: + invitation['test_invitation_url'] = None + + return invitations diff --git a/teraserver/python/tests/modules/FlaskModule/API/service/test_ServiceQueryTestsInvitations.py b/teraserver/python/tests/modules/FlaskModule/API/service/test_ServiceQueryTestsInvitations.py index 077d88de..b016c87f 100644 --- a/teraserver/python/tests/modules/FlaskModule/API/service/test_ServiceQueryTestsInvitations.py +++ b/teraserver/python/tests/modules/FlaskModule/API/service/test_ServiceQueryTestsInvitations.py @@ -132,7 +132,31 @@ def test_get_query_no_params_with_token_returns_all_accessible_invitations_with_ TeraTestType.delete(test_type_accessible.id_test_type) TeraTestType.delete(test_type_not_accessible.id_test_type) + def test_get_query_no_params_with_token_returns_all_accessible_invitations_with_urls(self): + """ + Test that an admin can access all invitations + """ + with self._flask_app.app_context(): + create_count = 10 + # Create Test type for service + test_type_accessible = self._create_test_type_for_service(self.id_service) + test_type_not_accessible = self._create_test_type_for_service(1) + + # Create invitations + self._create_invitations(create_count, id_test_type=test_type_accessible.id_test_type, id_user=1) + self._create_invitations(create_count, id_test_type=test_type_not_accessible.id_test_type, id_user=1) + + # Service should access only invitations of its test type + response = self._get_with_service_token_auth(self.test_client, token=self.service_token, params={'with_urls': True}) + self.assertEqual(200, response.status_code) + self.assertEqual(create_count, len(response.json)) + + for json_invitation in response.json: + self._validate_json(json_invitation, with_urls=True) + + TeraTestType.delete(test_type_accessible.id_test_type) + TeraTestType.delete(test_type_not_accessible.id_test_type) def test_get_query_with_id_test_invitation_or_key_with_service_token(self): """ @@ -635,6 +659,13 @@ def _create_invitations(self, count: int, invitations: list[TeraTestInvitation] = [] + + # Make sure test type has all required fields + test_type: TeraTestType = TeraTestType.get_test_type_by_id(id_test_type) + TeraTestType.update(test_type.id_test_type, {'test_type_has_json_format': True, + 'test_type_has_web_editor': True, + 'test_type_has_web_format': True}) + # Make sure we have only one of id_user, id_participant, id_device if sum(x is not None for x in [id_user, id_participant, id_device]) != 1: raise ValueError('Only one of id_user, id_participant, id_device must be set') @@ -662,7 +693,7 @@ def _delete_all_invitations(self): for invitation in invitations: TeraTestInvitation.delete(invitation.id_test_invitation) - def _validate_json(self, json: dict, with_uuids: bool = False): + def _validate_json(self, json: dict, with_uuids: bool = False, with_urls: bool = False): """ Validate a json """ @@ -691,3 +722,8 @@ def _validate_json(self, json: dict, with_uuids: bool = False): self.assertTrue('device_uuid' not in json) self.assertTrue('session_uuid' not in json) self.assertTrue('test_type_uuid' not in json) + + if with_urls: + self.assertTrue('test_invitation_url' in json) + else: + self.assertFalse('test_invitation_url' in json) diff --git a/teraserver/python/tests/modules/FlaskModule/API/user/test_UserQueryTestsInvitations.py b/teraserver/python/tests/modules/FlaskModule/API/user/test_UserQueryTestsInvitations.py index bb82800c..031ecb64 100644 --- a/teraserver/python/tests/modules/FlaskModule/API/user/test_UserQueryTestsInvitations.py +++ b/teraserver/python/tests/modules/FlaskModule/API/user/test_UserQueryTestsInvitations.py @@ -142,6 +142,27 @@ def test_get_query_no_params_as_admin_with_uuids_returns_all_accessible_invitati self.assertEqual(200, response.status_code) self.assertEqual(0, len(response.json)) + def test_get_query_no_params_as_admin_with_urls_returns_all_accessible_invitations(self): + """ + Test that an admin can access all invitations + """ + with self._flask_app.app_context(): + create_count = 10 + # Create 10 invitations + self._create_invitations(create_count, id_test_type=1, id_user=1) + + # Admin should access all invitations + response = self._get_with_user_http_auth(self.test_client, username='admin', password='admin', params={'with_urls': True}) + self.assertEqual(200, response.status_code) + self.assertEqual(create_count, len(response.json)) + for invitation in response.json: + self._validate_json(invitation, with_urls=True) + + # Verify that invitations are not accessible to no access user + response = self._get_with_user_http_auth(self.test_client, username='user4', password='user4') + self.assertEqual(200, response.status_code) + self.assertEqual(0, len(response.json)) + def test_get_query_with_id_test_invitation_or_key_as_admin(self): """ Test that an admin can access an invitation with id_test_invitation or test_invitation_key @@ -646,6 +667,11 @@ def _create_invitations(self, count: int, """ Create a number of invitations. """ + # Make sure test type has all required fields + test_type: TeraTestType = TeraTestType.get_test_type_by_id(id_test_type) + TeraTestType.update(test_type.id_test_type, {'test_type_has_json_format': True, + 'test_type_has_web_editor': True, + 'test_type_has_web_format': True}) invitations: list[TeraTestInvitation] = [] @@ -676,7 +702,7 @@ def _delete_all_invitations(self): for invitation in invitations: TeraTestInvitation.delete(invitation.id_test_invitation) - def _validate_json(self, json: dict, with_uuids: bool = False): + def _validate_json(self, json: dict, with_uuids: bool = False, with_urls: bool = False): """ Validate a json """ @@ -705,3 +731,8 @@ def _validate_json(self, json: dict, with_uuids: bool = False): self.assertTrue('device_uuid' not in json) self.assertTrue('session_uuid' not in json) self.assertTrue('test_type_uuid' not in json) + + if with_urls: + self.assertTrue('test_invitation_url' in json) + else: + self.assertFalse('test_invitation_url' in json)