Skip to content

support custom template path #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Nov 4, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
unit test custom templates path
  • Loading branch information
erichulburd committed Nov 3, 2020
commit 6b12c9c59f6f974fcd08b45a39392f98e9d5cf3a
24 changes: 24 additions & 0 deletions tests/test___init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,27 @@ def test__get_errors(mocker):
project = Project(openapi=openapi)

assert project._get_errors() == [1, 2, 3]


def test__custom_templates(mocker):
from openapi_python_client import GeneratorData, Project
from openapi_python_client.parser.openapi import EndpointCollection, Schemas

openapi = mocker.MagicMock(
autospec=GeneratorData,
title="My Test API",
endpoint_collections_by_tag={
"default": mocker.MagicMock(autospec=EndpointCollection, parse_errors=[1]),
"other": mocker.MagicMock(autospec=EndpointCollection, parse_errors=[2]),
},
schemas=mocker.MagicMock(autospec=Schemas, errors=[3]),
)

project = Project(openapi=openapi)
assert isinstance(project.env.loader, jinja2.PackageLoader)

project = Project(openapi=openapi, custom_template_path='../end_to_end_tests/test_custom_templates')
assert isinstance(project.env.loader, jinja2.ChoiceLoader)
assert len(project.env.loader.loaders) == 2
assert isinstance(project.env.loader.loaders[0], jinja2.ChoiceLoader)
assert isinstance(project.env.loader.loaders[1], jinja2.PackageLoader)