-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #79. Added Service API for test types and tests
- Loading branch information
Showing
11 changed files
with
714 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
teraserver/python/modules/FlaskModule/API/service/ServiceQueryTestTypes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from flask_restx import Resource | ||
from flask_babel import gettext | ||
from modules.LoginModule.LoginModule import LoginModule, current_service | ||
from modules.FlaskModule.FlaskModule import service_api_ns as api | ||
from modules.DatabaseModule.DBManager import DBManager | ||
from opentera.db.models.TeraTestTypeProject import TeraTestTypeProject | ||
from opentera.db.models.TeraTestTypeSite import TeraTestTypeSite | ||
from opentera.db.models.TeraParticipant import TeraParticipant | ||
|
||
|
||
# Parser definition(s) | ||
get_parser = api.parser() | ||
get_parser.add_argument('id_site', type=int, help='ID of the site to query test types for') | ||
get_parser.add_argument('id_project', type=int, help='ID of the project to query test types for') | ||
get_parser.add_argument('id_participant', type=int, help='ID of the participant to query types for') | ||
|
||
|
||
class ServiceQueryTestTypes(Resource): | ||
|
||
def __init__(self, _api, *args, **kwargs): | ||
Resource.__init__(self, _api, *args, **kwargs) | ||
self.module = kwargs.get('flaskModule', None) | ||
self.test = kwargs.get('test', False) | ||
|
||
@LoginModule.service_token_or_certificate_required | ||
@api.expect(get_parser) | ||
@api.doc(description='Return test types information for the current service', | ||
responses={200: 'Success', | ||
500: 'Required parameter is missing', | ||
501: 'Not implemented.', | ||
403: 'Logged user doesn\'t have permission to access the requested data'}) | ||
def get(self): | ||
parser = get_parser | ||
args = parser.parse_args(strict=True) | ||
|
||
service_access = DBManager.serviceAccess(current_service) | ||
|
||
test_types = [] | ||
if args['id_site']: | ||
if args['id_site'] in service_access.get_accessibles_sites_ids(): | ||
test_types = [tt.test_type_site_test_type for tt in | ||
TeraTestTypeSite.get_tests_types_for_site(args['id_site'])] | ||
elif args['id_project']: | ||
if args['id_project'] in service_access.get_accessible_projects_ids(): | ||
test_types = [tt.test_type_project_test_type for tt in | ||
TeraTestTypeProject.get_tests_types_for_project(args['id_project'])] | ||
elif args['id_participant']: | ||
if args['id_participant'] in service_access.get_accessible_participants_ids(): | ||
part_info = TeraParticipant.get_participant_by_id(args['id_participant']) | ||
test_types = [tt.test_type_project_test_type for tt in | ||
TeraTestTypeProject.get_tests_types_for_project(part_info.id_project)] | ||
else: | ||
test_types = service_access.get_accessible_tests_types() | ||
|
||
return [tt.to_json() for tt in test_types] |
Oops, something went wrong.