async def test_file_metadata(self, handler, mock_file_metadata):

        handler.provider.metadata = MockCoroutine(return_value=mock_file_metadata)

        await handler.file_metadata()

        handler.write.assert_called_once_with({
            'data': mock_file_metadata.json_api_serialized(handler.resource)
        })
    async def test_file_metadata(self, handler, mock_file_metadata):

        handler.provider.metadata = MockCoroutine(return_value=mock_file_metadata)

        await handler.file_metadata()

        handler.write.assert_called_once_with({
            'data': mock_file_metadata.json_api_serialized(handler.resource)
        })
    async def test_file_metadata_version(self, handler, mock_file_metadata):
        handler.provider.metadata = MockCoroutine(return_value=mock_file_metadata)
        handler.requested_version = 'version id'

        await handler.file_metadata()

        handler.provider.metadata.assert_called_once_with(handler.path, revision='version id')
        handler.write.assert_called_once_with({
            'data': mock_file_metadata.json_api_serialized(handler.resource)
        })
    async def test_file_metadata_version(self, handler, mock_file_metadata):
        handler.provider.metadata = MockCoroutine(return_value=mock_file_metadata)
        handler.requested_version = 'version id'

        await handler.file_metadata()

        handler.provider.metadata.assert_called_once_with(handler.path, revision='version id')
        handler.write.assert_called_once_with({
            'data': mock_file_metadata.json_api_serialized(handler.resource)
        })
    async def test_header_file_metadata(self, http_request, mock_file_metadata):

        handler = mock_handler(http_request)
        handler.provider.metadata = MockCoroutine(return_value=mock_file_metadata)

        await handler.header_file_metadata()

        assert handler._headers['Content-Length'] == '1337'
        assert handler._headers['Last-Modified'] == 'Wed, 25 Sep 1991 18:20:30 GMT'
        assert handler._headers['Content-Type'] == 'application/octet-stream'
        expected = json.dumps(mock_file_metadata.json_api_serialized(handler.resource))
        assert handler._headers['X-Waterbutler-Metadata'] == expected
    async def test_header_file_metadata(self, handler, mock_file_metadata):

        handler.provider.metadata = MockCoroutine(return_value=mock_file_metadata)

        await handler.header_file_metadata()

        assert handler._headers['Content-Length'] == '1337'
        assert handler._headers['Last-Modified'] == b'Wed, 25 Sep 1991 18:20:30 GMT'
        assert handler._headers['Content-Type'] == b'application/octet-stream'
        expected = bytes(json.dumps(mock_file_metadata.json_api_serialized(handler.resource)),
                         'latin-1')
        assert handler._headers['X-Waterbutler-Metadata'] == expected
Exemplo n.º 7
0
    async def test_not_created(self, handler, mock_file_metadata):
        handler.resource = '3rqws'
        handler.uploader.set_result((mock_file_metadata, False))
        handler.set_status = mock.Mock()

        await handler.upload_file()

        assert handler.wsock.close.called
        assert handler.writer.close.called
        assert handler.set_status.called is False
        handler.write.assert_called_once_with({
            'data': mock_file_metadata.json_api_serialized('3rqws')
        })