diff options
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/units/client/journal.py | 18 | ||||
-rwxr-xr-x | tests/units/client/offline_routes.py | 49 | ||||
-rwxr-xr-x | tests/units/client/online_routes.py | 49 | ||||
-rwxr-xr-x | tests/units/client/server_routes.py | 50 | ||||
-rwxr-xr-x | tests/units/db/routes.py | 102 |
5 files changed, 179 insertions, 89 deletions
diff --git a/tests/units/client/journal.py b/tests/units/client/journal.py index fd36a2a..30c67f8 100755 --- a/tests/units/client/journal.py +++ b/tests/units/client/journal.py @@ -107,32 +107,32 @@ class JournalTest(tests.Test): request.path = ['journal'] response = Response() self.assertEqual([ - {'guid': 'guid1', 'title': 'title1', 'description': 'description1', 'preview': url + 'guid1/preview'}, - {'guid': 'guid2', 'title': 'title2', 'description': 'description2', 'preview': url + 'guid2/preview'}, - {'guid': 'guid3', 'title': 'title3', 'description': 'description3', 'preview': url + 'guid3/preview'}, + {'guid': 'guid1', 'title': 'title1', 'description': 'description1', 'preview': {'url': url + 'guid1/preview'}}, + {'guid': 'guid2', 'title': 'title2', 'description': 'description2', 'preview': {'url': url + 'guid2/preview'}}, + {'guid': 'guid3', 'title': 'title3', 'description': 'description3', 'preview': {'url': url + 'guid3/preview'}}, ], ds.journal_find(request, response)['result']) request = Request(offset=1, limit=1, reply=['uid', 'title', 'description', 'preview']) request.path = ['journal'] self.assertEqual([ - {'guid': 'guid2', 'title': 'title2', 'description': 'description2', 'preview': url + 'guid2/preview'}, + {'guid': 'guid2', 'title': 'title2', 'description': 'description2', 'preview': {'url': url + 'guid2/preview'}}, ], ds.journal_find(request, response)['result']) request = Request(query='title3', reply=['uid', 'title', 'description', 'preview']) request.path = ['journal'] self.assertEqual([ - {'guid': 'guid3', 'title': 'title3', 'description': 'description3', 'preview': url + 'guid3/preview'}, + {'guid': 'guid3', 'title': 'title3', 'description': 'description3', 'preview': {'url': url + 'guid3/preview'}}, ], ds.journal_find(request, response)['result']) request = Request(order_by=['+title'], reply=['uid', 'title', 'description', 'preview']) request.path = ['journal'] self.assertEqual([ - {'guid': 'guid3', 'title': 'title3', 'description': 'description3', 'preview': url + 'guid3/preview'}, - {'guid': 'guid2', 'title': 'title2', 'description': 'description2', 'preview': url + 'guid2/preview'}, - {'guid': 'guid1', 'title': 'title1', 'description': 'description1', 'preview': url + 'guid1/preview'}, + {'guid': 'guid3', 'title': 'title3', 'description': 'description3', 'preview': {'url': url + 'guid3/preview'}}, + {'guid': 'guid2', 'title': 'title2', 'description': 'description2', 'preview': {'url': url + 'guid2/preview'}}, + {'guid': 'guid1', 'title': 'title1', 'description': 'description1', 'preview': {'url': url + 'guid1/preview'}}, ], ds.journal_find(request, response)['result']) @@ -146,7 +146,7 @@ class JournalTest(tests.Test): request.path = ['journal', 'guid1'] response = Response() self.assertEqual( - {'guid': 'guid1', 'title': 'title1', 'description': 'description1', 'preview': url + 'guid1/preview'}, + {'guid': 'guid1', 'title': 'title1', 'description': 'description1', 'preview': {'url': url + 'guid1/preview'}}, ds.journal_get(request, response)) def test_GetPropRequest(self): diff --git a/tests/units/client/offline_routes.py b/tests/units/client/offline_routes.py index a163769..866e5d9 100755 --- a/tests/units/client/offline_routes.py +++ b/tests/units/client/offline_routes.py @@ -146,27 +146,48 @@ class OfflineRoutes(tests.Test): 'summary': 'summary', 'description': 'description', }) - ipc.request('PUT', ['context', guid, 'preview'], 'image') + blob = 'preview_blob' + ipc.request('PUT', ['context', guid, 'preview'], blob) self.assertEqual( - 'image', + blob, ipc.request('GET', ['context', guid, 'preview']).content) - self.assertEqual( - {'preview': 'http://127.0.0.1:5555/context/%s/preview' % guid}, - ipc.get(['context', guid], reply=['preview'])) - self.assertEqual( - [{'preview': 'http://127.0.0.1:5555/context/%s/preview' % guid}], - ipc.get(['context'], reply=['preview'])['result']) + self.assertEqual({ + 'preview': { + 'url': 'http://127.0.0.1:5555/context/%s/preview' % guid, + 'blob_size': len(blob), + 'digest': hashlib.sha1(blob).hexdigest(), + 'mime_type': 'image/png', + }, + }, + ipc.get(['context', guid], reply=['preview'])) + self.assertEqual([{ + 'preview': { + 'url': 'http://127.0.0.1:5555/context/%s/preview' % guid, + 'blob_size': len(blob), + 'digest': hashlib.sha1(blob).hexdigest(), + 'mime_type': 'image/png', + }, + }], + ipc.get(['context'], reply=['preview'])['result']) self.assertEqual( file(src_root + '/sugar_network/static/httpdocs/images/package.png').read(), ipc.request('GET', ['context', guid, 'icon']).content) - self.assertEqual( - {'icon': 'http://127.0.0.1:5555/static/images/package.png'}, - ipc.get(['context', guid], reply=['icon'])) - self.assertEqual( - [{'icon': 'http://127.0.0.1:5555/static/images/package.png'}], - ipc.get(['context'], reply=['icon'])['result']) + self.assertEqual({ + 'icon': { + 'url': 'http://127.0.0.1:5555/static/images/package.png', + 'mime_type': 'image/png', + }, + }, + ipc.get(['context', guid], reply=['icon'])) + self.assertEqual([{ + 'icon': { + 'url': 'http://127.0.0.1:5555/static/images/package.png', + 'mime_type': 'image/png', + }, + }], + ipc.get(['context'], reply=['icon'])['result']) def test_favorite(self): ipc = self.start_offline_client() diff --git a/tests/units/client/online_routes.py b/tests/units/client/online_routes.py index ddf8a4c..064a9bb 100755 --- a/tests/units/client/online_routes.py +++ b/tests/units/client/online_routes.py @@ -233,27 +233,48 @@ class OnlineRoutes(tests.Test): 'summary': 'summary', 'description': 'description', }) - ipc.request('PUT', ['context', guid, 'preview'], 'image') + blob = 'preview_blob' + ipc.request('PUT', ['context', guid, 'preview'], blob, headers={'content-type': 'image/png'}) self.assertEqual( - 'image', + blob, ipc.request('GET', ['context', guid, 'preview']).content) - self.assertEqual( - {'preview': 'http://127.0.0.1:8888/context/%s/preview' % guid}, - ipc.get(['context', guid], reply=['preview'])) - self.assertEqual( - [{'preview': 'http://127.0.0.1:8888/context/%s/preview' % guid}], - ipc.get(['context'], reply=['preview'])['result']) + self.assertEqual({ + 'preview': { + 'url': 'http://127.0.0.1:8888/context/%s/preview' % guid, + 'blob_size': len(blob), + 'digest': hashlib.sha1(blob).hexdigest(), + 'mime_type': 'image/png', + }, + }, + ipc.get(['context', guid], reply=['preview'])) + self.assertEqual([{ + 'preview': { + 'url': 'http://127.0.0.1:8888/context/%s/preview' % guid, + 'blob_size': len(blob), + 'digest': hashlib.sha1(blob).hexdigest(), + 'mime_type': 'image/png', + }, + }], + ipc.get(['context'], reply=['preview'])['result']) self.assertEqual( file(src_root + '/sugar_network/static/httpdocs/images/package.png').read(), ipc.request('GET', ['context', guid, 'icon']).content) - self.assertEqual( - {'icon': 'http://127.0.0.1:8888/static/images/package.png'}, - ipc.get(['context', guid], reply=['icon'])) - self.assertEqual( - [{'icon': 'http://127.0.0.1:8888/static/images/package.png'}], - ipc.get(['context'], reply=['icon'])['result']) + self.assertEqual({ + 'icon': { + 'url': 'http://127.0.0.1:8888/static/images/package.png', + 'mime_type': 'image/png', + }, + }, + ipc.get(['context', guid], reply=['icon'])) + self.assertEqual([{ + 'icon': { + 'url': 'http://127.0.0.1:8888/static/images/package.png', + 'mime_type': 'image/png', + }, + }], + ipc.get(['context'], reply=['icon'])['result']) def test_favorite(self): local = self.start_online_client() diff --git a/tests/units/client/server_routes.py b/tests/units/client/server_routes.py index 47282ce..6bbb955 100755 --- a/tests/units/client/server_routes.py +++ b/tests/units/client/server_routes.py @@ -3,6 +3,7 @@ import os import shutil +import hashlib from os.path import exists from __init__ import tests, src_root @@ -129,27 +130,48 @@ class ServerRoutesTest(tests.Test): 'summary': 'summary', 'description': 'description', }) - ipc.request('PUT', ['context', guid, 'preview'], 'image') + blob = 'preview_blob' + ipc.request('PUT', ['context', guid, 'preview'], blob) self.assertEqual( - 'image', + blob, ipc.request('GET', ['context', guid, 'preview']).content) - self.assertEqual( - {'preview': 'http://127.0.0.1:5555/context/%s/preview' % guid}, - ipc.get(['context', guid], reply=['preview'])) - self.assertEqual( - [{'preview': 'http://127.0.0.1:5555/context/%s/preview' % guid}], - ipc.get(['context'], reply=['preview'])['result']) + self.assertEqual({ + 'preview': { + 'url': 'http://127.0.0.1:5555/context/%s/preview' % guid, + 'blob_size': len(blob), + 'digest': hashlib.sha1(blob).hexdigest(), + 'mime_type': 'image/png', + }, + }, + ipc.get(['context', guid], reply=['preview'])) + self.assertEqual([{ + 'preview': { + 'url': 'http://127.0.0.1:5555/context/%s/preview' % guid, + 'blob_size': len(blob), + 'digest': hashlib.sha1(blob).hexdigest(), + 'mime_type': 'image/png', + }, + }], + ipc.get(['context'], reply=['preview'])['result']) self.assertEqual( file(src_root + '/sugar_network/static/httpdocs/images/package.png').read(), ipc.request('GET', ['context', guid, 'icon']).content) - self.assertEqual( - {'icon': 'http://127.0.0.1:5555/static/images/package.png'}, - ipc.get(['context', guid], reply=['icon'])) - self.assertEqual( - [{'icon': 'http://127.0.0.1:5555/static/images/package.png'}], - ipc.get(['context'], reply=['icon'])['result']) + self.assertEqual({ + 'icon': { + 'url': 'http://127.0.0.1:5555/static/images/package.png', + 'mime_type': 'image/png', + }, + }, + ipc.get(['context', guid], reply=['icon'])) + self.assertEqual([{ + 'icon': { + 'url': 'http://127.0.0.1:5555/static/images/package.png', + 'mime_type': 'image/png', + }, + }], + ipc.get(['context'], reply=['icon'])['result']) def test_PopulateNode(self): os.makedirs('disk/sugar-network') diff --git a/tests/units/db/routes.py b/tests/units/db/routes.py index 95aeb4e..51cd892 100755 --- a/tests/units/db/routes.py +++ b/tests/units/db/routes.py @@ -254,28 +254,40 @@ class RoutesTest(tests.Test): self.volume = db.Volume(tests.tmpdir, [TestDocument], lambda event: None) guid = self.call('POST', path=['testdocument'], content={}) - self.call('PUT', path=['testdocument', guid, 'blob'], content='blob') + blob = 'blob' + self.call('PUT', path=['testdocument', guid, 'blob'], content=blob) blob_path = tests.tmpdir + '/testdocument/%s/%s/blob' % (guid[:2], guid) blob_meta = { 'seqno': 2, 'blob': blob_path + '.blob', - 'blob_size': 4, - 'digest': hashlib.sha1('blob').hexdigest(), + 'blob_size': len(blob), + 'digest': hashlib.sha1(blob).hexdigest(), 'mime_type': 'application/octet-stream', 'mtime': int(os.stat(blob_path).st_mtime), } self.assertEqual('blob', file(self.call('GET', path=['testdocument', guid, 'blob'])['blob']).read()) - self.assertEqual( - {'guid': guid, 'blob': 'http://localhost/testdocument/%s/blob' % guid}, - self.call('GET', path=['testdocument', guid], reply=['guid', 'blob'], host='localhost')) - - self.assertEqual([ - {'guid': guid, 'blob': 'http://localhost/testdocument/%s/blob' % guid}, - ], - self.call('GET', path=['testdocument'], reply=['guid', 'blob'], host='localhost')['result']) + self.assertEqual({ + 'blob': { + 'url': 'http://localhost/testdocument/%s/blob' % guid, + 'blob_size': len(blob), + 'digest': hashlib.sha1(blob).hexdigest(), + 'mime_type': u'application/octet-stream', + }, + }, + self.call('GET', path=['testdocument', guid], reply=['blob'], host='localhost')) + + self.assertEqual([{ + 'blob': { + 'url': 'http://localhost/testdocument/%s/blob' % guid, + 'blob_size': len(blob), + 'digest': hashlib.sha1(blob).hexdigest(), + 'mime_type': u'application/octet-stream', + }, + }], + self.call('GET', path=['testdocument'], reply=['blob'], host='localhost')['result']) def test_GetBLOBsByUrls(self): @@ -286,37 +298,51 @@ class RoutesTest(tests.Test): return value self.volume = db.Volume(tests.tmpdir, [TestDocument], lambda event: None) - guid = self.call('POST', path=['testdocument'], content={}) + guid1 = self.call('POST', path=['testdocument'], content={}) - self.assertRaises(http.NotFound, self.call, 'GET', path=['testdocument', guid, 'blob']) + self.assertRaises(http.NotFound, self.call, 'GET', path=['testdocument', guid1, 'blob']) self.assertEqual( - {'blob': 'http://127.0.0.1/testdocument/%s/blob' % guid}, - self.call('GET', path=['testdocument', guid], reply=['blob'], host='127.0.0.1')) - self.assertEqual([ - {'blob': 'http://127.0.0.1/testdocument/%s/blob' % guid}, - ], - self.call('GET', path=['testdocument'], reply=['blob'], host='127.0.0.1')['result']) + {'blob': {'url': 'http://127.0.0.1/testdocument/%s/blob' % guid1}}, + self.call('GET', path=['testdocument', guid1], reply=['blob'], host='127.0.0.1')) - self.call('PUT', path=['testdocument', guid, 'blob'], content='file') - self.assertEqual('file', file(self.call('GET', path=['testdocument', guid, 'blob'])['blob']).read()) - self.assertEqual( - {'blob': 'http://127.0.0.1/testdocument/%s/blob' % guid}, - self.call('GET', path=['testdocument', guid], reply=['blob'], host='127.0.0.1')) - self.assertEqual([ - {'blob': 'http://127.0.0.1/testdocument/%s/blob' % guid}, - ], - self.call('GET', path=['testdocument'], reply=['blob'], host='127.0.0.1')['result']) + blob = 'file' + guid2 = self.call('POST', path=['testdocument'], content={'blob': blob}) + self.assertEqual('file', file(self.call('GET', path=['testdocument', guid2, 'blob'])['blob']).read()) + self.assertEqual({ + 'blob': { + 'url': 'http://127.0.0.1/testdocument/%s/blob' % guid2, + 'blob_size': len(blob), + 'digest': hashlib.sha1(blob).hexdigest(), + 'mime_type': u'application/octet-stream', + }, + }, + self.call('GET', path=['testdocument', guid2], reply=['blob'], host='127.0.0.1')) + + guid3 = self.call('POST', path=['testdocument'], content={'blob': {'url': 'http://foo'}}, content_type='application/json') + self.assertEqual('http://foo', self.call('GET', path=['testdocument', guid3, 'blob'])['url']) + self.assertEqual({ + 'blob': { + 'url': 'http://foo', + }, + }, + self.call('GET', path=['testdocument', guid3], reply=['blob'], host='127.0.0.1')) - self.call('PUT', path=['testdocument', guid, 'blob'], content={'url': 'http://foo'}, - content_type='application/json') - self.assertEqual('http://foo', self.call('GET', path=['testdocument', guid, 'blob'])['url']) self.assertEqual( - {'blob': 'http://foo'}, - self.call('GET', path=['testdocument', guid], reply=['blob'], host='127.0.0.1')) - self.assertEqual([ - {'blob': 'http://foo'}, - ], - self.call('GET', path=['testdocument'], reply=['blob'], host='127.0.0.1')['result']) + sorted([ + {'blob': { + 'url': 'http://127.0.0.1/testdocument/%s/blob' % guid1, + }}, + { 'blob': { + 'url': 'http://127.0.0.1/testdocument/%s/blob' % guid2, + 'blob_size': len(blob), + 'digest': hashlib.sha1(blob).hexdigest(), + 'mime_type': u'application/octet-stream', + }}, + { 'blob': { + 'url': 'http://foo', + }}, + ]), + sorted(self.call('GET', path=['testdocument'], reply=['blob'], host='127.0.0.1')['result'])) def test_CommandsGetAbsentBlobs(self): @@ -336,7 +362,7 @@ class RoutesTest(tests.Test): self.assertEqual('value', self.call('GET', path=['testdocument', guid, 'prop'])) self.assertRaises(http.NotFound, self.call, 'GET', path=['testdocument', guid, 'blob']) self.assertEqual( - {'blob': 'http://localhost/testdocument/%s/blob' % guid}, + {'blob': {'url': 'http://localhost/testdocument/%s/blob' % guid}}, self.call('GET', path=['testdocument', guid], reply=['blob'], host='localhost')) def test_Command_ReplyForGET(self): |