def test_missing(self): files = [ os.path.join(BASE_PATH, 'isolateserver_archive', f) for f in ('small_file.txt', 'empty_file.txt') ] sha1s = map(isolateserver_archive.sha1_file, files) sha1encoded = ''.join(map(binascii.unhexlify, sha1s)) compressed = [ zlib.compress( open(f, 'rb').read(), isolateserver_archive.compression_level(f)) for f in files ] path = 'http://random/' self._requests = [ (path + 'content/get_token', {}, StringIO.StringIO('foo bar')), ( path + 'content/contains/default-gzip?token=foo%20bar', {'data': sha1encoded, 'content_type': 'application/octet-stream'}, StringIO.StringIO('\0\0'), ), ( path + 'content/store/default-gzip/%s?token=foo%%20bar' % sha1s[0], {'data': compressed[0], 'content_type': 'application/octet-stream'}, StringIO.StringIO('ok'), ), ( path + 'content/store/default-gzip/%s?token=foo%%20bar' % sha1s[1], {'data': compressed[1], 'content_type': 'application/octet-stream'}, StringIO.StringIO('ok'), ), ] result = isolateserver_archive.main(['--remote', path] + files) self.assertEqual(0, result)
def test_present(self): files = [ os.path.join(BASE_PATH, 'isolateserver_archive', f) for f in ('small_file.txt', 'empty_file.txt') ] sha1encoded = ''.join( binascii.unhexlify(isolateserver_archive.sha1_file(f)) for f in files) path = 'http://random/' self._requests = [ (path + 'content/get_token', {}, StringIO.StringIO('foo bar')), ( path + 'content/contains/default-gzip?token=foo%20bar', {'data': sha1encoded, 'content_type': 'application/octet-stream'}, StringIO.StringIO('\1\1'), ), ] result = isolateserver_archive.main(['--remote', path] + files) self.assertEqual(0, result)