def test_file_metadata(self, file_metadata):
        data = CloudFilesFileMetadata(file_metadata)
        assert data.name == 'similar.file'
        assert data.provider == 'cloudfiles'
        assert data.path == '/similar.file'
        assert data.size == 190
        assert data.size_as_int == 190
        assert type(data.size_as_int) == int
        assert data.modified == '2014-12-19T23:22:14.728640'
        assert data.created_utc is None
        assert data.content_type == 'application/x-www-form-urlencoded;charset=utf-8'
        assert data.etag == 'edfa12d00b779b4b37b81fe5b61b2b3f'
        assert data.kind == 'file'
        assert data.modified_utc == '2014-12-19T23:22:14+00:00'
        assert data.extra == {
            'hashes': {
                'md5': 'edfa12d00b779b4b37b81fe5b61b2b3f'
            }
        }

        assert data.serialized() == {
            'extra': {
                'hashes': {'md5': 'edfa12d00b779b4b37b81fe5b61b2b3f'}},
            'kind': 'file',
            'name': 'similar.file',
            'path': '/similar.file',
            'provider': 'cloudfiles',
            'materialized': '/similar.file',
            'etag': '6ec17a9d5ecaf7f61ed46fa983361d2317fce07d36b40739b2f7529a1c0f47e0',
            'contentType': 'application/x-www-form-urlencoded;charset=utf-8',
            'modified': '2014-12-19T23:22:14.728640',
            'modified_utc': '2014-12-19T23:22:14+00:00',
            'created_utc': None,
            'size': 190,
            'sizeInt': 190,
        }

        assert data.json_api_serialized('cn42d') == {
            'id': 'cloudfiles/similar.file',
            'type': 'files',
            'attributes': {
                'extra': {
                    'hashes': {
                        'md5': 'edfa12d00b779b4b37b81fe5b61b2b3f'
                    }
                },
                'kind': 'file',
                'name': 'similar.file',
                'path': '/similar.file',
                'provider': 'cloudfiles',
                'materialized': '/similar.file',
                'etag': '6ec17a9d5ecaf7f61ed46fa983361d2317fce07d36b40739b2f7529a1c0f47e0',
                'contentType': 'application/x-www-form-urlencoded;charset=utf-8',
                'modified': '2014-12-19T23:22:14.728640',
                'modified_utc': '2014-12-19T23:22:14+00:00',
                'created_utc': None,
                'size': 190,
                'sizeInt': 190,
                'resource': 'cn42d'
            },
            'links': {
                'move': ('http://localhost:7777/v1/resources/cn42d'
                    '/providers/cloudfiles/similar.file'),
                'upload': ('http://localhost:7777/v1/resources/cn42d'
                    '/providers/cloudfiles/similar.file?kind=file'),
                'delete': ('http://localhost:7777/v1/resources/cn42d'
                    '/providers/cloudfiles/similar.file'),
                'download': ('http://localhost:7777/v1/resources/cn42d'
                    '/providers/cloudfiles/similar.file')
            }
        }

        assert data._json_api_links('cn42d') == {
            'move': 'http://localhost:7777/v1/resources/cn42d/providers/cloudfiles/similar.file',
            'upload': ('http://localhost:7777/v1/resources/'
                'cn42d/providers/cloudfiles/similar.file?kind=file'),
            'delete': 'http://localhost:7777/v1/resources/cn42d/providers/cloudfiles/similar.file',
            'download': 'http://localhost:7777/v1/resources/cn42d/providers/cloudfiles/similar.file'
        }
예제 #2
0
 def _serialize_folder_metadata(self, data):
     if data.get('subdir'):
         return CloudFilesFolderMetadata(data)
     elif data['content_type'] == 'application/directory':
         return CloudFilesFolderMetadata({'subdir': data['name'] + '/'})
     return CloudFilesFileMetadata(data)
예제 #3
0
    def test_file_metadata(self, file_metadata):
        data = CloudFilesFileMetadata(file_metadata)
        assert data.name == 'similar.file'
        assert data.provider == 'cloudfiles'
        assert data.path == '/similar.file'
        assert data.size == 190
        assert data.modified == '2014-12-19T23:22:14.728640'
        assert data.created_utc is None
        assert data.content_type == 'application/x-www-form-urlencoded;charset=utf-8'
        assert data.etag == 'edfa12d00b779b4b37b81fe5b61b2b3f'
        assert data.kind == 'file'
        assert data.modified_utc == '2014-12-19T23:22:14+00:00'
        assert data.extra == {
            'hashes': {
                'md5': 'edfa12d00b779b4b37b81fe5b61b2b3f'
            }
        }

        assert data.serialized() == {
            'extra': {
                'hashes': {'md5': 'edfa12d00b779b4b37b81fe5b61b2b3f'}},
            'kind': 'file',
            'name': 'similar.file',
            'path': '/similar.file',
            'provider': 'cloudfiles',
            'materialized': '/similar.file',
            'etag': '6ec17a9d5ecaf7f61ed46fa983361d2317fce07d36b40739b2f7529a1c0f47e0',
            'contentType': 'application/x-www-form-urlencoded;charset=utf-8',
            'modified': '2014-12-19T23:22:14.728640',
            'modified_utc': '2014-12-19T23:22:14+00:00',
            'created_utc': None,
            'size': 190
        }

        assert data.json_api_serialized('cn42d') == {
            'id': 'cloudfiles/similar.file',
            'type': 'files',
            'attributes': {
                'extra': {
                    'hashes': {
                        'md5': 'edfa12d00b779b4b37b81fe5b61b2b3f'
                    }
                },
                'kind': 'file',
                'name': 'similar.file',
                'path': '/similar.file',
                'provider': 'cloudfiles',
                'materialized': '/similar.file',
                'etag': '6ec17a9d5ecaf7f61ed46fa983361d2317fce07d36b40739b2f7529a1c0f47e0',
                'contentType': 'application/x-www-form-urlencoded;charset=utf-8',
                'modified': '2014-12-19T23:22:14.728640',
                'modified_utc': '2014-12-19T23:22:14+00:00',
                'created_utc': None,
                'size': 190,
                'resource': 'cn42d'
            },
            'links': {
                'move': ('http://localhost:7777/v1/resources/cn42d'
                    '/providers/cloudfiles/similar.file'),
                'upload': ('http://localhost:7777/v1/resources/cn42d'
                    '/providers/cloudfiles/similar.file?kind=file'),
                'delete': ('http://localhost:7777/v1/resources/cn42d'
                    '/providers/cloudfiles/similar.file'),
                'download': ('http://localhost:7777/v1/resources/cn42d'
                    '/providers/cloudfiles/similar.file')
            }
        }

        assert data._json_api_links('cn42d') == {
            'move': 'http://localhost:7777/v1/resources/cn42d/providers/cloudfiles/similar.file',
            'upload': ('http://localhost:7777/v1/resources/'
                'cn42d/providers/cloudfiles/similar.file?kind=file'),
            'delete': 'http://localhost:7777/v1/resources/cn42d/providers/cloudfiles/similar.file',
            'download': 'http://localhost:7777/v1/resources/cn42d/providers/cloudfiles/similar.file'
        }