Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.libnetworkcache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
slapos.libnetworkcache
Commits
18a26c12
Commit
18a26c12
authored
Aug 23, 2011
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Follow spec in tests.
parent
e3b11012
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
7 deletions
+27
-7
slapos/libnetworkcachetests.py
slapos/libnetworkcachetests.py
+27
-7
No files found.
slapos/libnetworkcachetests.py
View file @
18a26c12
...
...
@@ -41,15 +41,14 @@ class NCHandler(BaseHTTPServer.BaseHTTPRequestHandler):
self
.
end_headers
()
self
.
wfile
.
write
(
out
)
def
do_P
OS
T
(
self
):
def
do_P
U
T
(
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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment