##// END OF EJS Templates
git-lfs: report returned data as 'application/vnd.git-lfs+json' instead of plain json
marcink -
r198:f7c555da default
parent child Browse files
Show More
@@ -38,7 +38,7 b" GIT_LFS_PROTO_PAT = re.compile(r'^/(.+)/"
38
38
39
39
40 def write_response_error(http_exception, text=None):
40 def write_response_error(http_exception, text=None):
41 content_type = 'application/json'
41 content_type = GIT_LFS_CONTENT_TYPE + '+json'
42 _exception = http_exception(content_type=content_type)
42 _exception = http_exception(content_type=content_type)
43 _exception.content_type = content_type
43 _exception.content_type = content_type
44 if text:
44 if text:
@@ -85,10 +85,9 b' def lfs_objects_batch(request):'
85 oid - String OID of the LFS object.
85 oid - String OID of the LFS object.
86 size - Integer byte size of the LFS object. Must be at least zero.
86 size - Integer byte size of the LFS object. Must be at least zero.
87 """
87 """
88 request.response.content_type = GIT_LFS_CONTENT_TYPE + '+json'
88 auth = request.authorization
89 auth = request.authorization
89
90 repo = request.matchdict.get('repo')
90 repo = request.matchdict.get('repo')
91
92 data = request.json
91 data = request.json
93 operation = data.get('operation')
92 operation = data.get('operation')
94 if operation not in ('download', 'upload'):
93 if operation not in ('download', 'upload'):
@@ -143,6 +142,7 b' def lfs_objects_batch(request):'
143
142
144
143
145 def lfs_objects_oid_upload(request):
144 def lfs_objects_oid_upload(request):
145 request.response.content_type = GIT_LFS_CONTENT_TYPE + '+json'
146 repo = request.matchdict.get('repo')
146 repo = request.matchdict.get('repo')
147 oid = request.matchdict.get('oid')
147 oid = request.matchdict.get('oid')
148 store = LFSOidStore(
148 store = LFSOidStore(
@@ -178,6 +178,7 b' def lfs_objects_oid_download(request):'
178
178
179
179
180 def lfs_objects_verify(request):
180 def lfs_objects_verify(request):
181 request.response.content_type = GIT_LFS_CONTENT_TYPE + '+json'
181 repo = request.matchdict.get('repo')
182 repo = request.matchdict.get('repo')
182
183
183 data = request.json
184 data = request.json
@@ -18,6 +18,7 b''
18 import os
18 import os
19 import pytest
19 import pytest
20 from webtest.app import TestApp as WebObTestApp
20 from webtest.app import TestApp as WebObTestApp
21 import simplejson as json
21
22
22 from vcsserver.git_lfs.app import create_app
23 from vcsserver.git_lfs.app import create_app
23
24
@@ -43,18 +44,18 b' class TestLFSApplication(object):'
43 def test_app_deprecated_endpoint(self, git_lfs_app):
44 def test_app_deprecated_endpoint(self, git_lfs_app):
44 response = git_lfs_app.post('/repo/info/lfs/objects', status=501)
45 response = git_lfs_app.post('/repo/info/lfs/objects', status=501)
45 assert response.status_code == 501
46 assert response.status_code == 501
46 assert response.json == {u'message': u'LFS: v1 api not supported'}
47 assert json.loads(response.text) == {u'message': u'LFS: v1 api not supported'}
47
48
48 def test_app_lock_verify_api_not_available(self, git_lfs_app):
49 def test_app_lock_verify_api_not_available(self, git_lfs_app):
49 response = git_lfs_app.post('/repo/info/lfs/locks/verify', status=501)
50 response = git_lfs_app.post('/repo/info/lfs/locks/verify', status=501)
50 assert response.status_code == 501
51 assert response.status_code == 501
51 assert response.json == {
52 assert json.loads(response.text) == {
52 u'message': u'GIT LFS locking api not supported'}
53 u'message': u'GIT LFS locking api not supported'}
53
54
54 def test_app_lock_api_not_available(self, git_lfs_app):
55 def test_app_lock_api_not_available(self, git_lfs_app):
55 response = git_lfs_app.post('/repo/info/lfs/locks', status=501)
56 response = git_lfs_app.post('/repo/info/lfs/locks', status=501)
56 assert response.status_code == 501
57 assert response.status_code == 501
57 assert response.json == {
58 assert json.loads(response.text) == {
58 u'message': u'GIT LFS locking api not supported'}
59 u'message': u'GIT LFS locking api not supported'}
59
60
60 def test_app_batch_api_missing_auth(self, git_lfs_app,):
61 def test_app_batch_api_missing_auth(self, git_lfs_app,):
@@ -65,14 +66,14 b' class TestLFSApplication(object):'
65 response = git_lfs_app.post_json(
66 response = git_lfs_app.post_json(
66 '/repo/info/lfs/objects/batch', params={}, status=400,
67 '/repo/info/lfs/objects/batch', params={}, status=400,
67 extra_environ=http_auth)
68 extra_environ=http_auth)
68 assert response.json == {
69 assert json.loads(response.text) == {
69 u'message': u'unsupported operation mode: `None`'}
70 u'message': u'unsupported operation mode: `None`'}
70
71
71 def test_app_batch_api_missing_objects(self, git_lfs_app, http_auth):
72 def test_app_batch_api_missing_objects(self, git_lfs_app, http_auth):
72 response = git_lfs_app.post_json(
73 response = git_lfs_app.post_json(
73 '/repo/info/lfs/objects/batch', params={'operation': 'download'},
74 '/repo/info/lfs/objects/batch', params={'operation': 'download'},
74 status=400, extra_environ=http_auth)
75 status=400, extra_environ=http_auth)
75 assert response.json == {
76 assert json.loads(response.text) == {
76 u'message': u'missing objects data'}
77 u'message': u'missing objects data'}
77
78
78 def test_app_batch_api_unsupported_data_in_objects(
79 def test_app_batch_api_unsupported_data_in_objects(
@@ -82,7 +83,7 b' class TestLFSApplication(object):'
82 response = git_lfs_app.post_json(
83 response = git_lfs_app.post_json(
83 '/repo/info/lfs/objects/batch', params=params, status=400,
84 '/repo/info/lfs/objects/batch', params=params, status=400,
84 extra_environ=http_auth)
85 extra_environ=http_auth)
85 assert response.json == {
86 assert json.loads(response.text) == {
86 u'message': u'unsupported data in objects'}
87 u'message': u'unsupported data in objects'}
87
88
88 def test_app_batch_api_download_missing_object(
89 def test_app_batch_api_download_missing_object(
@@ -101,7 +102,7 b' class TestLFSApplication(object):'
101 u'oid': u'123',
102 u'oid': u'123',
102 u'size': u'1024'}
103 u'size': u'1024'}
103 ]
104 ]
104 assert response.json == {
105 assert json.loads(response.text) == {
105 'objects': expected_objects, 'transfer': 'basic'}
106 'objects': expected_objects, 'transfer': 'basic'}
106
107
107 def test_app_batch_api_download(self, git_lfs_app, http_auth):
108 def test_app_batch_api_download(self, git_lfs_app, http_auth):
@@ -128,7 +129,7 b' class TestLFSApplication(object):'
128 u'oid': u'456',
129 u'oid': u'456',
129 u'size': u'1024'}
130 u'size': u'1024'}
130 ]
131 ]
131 assert response.json == {
132 assert json.loads(response.text) == {
132 'objects': expected_objects, 'transfer': 'basic'}
133 'objects': expected_objects, 'transfer': 'basic'}
133
134
134 def test_app_batch_api_upload(self, git_lfs_app, http_auth):
135 def test_app_batch_api_upload(self, git_lfs_app, http_auth):
@@ -150,7 +151,7 b' class TestLFSApplication(object):'
150 u'oid': u'123',
151 u'oid': u'123',
151 u'size': u'1024'}
152 u'size': u'1024'}
152 ]
153 ]
153 assert response.json == {
154 assert json.loads(response.text) == {
154 'objects': expected_objects, 'transfer': 'basic'}
155 'objects': expected_objects, 'transfer': 'basic'}
155
156
156 def test_app_verify_api_missing_data(self, git_lfs_app):
157 def test_app_verify_api_missing_data(self, git_lfs_app):
@@ -159,7 +160,7 b' class TestLFSApplication(object):'
159 '/repo/info/lfs/verify', params=params,
160 '/repo/info/lfs/verify', params=params,
160 status=400)
161 status=400)
161
162
162 assert response.json == {
163 assert json.loads(response.text) == {
163 u'message': u'missing oid and size in request data'}
164 u'message': u'missing oid and size in request data'}
164
165
165 def test_app_verify_api_missing_obj(self, git_lfs_app):
166 def test_app_verify_api_missing_obj(self, git_lfs_app):
@@ -168,7 +169,7 b' class TestLFSApplication(object):'
168 '/repo/info/lfs/verify', params=params,
169 '/repo/info/lfs/verify', params=params,
169 status=404)
170 status=404)
170
171
171 assert response.json == {
172 assert json.loads(response.text) == {
172 u'message': u'oid `missing` does not exists in store'}
173 u'message': u'oid `missing` does not exists in store'}
173
174
174 def test_app_verify_api_size_mismatch(self, git_lfs_app):
175 def test_app_verify_api_size_mismatch(self, git_lfs_app):
@@ -183,7 +184,7 b' class TestLFSApplication(object):'
183 response = git_lfs_app.post_json(
184 response = git_lfs_app.post_json(
184 '/repo/info/lfs/verify', params=params, status=422)
185 '/repo/info/lfs/verify', params=params, status=422)
185
186
186 assert response.json == {
187 assert json.loads(response.text) == {
187 u'message': u'requested file size mismatch '
188 u'message': u'requested file size mismatch '
188 u'store size:11 requested:1024'}
189 u'store size:11 requested:1024'}
189
190
@@ -199,7 +200,7 b' class TestLFSApplication(object):'
199 response = git_lfs_app.post_json(
200 response = git_lfs_app.post_json(
200 '/repo/info/lfs/verify', params=params)
201 '/repo/info/lfs/verify', params=params)
201
202
202 assert response.json == {
203 assert json.loads(response.text) == {
203 u'message': {u'size': u'ok', u'in_store': u'ok'}}
204 u'message': {u'size': u'ok', u'in_store': u'ok'}}
204
205
205 def test_app_download_api_oid_not_existing(self, git_lfs_app):
206 def test_app_download_api_oid_not_existing(self, git_lfs_app):
@@ -208,7 +209,7 b' class TestLFSApplication(object):'
208 response = git_lfs_app.get(
209 response = git_lfs_app.get(
209 '/repo/info/lfs/objects/{oid}'.format(oid=oid), status=404)
210 '/repo/info/lfs/objects/{oid}'.format(oid=oid), status=404)
210
211
211 assert response.json == {
212 assert json.loads(response.text) == {
212 u'message': u'requested file with oid `missing` not found in store'}
213 u'message': u'requested file with oid `missing` not found in store'}
213
214
214 def test_app_download_api(self, git_lfs_app):
215 def test_app_download_api(self, git_lfs_app):
@@ -229,7 +230,7 b' class TestLFSApplication(object):'
229 response = git_lfs_app.put(
230 response = git_lfs_app.put(
230 '/repo/info/lfs/objects/{oid}'.format(oid=oid), params='CONTENT')
231 '/repo/info/lfs/objects/{oid}'.format(oid=oid), params='CONTENT')
231
232
232 assert response.json == {u'upload': u'ok'}
233 assert json.loads(response.text) == {u'upload': u'ok'}
233
234
234 # verify that we actually wrote that OID
235 # verify that we actually wrote that OID
235 oid_path = os.path.join(git_lfs_app._store, oid)
236 oid_path = os.path.join(git_lfs_app._store, oid)
General Comments 0
You need to be logged in to leave comments. Login now