def test_response_for(self, mock_method):
        resource = HypermediaResource()

        # Response
        response = Mock()
        response.body = "body"
        response.media_type = "media_type"

        # Read action
        self.resource.read = Mock()
        self.resource.read.return_value = resource

        # Mock build response
        self.resource.build_response = Mock()
        self.resource.build_response.return_value = response

        self.resource.response_for(request('GET', {}))
        self.resource.build_response.assert_called_with(resource, "application/hal+json")
        mock_method.assert_called_with(response.body, mimetype=response.media_type)
    def test_response_for(self):
        resource = Representor()

        # Mock HypermediaResponse so we don't have to translate a resource
        hypermedia_response = Mock()
        hypermedia_response.media_type = "application/hal+json"
        hypermedia_response.body = "{ \"foo\": \"bar\" }"

        # Mock build response to return the mocked hypermedia_response
        self.resource.build_response = Mock()
        self.resource.build_response.return_value = hypermedia_response

        # Mock read action on a Flask API resource
        self.resource.read = Mock()
        self.resource.read.return_value = resource

        response = self.resource.response_for(request('GET', {}))
        self.assertEqual(response.mimetype, "application/hal+json")
        self.assertEqual(response.data, "{ \"foo\": \"bar\" }")
def adapter():
    adapter = Mock()
    adapter.media_type = "application/hal+json"
    adapter.parse.return_value = "parsed"
    adapter.build.return_value = "built"
    return adapter