Skip to content

Commit

Permalink
Add "optionals not required" build (#6047)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan P Kilby authored and carltongibson committed Jun 22, 2018
1 parent 7e0ad92 commit 1a17043
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ matrix:
- { python: "3.6", env: DJANGO=1.11 }
- { python: "3.6", env: DJANGO=2.0 }
- { python: "3.6", env: DJANGO=2.1 }
- { python: "3.6", env: TOXENV=base }
- { python: "2.7", env: TOXENV=lint }
- { python: "2.7", env: TOXENV=docs }

Expand Down
1 change: 1 addition & 0 deletions tests/test_encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def test_encode_uuid(self):
unique_id = uuid4()
assert self.encoder.default(unique_id) == str(unique_id)

@pytest.mark.skipif(not coreapi, reason='coreapi is not installed')
def test_encode_coreapi_raises_error(self):
"""
Tests encoding a coreapi objects raises proper error
Expand Down
2 changes: 2 additions & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.utils.six.moves import reload_module

from rest_framework import filters, generics, serializers
from rest_framework.compat import coreschema
from rest_framework.test import APIRequestFactory

factory = APIRequestFactory()
Expand All @@ -28,6 +29,7 @@ def test_filter_queryset_raises_error(self):
with pytest.raises(NotImplementedError):
self.filter_backend.filter_queryset(None, None, None)

@pytest.mark.skipif(not coreschema, reason='coreschema is not installed')
def test_get_schema_fields_checks_for_coreapi(self):
filters.coreapi = None
with pytest.raises(AssertionError):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ def get(self, request):
self.assertContains(response, '<tr><th>Iteritems</th><td>a string</td></tr>', html=True)


@pytest.mark.skipif(not coreapi, reason='coreapi is not installed')
class TestDocumentationRenderer(TestCase):

def test_document_with_link_named_data(self):
Expand Down Expand Up @@ -738,6 +739,7 @@ def test_document_with_link_named_data(self):
assert '<h1>Data Endpoint API</h1>' in html


@pytest.mark.skipif(not coreapi, reason='coreapi is not installed')
class TestSchemaJSRenderer(TestCase):

def test_schemajs_output(self):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ def test_get_link_requires_instance(self):
with pytest.raises(AssertionError):
descriptor.get_link(None, None, None) # ???: Do the dummy arguments require a tighter assert?

@pytest.mark.skipif(not coreapi, reason='coreapi is not installed')
def test_update_fields(self):
"""
That updating fields by-name helper is correct
Expand Down Expand Up @@ -698,6 +699,7 @@ def test_update_fields(self):
assert len(fields) == 1
assert fields[0].required is False

@pytest.mark.skipif(not coreapi, reason='coreapi is not installed')
def test_get_manual_fields(self):
"""That get_manual_fields is applied during get_link"""

Expand All @@ -718,6 +720,7 @@ class CustomView(APIView):
assert len(fields) == 2
assert "my_extra_field" in [f.name for f in fields]

@pytest.mark.skipif(not coreapi, reason='coreapi is not installed')
def test_view_with_manual_schema(self):

path = '/example'
Expand Down Expand Up @@ -764,6 +767,7 @@ class CustomView(APIView):
link = view.schema.get_link(path, method, base_url)
assert link == expected

@unittest.skipUnless(coreschema, 'coreschema is not installed')
def test_field_to_schema(self):
label = 'Test label'
help_text = 'This is a helpful test text'
Expand Down Expand Up @@ -983,6 +987,7 @@ def detail_export(self, request):
naming_collisions_router.register(r'collision', NamingCollisionViewSet, base_name="collision")


@pytest.mark.skipif(not coreapi, reason='coreapi is not installed')
class TestURLNamingCollisions(TestCase):
"""
Ref: https://github.com/encode/django-rest-framework/issues/4704
Expand Down Expand Up @@ -1167,6 +1172,7 @@ def custom_action(self, request, pk):
assert inspector.get_allowed_methods(callback) == ["GET"]


@pytest.mark.skipif(not coreapi, reason='coreapi is not installed')
class TestAutoSchemaAllowsFilters(object):
class MockAPIView(APIView):
filter_backends = [filters.OrderingFilter]
Expand Down
10 changes: 7 additions & 3 deletions tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
"""
from django.conf.urls import url

from rest_framework.compat import coreapi
from rest_framework.documentation import include_docs_urls

urlpatterns = [
url(r'^docs/', include_docs_urls(title='Test Suite API')),
]
if coreapi:
urlpatterns = [
url(r'^docs/', include_docs_urls(title='Test Suite API')),
]
else:
urlpatterns = []
8 changes: 7 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ envlist =
{py34,py35,py36}-django20,
{py35,py36}-django21
{py35,py36}-djangomaster,
dist,lint,docs,
base,dist,lint,docs,

[travis:env]
DJANGO =
Expand All @@ -30,6 +30,12 @@ deps =
-rrequirements/requirements-testing.txt
-rrequirements/requirements-optionals.txt

[testenv:base]
; Ensure optional dependencies are not required
deps =
django
-rrequirements/requirements-testing.txt

[testenv:dist]
commands = ./runtests.py --fast {posargs} --no-pkgroot --staticfiles -rw
deps =
Expand Down

0 comments on commit 1a17043

Please sign in to comment.