def _build_request(self) -> Request: request = Request(HttpRequest()) request.user = self._get_executor() params = self._add_params() if params: request._full_data = params return request
def has_permission(self, obj, method, action, data): """Check if user has permission to perform action.""" # Fake the request request = Request(HttpRequest()) request.method = method request.user = self.user request._full_data = data # Fake the corresponding view view = FakeView(action, lambda: obj) return self.access_policy.has_permission(request, view)
def convert_to_drf_request(request: HttpRequest, data: dict = None) -> Request: """ Convert a standard Django request to the DRF equivalent. DRF ViewSets can't take normal Django requests, so any interaction with the API side must involve converting the request object before sending it off. We also occasionally want to have data on it to make the API happy, so this function also handles that. """ new_request = Request(request) new_request._full_data = data return new_request
def test_get_attribute_data(request_data, project, attribute_data): http_request = HttpRequest() request = Request(http_request) request._full_data = {"attribute_data": request_data} assert get_attribute_data(request, project) == { **attribute_data, **( { "kaavaprosessin_kokoluokka": project.subtype.name, "kaavan_vaihe": project.phase.prefixed_name, } if project else {} ), }
def has_view_catalog_permissions(self, path): """ Check if the authenticated user is an administrator and is requesting the catalog endpoint. """ try: distribution = ContainerDistribution.objects.get(base_path=path) except ContainerDistribution.DoesNotExist: distribution = None # Fake the request request = Request(HttpRequest()) request.method = "GET" request.user = self.user request._full_data = {"base_path": path} # Fake the corresponding view view = namedtuple("FakeView", ["action", "get_object"])("catalog", lambda: distribution) return self.access_policy.has_permission(request, view)
def _extend_request(self, request): data = request.data.copy() data['organization_uuid'] = request.session['jwt_organization_uuid'] request_extended = Request(HttpRequest()) request_extended._full_data = data return request_extended
def test_get_attribute_data(request_data, project, attribute_data): http_request = HttpRequest() request = Request(http_request) request._full_data = {"attribute_data": request_data} assert get_attribute_data(request, project) == attribute_data
def test_should_not_refresh_with_data_false(self): drf_request = Request(HttpRequest()) drf_request._full_data = {"refresh": False} # type: ignore self.assertFalse(should_refresh(drf_request))
def test_should_refresh_with_data_true(self): drf_request = Request(HttpRequest()) drf_request._full_data = {"refresh": True} # type: ignore self.assertTrue(should_refresh((drf_request)))