Skip to content
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

Use HTTP GET request for acquiring family information #34

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 20 additions & 5 deletions epo_ops/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,25 @@ def _check_for_exceeded_quota(self, response):
raise
return response # pragma: no cover

def _post(self, url, data, extra_headers=None, params=None):
def _req(self, url, data, extra_headers=None, params=None, use_get=False):
headers = {
'Accept': self.accept_type,
'Content-Type': 'text/plain'
}
headers.update(extra_headers or {})
return self.request.post(
request_method = self.request.post
if use_get:
request_method = self.request.get
return request_method(
url, data=data, headers=headers, params=params
)

def _make_request(self, url, data, extra_headers=None, params=None):
def _make_request(self, url, data, extra_headers=None, params=None, use_get=False):
extra_headers = extra_headers or {}
token = 'Bearer {0}'.format(self.access_token.token)
extra_headers['Authorization'] = token

response = self._post(url, data, extra_headers, params)
response = self._req(url, data, extra_headers, params, use_get=use_get)
response = self._check_for_expired_token(response)
response = self._check_for_exceeded_quota(response)
response.raise_for_status()
Expand All @@ -93,6 +96,17 @@ def _make_request_url(
]
return u'/'.join(filter(None, parts))

def _make_request_url_get(
self, service, reference_type, input, endpoint, constituents
):
constituents = constituents or []
parts = [
self.__service_url_prefix__, service, reference_type,
input and input.__class__.__name__.lower(), input.as_api_input(), endpoint,
','.join(constituents)
]
return u'/'.join(filter(None, parts))

# Service requests
def _service_request(
self, path, reference_type, input, endpoint, constituents
Expand Down Expand Up @@ -126,9 +140,10 @@ def _image_request(self, path, range, document_format):
)

def family(self, reference_type, input, endpoint=None, constituents=None):
return self._service_request(
url = self._make_request_url_get(
self.__family_path__, reference_type, input, endpoint, constituents
)
return self._make_request(url, None, params=input.as_api_input(), use_get=True)

def image(self, path, range=1, document_format='application/tiff'):
return self._image_request(
Expand Down
16 changes: 16 additions & 0 deletions epo_ops/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,19 @@ def post(self, url, data=None, **kwargs):

self.reset_env()
return response

def get(self, url, data=None, **kwargs):
self.reset_env()

for mw in self.middlewares:
url, data, kwargs = mw.process_request(
self.env, url, data, **kwargs
)

response = self.env['response'] or requests.get(url, **kwargs)

for mw in reversed(self.middlewares):
response = mw.process_response(self.env, response)

self.reset_env()
return response
17 changes: 17 additions & 0 deletions tests/helpers/api_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ def assert_family_success(client):
return response


def assert_family_biblio_success(client):
response = client.family(*data, constituents=['biblio'])
assert_request_success(response)
assert 'patent-family' in response.text
assert 'exchange-document' in response.text
assert 'bibliographic-data' in response.text
return response


def assert_family_legal_success(client):
response = client.family(*data, constituents=['legal'])
assert_request_success(response)
assert 'patent-family legal="true"' in response.text
assert 'ops:legal' in response.text
return response


def assert_image_success(client):
response = client.image(*idata)
assert_request_success(response)
Expand Down
12 changes: 11 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
from epo_ops.middlewares.throttle.storages import sqlite

from .helpers.api_helpers import (
assert_family_success, assert_image_success,
assert_family_success,
assert_family_biblio_success, assert_family_legal_success,
assert_image_success,
assert_number_service_success,
assert_published_data_search_success,
assert_published_data_search_with_range_success,
Expand All @@ -29,6 +31,14 @@ def test_family(all_clients):
assert_family_success(all_clients)


def test_family_biblio(all_clients):
assert_family_biblio_success(all_clients)


def test_family_legal(all_clients):
assert_family_legal_success(all_clients)


def test_image(all_clients):
assert_image_success(all_clients)

Expand Down