Commit 18a26c12 authored by Łukasz Nowak's avatar Łukasz Nowak

Follow spec in tests.

parent e3b11012
......@@ -41,15 +41,14 @@ class NCHandler(BaseHTTPServer.BaseHTTPRequestHandler):
self.end_headers()
self.wfile.write(out)
def do_POST(self):
def do_PUT(self):
path = os.path.abspath(os.path.join(self.tree, *self.path.split('/')))
if not os.path.exists(path):
os.makedirs(path)
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
data = self.rfile.read(int(self.headers.getheader('content-length')))
cksum = hashlib.sha512(data).hexdigest()
if 'shadir' in path:
d = json.loads(data)
path = os.path.join(path, d[0]['urlmd5'])
data = json.dumps([d])
if os.path.exists(path):
f = open(path, 'r')
......@@ -61,6 +60,25 @@ class NCHandler(BaseHTTPServer.BaseHTTPRequestHandler):
json_data_list = json.loads(file_data)
json_data_list.append(d)
data = json.dumps(json_data_list)
else:
raise ValueError('shacache shall use POST')
open(path, 'wb').write(data)
self.send_response(201)
self.send_header('Content-Length', str(len(cksum)))
self.send_header('Content-Type', 'text/html')
self.end_headers()
self.wfile.write(cksum)
return
def do_POST(self):
path = os.path.abspath(os.path.join(self.tree, *self.path.split('/')))
if not os.path.exists(path):
os.makedirs(path)
data = self.rfile.read(int(self.headers.getheader('content-length')))
cksum = hashlib.sha512(data).hexdigest()
if 'shadir' in path:
raise ValueError('shadir shall use PUT')
else:
path = os.path.join(path, cksum)
......@@ -182,15 +200,17 @@ class OnlineTest(OnlineMixin, unittest.TestCase):
"""Check scenario with shadir used"""
nc = NetworkcacheClient(self.shacache, self.shadir)
urlmd5 = str(random.random())
nc.upload(self.test_data, urlmd5, file_name='my file')
result = nc.select(urlmd5)
key = 'somekey' + str(random.random())
nc.upload(self.test_data, urlmd5, file_name='my file', key=key)
result = nc.select(key)
self.assertEqual(result.read(), self.test_string)
def test_upload_shadir_no_filename(self):
"""Check scenario with shadir used, but not filename passed"""
nc = NetworkcacheClient(self.shacache, self.shadir)
urlmd5 = str(random.random())
self.assertRaises(ValueError, nc.upload, self.test_data, urlmd5)
self.assertRaises(ValueError, nc.upload, self.test_data, urlmd5,
key='somekey')
def test_upload_twice_same(self):
nc = NetworkcacheClient(self.shacache, self.shadir)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment