def __init__(self, username, password, serializer=None): self.serializer = serializer self.username = username self.password = password if not self.serializer: self.serializer = LimsSerializer() super(ApiClient, self).__init__(enforce_csrf_checks=False, SERVER_NAME='localhost')
def _get_list_response(self,request,**kwargs): ''' Return a deserialized list of dicts ''' includes = kwargs.pop('includes', '*') try: logger.debug( 'get internal list response %s, %s ', self._meta.resource_name, kwargs) kwargs.setdefault('limit', 0) response = self.get_list( request, format='json', includes=includes, **kwargs) logger.debug('response: %r', response) _data = self._meta.serializer.deserialize( LimsSerializer.get_content(response), response['Content-Type']) _data = _data[self._meta.collection_name] logger.debug(' data: %s'% _data) return _data except Http404: return [] except Exception as e: # FIXME: temporary travis debug logger.exception('on get list') return []
def __init__(self, username, password, serializer=None): self.serializer = serializer self.username = username self.password = password if not self.serializer: self.serializer = LimsSerializer() super(ApiClient, self).__init__( enforce_csrf_checks=False, SERVER_NAME='localhost')
class Meta: queryset = Reaction.objects.all() #.order_by('facility_id') authentication = MultiAuthentication(BasicAuthentication(), SessionAuthentication()) always_return_data = True authorization= SuperUserAuthorization() resource_name = 'reaction' ordering = [] filtering = {} serializer = LimsSerializer()
class Meta: queryset = ExpressionHost.objects.all() authentication = MultiAuthentication(BasicAuthentication(), SessionAuthentication()) authorization= SuperUserAuthorization() resource_name = 'expressionhost' always_return_data = True ordering = [] filtering = {} serializer = LimsSerializer()
class ApiClient(django.test.client.Client): def __init__(self, username, password, serializer=None): self.serializer = serializer self.username = username self.password = password if not self.serializer: self.serializer = LimsSerializer() super(ApiClient, self).__init__( enforce_csrf_checks=False, SERVER_NAME='localhost') def deserialize(self, resp): return self.serializer.deserialize( self.serializer.get_content(resp), resp['Content-Type']) def create_basic(self, username, password): """ Creates & returns the HTTP ``Authorization`` header for use with BASIC Auth. """ import base64 return 'Basic %s' % base64.b64encode( ':'.join([username, password]).encode('utf-8')).decode('utf-8') def get_credentials(self): return self.create_basic(username=self.username, password=self.password) def request(self, **request): # Default to JSON for background client requests if DJANGO_ACCEPT_PARAM not in request: request[DJANGO_ACCEPT_PARAM] = JSON_MIMETYPE if 'HTTP_AUTHORIZATION' not in request: request['HTTP_AUTHORIZATION'] = self.get_credentials() return django.test.client.Client.request(self, **request)
class ApiClient(django.test.client.Client): def __init__(self, username, password, serializer=None): self.serializer = serializer self.username = username self.password = password if not self.serializer: self.serializer = LimsSerializer() super(ApiClient, self).__init__(enforce_csrf_checks=False, SERVER_NAME='localhost') def deserialize(self, resp): return self.serializer.deserialize(self.serializer.get_content(resp), resp['Content-Type']) def create_basic(self, username, password): """ Creates & returns the HTTP ``Authorization`` header for use with BASIC Auth. """ import base64 return 'Basic %s' % base64.b64encode(':'.join( [username, password]).encode('utf-8')).decode('utf-8') def get_credentials(self): return self.create_basic(username=self.username, password=self.password) def request(self, **request): # Default to JSON for background client requests if DJANGO_ACCEPT_PARAM not in request: request[DJANGO_ACCEPT_PARAM] = JSON_MIMETYPE if 'HTTP_AUTHORIZATION' not in request: request['HTTP_AUTHORIZATION'] = self.get_credentials() return django.test.client.Client.request(self, **request)
def top_level(self, request, api_name=None): ''' A view that returns a serialized list of all resources registers to the API. ''' fullschema = parse_val( request.GET.get('fullschema', False), 'fullschema', 'boolean') available_resources = {} if api_name is None: api_name = self.api_name for name, resource in self._registry.items(): if not fullschema: schema = self._build_reverse_url('api_get_schema', kwargs={ 'api_name': api_name, 'resource_name': name, }) else: schema = resource.build_schema() available_resources[name] = { 'list_endpoint': self._build_reverse_url('api_dispatch_list', kwargs={ 'api_name': api_name, 'resource_name': name, }), 'schema': schema, } serializer = LimsSerializer() content_type = serializer.get_accept_content_type(request) serialized = serializer.serialize(available_resources, content_type) return HttpResponse( content=serialized, content_type=content_type)
def top_level(self, request, api_name=None): ''' A view that returns a serialized list of all resources registers to the API. ''' fullschema = parse_val(request.GET.get('fullschema', False), 'fullschema', 'boolean') available_resources = {} if api_name is None: api_name = self.api_name for name, resource in self._registry.items(): if not fullschema: schema = self._build_reverse_url('api_get_schema', kwargs={ 'api_name': api_name, 'resource_name': name, }) else: schema = resource.build_schema() available_resources[name] = { 'list_endpoint': self._build_reverse_url('api_dispatch_list', kwargs={ 'api_name': api_name, 'resource_name': name, }), 'schema': schema, } serializer = LimsSerializer() content_type = serializer.get_accept_content_type(request) serialized = serializer.serialize(available_resources, content_type) return HttpResponse(content=serialized, content_type=content_type)
class Meta: queryset = SmallMolecule.objects.all() #.order_by('facility_id') authentication = MultiAuthentication(BasicAuthentication(), SessionAuthentication()) authorization= SuperUserAuthorization() resource_name = 'smallmolecule' # NOTE: in order to patch_list, wherein 'resource_uri' is not set, # the method 'put' is required. TODO: figure out better allowed methods # allowed_methods = ['get', 'patch', 'delete', 'put', 'post'] # list_allowed_methods = ['get','patch','put','delete'] always_return_data = True ordering = [] filtering = {} serializer = LimsSerializer()
def _get_detail_response(self,request,**kwargs): ''' Return the detail response as a dict ''' logger.info('_get_detail_response: %r, %r', self._meta.resource_name, kwargs) try: response = self.get_detail( request, format='json', includes='*', **kwargs) _data = [] if response.status_code == 200: _data = self._meta.serializer.deserialize( LimsSerializer.get_content(response), response['Content-Type']) else: logger.info( 'no data found for %r, %r', self._meta.resource_name, kwargs) return _data except Http404: return []