Commit 57b9b5f3 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[webapi] Remove use of django rest_framework client use for testing

parent 6103410d
......@@ -649,12 +649,12 @@ def edit_local_file(prefix, editor, asset_type, name):
return 0
def make_webapi(c):
def make_webapi(config):
"""Instantiates an usable web-api proxy using the command-line configuration
c (object): The command-line configuration object, from which this function
config (object): The command-line configuration object, from which this function
will extract the ``platform``, ``user`` and ``token`` parameters.
......@@ -664,63 +664,9 @@ def make_webapi(c):
if c.platform.startswith("django://"):
from .webapi import WebAPI
# returns a Django RestFramework API client that looks like our WebAPI
from rest_framework.test import APIClient
from rest_framework.authtoken.models import Token
class APIClientContext(APIClient):
def __init__(self, platform, user, token, *args, **kwargs):
self.platform = platform
super(APIClientContext, self).__init__(*args, **kwargs)
self.user = user
self.token = token
# sets-up authorization token on all requests, if user is set
if self.user is not None:
token = Token.objects.get(user__username=user)
self.credentials(HTTP_AUTHORIZATION="Token " + token.key)
def is_anonymous(self):
"""Tells if the user has not set credentials for the platform"""
return self.token is None
def __enter__(self):
return self
def __exit__(self, *exc):
def _message(self, asset_type, url, data=None):
if data:
data = simplejson.dumps(data)
retval = getattr(super(APIClientContext, self), asset_type)(
url, data, content_type="application/json"
return (retval.status_code, retval.content)
def get(self, url, data=None):
return self._message("get", url, data)
def put(self, url, data=None):
return self._message("put", url, data)
def post(self, url, data=None):
return self._message("post", url, data)
def delete(self, url, data=None):
return self._message("delete", url, data)
return APIClientContext(c.platform, c.user, c.token)
# sets up our own client
from .webapi import WebAPI
return WebAPI(c.platform, c.user, c.token)
return WebAPI(config.platform, config.user, config.token)
def check_one(prefix, asset_type, name):
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment