コード例 #1
0
 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))
コード例 #2
0
    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)
コード例 #3
0
    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,
        }}, {})