Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:KarrLab/datanator_rest_api
- Loading branch information
Showing
8 changed files
with
107 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from connexion.resolver import RestyResolver | ||
import re | ||
|
||
|
||
class AutoResolver(RestyResolver): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
def resolve_operation_id_using_rest_semantics(self, operation): | ||
""" | ||
Resolves the operationId using REST semantics | ||
:type operation: connexion.operations.AbstractOperation | ||
""" | ||
path_match = re.search( | ||
r'^/?(?P<resource_name>([\w\-](?<!/))*)(?P<trailing_slash>/*)(?P<extended_path>.*)$', operation.path | ||
) | ||
|
||
def get_controller_name(): | ||
|
||
name = self.default_module_name | ||
resource_name = path_match.group('resource_name') | ||
|
||
if resource_name: | ||
resource_controller_name = resource_name.replace('-', '_') | ||
name += '.' + resource_controller_name | ||
|
||
return name | ||
|
||
def get_path_name(): | ||
return path_match.group('extended_path').replace('/', '.') if path_match.group('extended_path') else '' | ||
|
||
def get_function_name(): | ||
method = operation.method | ||
|
||
return method.lower() | ||
|
||
return '{}.{}{}'.format(get_controller_name(), get_path_name(), get_function_name()) |
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 @@ | ||
from .AutoResolver import AutoResolver |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
flask >= 1.1.0 | ||
capturer # to capture standard output in tests | ||
mock # to mock python classes and methods | ||
swagger_tester #to confirm api responses meet specification | ||
prance #to parse api |
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 was deleted.
Oops, something went wrong.
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,40 @@ | ||
""" | ||
Test the implementation of the API | ||
:Author: Bilal Shaikh < bilalshaikh42@gmail.com > | ||
:Date: 2019-08-23 | ||
:Copyright: 2019, Karr Lab | ||
:License: MIT | ||
""" | ||
import connexion | ||
import unittest | ||
import datanator_rest_api.core as core | ||
from prance import BaseParser | ||
|
||
|
||
class ImplementationTestCase(unittest.TestCase): | ||
def setUp(self): | ||
|
||
self.AutoResolver = core.AutoResolver | ||
self.app = connexion.App(__name__) | ||
self.app.add_api('../../datanator_rest_api/spec/DatanatorAPI.yaml', resolver=self.AutoResolver( | ||
"datanator_rest_api.routes"), validate_responses=False) | ||
self.client = self.app.app.test_client() | ||
self.client.testing = True | ||
|
||
def test_1(self): | ||
response = self.client.get('/datanator/') | ||
assert(response.status_code == 200) | ||
|
||
|
||
class RoutesTestCase(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
cls.parser = BaseParser('./datanator_rest_api/spec/DatanatorAPI.yaml') | ||
cls.specification = cls.parser.specification | ||
cls.paths = cls.specification['paths'] | ||
cls.routes = cls.paths.keys() | ||
|
||
def test_routes(self): | ||
for route in self.routes: | ||
print(route) | ||
assert(True) |