Skip to content

Commit

Permalink
Merge pull request #49 from Yupeek/develop
Browse files Browse the repository at this point in the history
release 1.8.3
  • Loading branch information
darius BERNARD authored Jan 25, 2019
2 parents fd05f23 + 5b9ff07 commit 0afdc9c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rest_models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__VERSION__ = '1.8.2'
__VERSION__ = '1.8.3'

try:
from rest_models.checks import register_checks
Expand Down
7 changes: 7 additions & 0 deletions rest_models/backend/connexion.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ def request(self, method, url, **kwargs):
return response


def get_basic_session():
session = requests.Session()
session.mount(LocalApiAdapter.SPECIAL_URL, LocalApiAdapter())
session.mount('http://testserver', LocalApiAdapter()) # for special host used by django for unittests
return session


class ApiConnexion(ApiVerbShortcutMixin):
"""
wrapper for request.Session that in fact implement useless methods like rollback which
Expand Down
9 changes: 8 additions & 1 deletion rest_models/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from django.core.files.storage import Storage
from django.utils.deconstruct import deconstructible

from rest_models.backend.connexion import get_basic_session

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -73,7 +75,12 @@ def _open(self, name, mode='rb'):
if 'r' not in mode:
NotImplementedError("This backend doesn't support writing on file.")
cursor = self.get_cursor(name) # fetch a valid cursor which just got the name
response = cursor.session.get(self.url(name))
url = self.url(name)
# try with anonymous data
response = get_basic_session().get(url)
# if we fail, we try with authenticated session
if response.status_code in (403, 401):
response = cursor.session.get(url)
response.raise_for_status()
return ContentFile(response.content, name)

Expand Down

0 comments on commit 0afdc9c

Please sign in to comment.