Skip to content

Commit

Permalink
Merge bc9f9d9 into c6ee4ba
Browse files Browse the repository at this point in the history
  • Loading branch information
vancamti committed Jan 21, 2021
2 parents c6ee4ba + bc9f9d9 commit 5d5abc0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
1 change: 0 additions & 1 deletion .travis.yml
@@ -1,7 +1,6 @@
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
env:
Expand Down
4 changes: 3 additions & 1 deletion pyramid_urireferencer/views.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-

from pyramid.httpexceptions import HTTPBadRequest
from pyramid.view import view_config
from pyramid_urireferencer import get_referencer

Expand All @@ -20,4 +20,6 @@ class RestView(ApplicatieView):
class ReferencesPluginView(RestView):
@view_config(route_name='references', renderer='json_item', accept='application/json')
def get_references(self):
if not self.request.params.get('uri'):
raise HTTPBadRequest('Uri is required.')
return get_referencer(self.request.registry).references(self.request.params.get('uri'), self.request)
1 change: 1 addition & 0 deletions requirements-dev.txt
Expand Up @@ -2,6 +2,7 @@
--requirement requirements.txt

#testing
attrs==19.1.0
pytest==3.4.2
pytest-cov==2.5.1
webtest==2.0.29
Expand Down
29 changes: 25 additions & 4 deletions tests/test_views.py
Expand Up @@ -2,11 +2,22 @@

import json
import unittest

try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch

import httpretty
from pyramid import testing
from pyramid_urireferencer import IReferencer, Referencer, _add_referencer, get_referencer
from pyramid_urireferencer.views import ReferencesPluginView
from pyramid.httpexceptions import HTTPBadRequest

from pyramid_urireferencer import IReferencer
from pyramid_urireferencer import Referencer
from pyramid_urireferencer import _add_referencer
from pyramid_urireferencer import get_referencer
from pyramid_urireferencer.models import RegistryResponse
from pyramid_urireferencer.views import ReferencesPluginView

try:
from urllib import urlencode
Expand Down Expand Up @@ -64,12 +75,22 @@ def test_is_referenced(self):
httpretty.disable() # disable afterwards, so that you will have no problems in code that uses that socket module
httpretty.reset()

def test_no_uri(self):
request = Mock(params={'uri': ''})
view = ReferencesPluginView(request)
with self.assertRaises(HTTPBadRequest):
view.get_references()

def test_uri_none(self):
request = Mock(params={'uri': None})
view = ReferencesPluginView(request)
with self.assertRaises(HTTPBadRequest):
view.get_references()


class TestReferencer(Referencer):
def references(self, uri, request):
return None

def get_uri(self, request):
return 'https://id.erfgoed.net/resources/1'


0 comments on commit 5d5abc0

Please sign in to comment.