Skip to content

Commit

Permalink
Remove redundant spec parsing (RedHatInsights#1041)
Browse files Browse the repository at this point in the history
TranslatingParser does parsing automatically on initialization. Calling it again manually is not only unnecessary, but also inefficient. Removed the call from the create_app function.
  • Loading branch information
Glutexo authored Nov 30, 2021
1 parent 1ebfeda commit 97d5319
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 0 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ def create_app(runtime_environment):
connexion_app = connexion.App("inventory", specification_dir="./swagger/", options=connexion_options)

parser = TranslatingParser(SPECIFICATION_FILE)
parser.parse()
for api_url in app_config.api_urls:
if api_url:
connexion_app.add_api(
Expand Down
24 changes: 24 additions & 0 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from api.host_query_db import params_to_order_by
from api.parsing import custom_fields_parser
from app import create_app
from app import SPECIFICATION_FILE
from app.auth.identity import from_auth_header
from app.auth.identity import from_bearer_token
from app.auth.identity import Identity
Expand Down Expand Up @@ -420,6 +421,29 @@ def test_config_is_assigned(self, config, get_engine):
self.assertEqual(config.return_value, app.config["INVENTORY_CONFIG"])


@patch("app.connexion.App")
@patch("app.db.get_engine")
class CreateAppConnexionAppInitTestCase(TestCase):
@patch("app.TranslatingParser")
def test_specification_is_provided(self, translating_parser, get_engine, app):
create_app(RuntimeEnvironment.TEST)

translating_parser.assert_called_once_with(SPECIFICATION_FILE)
assert "lazy" not in translating_parser.mock_calls[0].kwargs

app.return_value.add_api.assert_called_once()
args = app.return_value.add_api.mock_calls[0].args
assert len(args) == 1
assert args[0] is translating_parser.return_value.specification

def test_specification_is_parsed(self, get_engine, app):
create_app(RuntimeEnvironment.TEST)
app.return_value.add_api.assert_called_once()
args = app.return_value.add_api.mock_calls[0].args
assert len(args) == 1
assert args[0] is not None


class HostOrderHowTestCase(TestCase):
def test_asc(self):
column = Mock()
Expand Down

0 comments on commit 97d5319

Please sign in to comment.