def test_ok(self): with patch("gobstuf.rest.brp.rest_response.request", mock_request): result = RESTResponse.ok(any_data) response = json.loads(result['response']) self.assertEqual(result['content_type'], 'application/hal+json') self.assertEqual(result['status'], 200) self.assertEqual(response, RESTResponse._hal(any_data))
def _build_response(self, response_obj: StufMappedResponse, **kwargs): """Return single object response by default Overridden by StufRestFilterView to create a list of objects :param response_obj: :param kwargs: :return: """ try: data = response_obj.get_answer_object() except NoStufAnswerException: # Return 404, answer section is empty return RESTResponse.not_found(detail=self.get_not_found_message( **kwargs)) else: return RESTResponse.ok(data)
def _build_response(self, response_obj: StufMappedResponse, **kwargs): """Returns the REST response, of the format: _embedded: { ingeschrevenpersonen: [ { response object 1}, { response object 2}, { ... }, ] } :param response_obj: :param kwargs: :return: """ data = response_obj.get_all_answer_objects() return RESTResponse.ok({'_embedded': { self.name: data, }}, {})