async def test_metadata_file_with_branch(self, provider): path = '/folder1/folder2/file' gl_path = GitLabPath(path, _ids=([(None, 'my-branch')] * 4)) url = ('http://base.url/api/v4/projects/123/repository/files/' 'folder1%2Ffolder2%2Ffile?ref=my-branch') aiohttpretty.register_json_uri('GET', url, body=fixtures.simple_file_metadata()) history_url = ('http://base.url/api/v4/projects/123/repository/commits' '?path=folder1/folder2/file&ref_name=my-branch&page=1' '&per_page={}'.format(provider.MAX_PAGE_SIZE)) aiohttpretty.register_json_uri('GET', history_url, body=fixtures.revisions_for_file()) result = await provider.metadata(gl_path) assert result.json_api_serialized('mst3k')['links'] == { 'move': ('http://localhost:7777/v1/resources/mst3k/providers/gitlab' '/folder1/folder2/file?branch=my-branch'), 'upload': None, 'download': ('http://localhost:7777/v1/resources/mst3k/providers/gitlab' '/folder1/folder2/file?branch=my-branch'), 'delete': None, }
async def test_metadata_file_with_default_ref(self, provider): path = '/folder1/folder2/file' gl_path = GitLabPath(path, _ids=([('a1b2c3d4', 'master')] * 4)) url = ('http://base.url/api/v4/projects/123/repository/files/' 'folder1%2Ffolder2%2Ffile?ref=a1b2c3d4') aiohttpretty.register_json_uri('GET', url, body=fixtures.simple_file_metadata()) history_url = ('http://base.url/api/v4/projects/123/repository/commits' '?path=folder1/folder2/file&ref_name=a1b2c3d4&page=1' '&per_page={}'.format(provider.MAX_PAGE_SIZE)) aiohttpretty.register_json_uri('GET', history_url, body=fixtures.revisions_for_file()) etag = hashlib.sha256('{}::{}::{}'.format('gitlab', path, 'a1b2c3d4').encode('utf-8'))\ .hexdigest() result = await provider.metadata(gl_path) assert result.serialized() == { 'name': 'file', 'kind': 'file', 'size': 123, 'sizeInt': 123, 'provider': 'gitlab', 'path': path, 'materialized': path, 'modified': '2017-07-24T16:02:17.000-04:00', 'modified_utc': '2017-07-24T20:02:17+00:00', 'created_utc': '2016-11-30T18:30:23+00:00', 'contentType': None, 'etag': etag, 'extra': { 'commitSha': 'a1b2c3d4', 'branch': 'master', 'webView': 'http://base.url/cat/food/blob/master/folder1/folder2/file', }, } assert result.json_api_serialized('mst3k')['links'] == { 'move': ('http://localhost:7777/v1/resources/mst3k/providers/gitlab' '/folder1/folder2/file?commitSha=a1b2c3d4'), 'upload': None, 'download': ('http://localhost:7777/v1/resources/mst3k/providers/gitlab' '/folder1/folder2/file?commitSha=a1b2c3d4'), 'delete': None, }
async def test_metadata_file_ruby_response(self, provider): """See: https://gitlab.com/gitlab-org/gitlab-ce/issues/31790""" path = '/folder1/folder2/file' gl_path = GitLabPath(path, _ids=([(None, 'my-branch')] * 4)) url = ('http://base.url/api/v4/projects/123/repository/files/' 'folder1%2Ffolder2%2Ffile?ref=my-branch') aiohttpretty.register_uri('GET', url, body=fixtures.weird_ruby_response()) history_url = ('http://base.url/api/v4/projects/123/repository/commits' '?path=folder1/folder2/file&ref_name=my-branch&page=1' '&per_page={}'.format(provider.MAX_PAGE_SIZE)) aiohttpretty.register_json_uri('GET', history_url, body=fixtures.revisions_for_file()) result = await provider.metadata(gl_path) assert result.name == 'file' assert result.size == 5 assert result.content_type == None
async def test_metadata_file_with_default_ref(self, provider): path = '/folder1/folder2/file' gl_path = GitLabPath(path, _ids=([('a1b2c3d4', 'master')] * 4)) url = ('http://base.url/api/v4/projects/123/repository/files/' 'folder1%2Ffolder2%2Ffile?ref=a1b2c3d4') aiohttpretty.register_json_uri('GET', url, body=fixtures.simple_file_metadata()) history_url = ('http://base.url/api/v4/projects/123/repository/commits' '?path=folder1/folder2/file&ref_name=a1b2c3d4&page=1' '&per_page={}'.format(provider.MAX_PAGE_SIZE)) aiohttpretty.register_json_uri('GET', history_url, body=fixtures.revisions_for_file()) etag = hashlib.sha256('{}::{}::{}'.format('gitlab', path, 'a1b2c3d4').encode('utf-8'))\ .hexdigest() result = await provider.metadata(gl_path) assert result.serialized() == { 'name': 'file', 'kind': 'file', 'size': 123, 'sizeInt': 123, 'provider':'gitlab', 'path': path, 'materialized': path, 'modified': '2017-07-24T16:02:17.000-04:00', 'modified_utc': '2017-07-24T20:02:17+00:00', 'created_utc': '2016-11-30T18:30:23+00:00', 'contentType': None, 'etag': etag, 'extra': { 'commitSha': 'a1b2c3d4', 'branch': 'master', 'webView': 'http://base.url/cat/food/blob/master/folder1/folder2/file', }, } assert result.json_api_serialized('mst3k')['links'] == { 'move': ('http://localhost:7777/v1/resources/mst3k/providers/gitlab' '/folder1/folder2/file?commitSha=a1b2c3d4'), 'upload': None, 'download': ('http://localhost:7777/v1/resources/mst3k/providers/gitlab' '/folder1/folder2/file?commitSha=a1b2c3d4'), 'delete': None, }
async def test_revisions(self, provider): path = '/folder1/folder2/file' gl_path = GitLabPath(path, _ids=([('a1b2c3d4', 'master')] * 4)) url = ('http://base.url/api/v4/projects/123/repository/commits' '?path=folder1/folder2/file&ref_name=a1b2c3d4') aiohttpretty.register_json_uri('GET', url, body=fixtures.revisions_for_file()) revisions = await provider.revisions(gl_path) assert len(revisions) == 3 assert revisions[0].serialized() == { 'version': '931aece9275c0d084dfa7f6e0b3b2bb250e4b089', 'modified': '2017-07-24T16:02:17.000-04:00', 'modified_utc': '2017-07-24T20:02:17+00:00', 'versionIdentifier': 'commitSha', 'extra': { 'user': { 'name': 'Fitz Elliott', }, }, }