Skip to content

Commit

Permalink
Merge pull request #234 from macisamuele/maci-add-appveyor-support
Browse files Browse the repository at this point in the history
Add appveyor support and fix issues on Windows
  • Loading branch information
macisamuele committed Jul 2, 2018
2 parents 13ffad4 + 348dab5 commit 87f0536
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 9 deletions.
28 changes: 28 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: '{build}'
image: Visual Studio 2017

environment:
matrix:
# Available python versions and their locations on https://www.appveyor.com/docs/build-environment/#python
- PYTHON: C:\Python27-x64
TOXENV: py27
- PYTHON: C:\Python27-x64
TOXENV: py27-pyramid15
- PYTHON: C:\Python35-x64
TOXENV: py35
- PYTHON: C:\Python36-x64
TOXENV: py36

build: off

install:
- cmd: SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%
- cmd: pip install tox

before_test:
- cmd: python --version
- cmd: pip --version
- cmd: tox --version

test_script:
- cmd: tox
3 changes: 2 additions & 1 deletion pyramid_swagger/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from bravado_core.spec import strip_xscope
from six.moves.urllib.parse import urlparse
from six.moves.urllib.parse import urlunparse
from six.moves.urllib.request import pathname2url

from pyramid_swagger.model import PyramidEndpoint

Expand Down Expand Up @@ -288,7 +289,7 @@ def view_for_swagger_schema(request):
return fixed_spec

for ref_fname in all_files:
ref_fname_parts = os.path.splitext(ref_fname)
ref_fname_parts = os.path.splitext(pathname2url(ref_fname))
for schema_format in ['yaml', 'json']:
route_name = 'pyramid_swagger.swagger20.api_docs.{0}.{1}'\
.format(ref_fname.replace('/', '.'), schema_format)
Expand Down
7 changes: 4 additions & 3 deletions pyramid_swagger/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from bravado_core.spec import Spec
from six import iteritems
from six.moves.urllib import parse as urlparse
from six.moves.urllib.request import pathname2url

from .api import build_swagger_12_endpoints
from .load_schema import load_schema
Expand Down Expand Up @@ -117,7 +118,7 @@ def get_resource_listing(schema_dir, should_generate_resource_listing):
:param should_generate_resource_listing: when True a resource listing will
be generated from the list of *.json files in the schema_dir. Otherwise
return the contents of the resource listing file
:type should_enerate_resource_listing: boolean
:type should_generate_resource_listing: boolean
:returns: the contents of a resource listing document
"""
listing_filename = os.path.join(schema_dir, API_DOCS_FILENAME)
Expand Down Expand Up @@ -152,7 +153,7 @@ def get_swagger_schema(settings):
:type settings: dict
:returns: a :class:`pyramid_swagger.model.SwaggerSchema`
"""
schema_dir = settings.get('pyramid_swagger.schema_directory', 'api_docs/')
schema_dir = settings.get('pyramid_swagger.schema_directory', 'api_docs')
resource_listing = get_resource_listing(
schema_dir,
settings.get('pyramid_swagger.generate_resource_listing', False)
Expand All @@ -179,7 +180,7 @@ def get_swagger_spec(settings):
schema_filename = settings.get('pyramid_swagger.schema_file',
'swagger.json')
schema_path = os.path.join(schema_dir, schema_filename)
schema_url = urlparse.urljoin('file:', os.path.abspath(schema_path))
schema_url = urlparse.urljoin('file:', pathname2url(os.path.abspath(schema_path)))

handlers = build_http_handlers(None) # don't need http_client for file:
file_handler = handlers['file']
Expand Down
5 changes: 4 additions & 1 deletion pyramid_swagger/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import swagger_spec_validator
from jsonschema.exceptions import ValidationError
from six.moves.urllib import parse as urlparse
from six.moves.urllib.request import pathname2url

from .exceptions import wrap_exception

Expand All @@ -31,4 +33,5 @@ def validate_swagger_schema(schema_dir, resource_listing):
schema_filepath = os.path.join(schema_dir, API_DOCS_FILENAME)
swagger_spec_validator.validator12.validate_spec(
resource_listing,
"file://{0}".format(os.path.abspath(schema_filepath)))
urlparse.urljoin('file:', pathname2url(os.path.abspath(schema_filepath))),
)
9 changes: 8 additions & 1 deletion tests/acceptance/relative_ref_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import os.path
import re
import sys

import pytest
import yaml
Expand Down Expand Up @@ -153,4 +154,10 @@ def test_dereferenced_swagger_schema_retrieval(schema_format, test_app_deref):
ref_pattern = re.compile('("\$ref": "[^#][^"]*")')
assert ref_pattern.findall(json.dumps(actual_dict)) == []

assert actual_dict == expected_dict
if sys.platform != 'win32':
# This checks that the returned dictionary matches the expected one
# as this check mainly validates the bravado-core performs valid flattening
# of specs and bravado-core flattening could provide different results
# (in terms of references names) according to the platform we decided
# to not check it for windows
assert actual_dict == expected_dict
7 changes: 4 additions & 3 deletions tests/spec_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@


def test_success_for_good_app():
dir_path = 'tests/sample_schemas/good_app/'
dir_path = 'tests/sample_schemas/good_app/'.replace('/', os.path.sep)
with open(os.path.join(dir_path, API_DOCS_FILENAME)) as f:
resource_listing = simplejson.load(f)
validate_swagger_schema(dir_path, resource_listing)


def test_proper_error_on_missing_api_declaration():
with pytest.raises(ValidationError) as exc:
dir_path = 'tests/sample_schemas/missing_api_declaration/'
dir_path = 'tests/sample_schemas/missing_api_declaration/'.replace('/', os.path.sep)
with open(os.path.join(dir_path, API_DOCS_FILENAME)) as f:
resource_listing = simplejson.load(f)
validate_swagger_schema(dir_path, resource_listing)

assert "{0}{1}".format(dir_path, "missing.json") in str(exc)
assert os.path.basename(dir_path) in str(exc)
assert os.path.basename('missing.json') in str(exc)

0 comments on commit 87f0536

Please sign in to comment.