def test(self, request, *args, **kwargs): assert issubclass(self.get_serializer_class(), serializers.EmptySerializer) response = request.session.get(0, "OK") request.session[0] = "OK" request.session.save() return responses.HTTP_200_OK(response)
def update(self, request: drf_request.Request, *args, **kwargs): partial = kwargs.pop('partial', False) instance = self.get_object() serializer = self.get_serializer(instance, data=request.data, partial=partial) serializer.is_valid(raise_exception=True) self.perform_update(serializer) return responses.HTTP_200_OK(serializer.data)
def _settings(self, request: drf_request.Request, *args, **kwargs): instance, _ = UserSettings.objects.get_or_create( user=self.get_object(), defaults=SimpleLazyObject(lambda: {'value': self.get_serializer({}).data}) # type: ignore ) if request.method.upper() == 'PUT': # type: ignore serializer = self.get_serializer(instance.value, data=request.data) serializer.is_valid(raise_exception=True) instance.value = serializer.save() instance.save() else: serializer = self.get_serializer(instance.value) return responses.HTTP_200_OK(serializer.data)
def twofa(self, request: drf_request.Request, *args, **kwargs): user: User = self.get_object() # type: ignore instance = getattr(user, 'twofa', None) if request.method.upper() == 'PUT': # type: ignore serializer = self.get_serializer(instance, data=request.data) serializer.is_valid(raise_exception=True) serializer.save(user=user) request.session['2fa'] = True else: serializer = self.get_serializer( instance or SimpleLazyObject(lambda: TwoFactor(user=user)) ) return responses.HTTP_200_OK(serializer.data)
def list(self, request): start_time = time.time() headers = request._request.META # Don't send wsgi.* headers headers = { k: v for k, v in headers.items() if not k.startswith('wsgi.') } serializer = DataSerializer(data=json.dumps( dict(headers=headers, query=request.query_params, user_id=request.user.id))) serializer.is_valid(raise_exception=True) request._request.is_bulk = False return responses.HTTP_200_OK( serializer.data, timings=dict(req=( i for i in ['test case', time.time() - start_time]), miss=None))
def test(self, request, *args, **kwargs): return responses.HTTP_200_OK('OK')
def new_action_detail(self, request, *args, **kwargs): return responses.HTTP_200_OK('OK') # nocv
def test_bulk_perf(self, request, *args, **kwargs): time.sleep(0.001) return responses.HTTP_200_OK({'id': request.user.id})
def put(self, request): data = request.data return responses.HTTP_200_OK(data)