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
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Łukasz Nowak
slapos.libnetworkcache
Commits
53709925
Commit
53709925
authored
Aug 23, 2011
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement negative scenarios.
parent
df29bab7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
16 deletions
+68
-16
slapos/libnetworkcachetests.py
slapos/libnetworkcachetests.py
+68
-16
No files found.
slapos/libnetworkcachetests.py
View file @
53709925
...
...
@@ -11,7 +11,7 @@ import tempfile
import
threading
import
time
import
unittest
from
slapos.libnetworkcache
import
NetworkcacheClient
from
slapos.libnetworkcache
import
NetworkcacheClient
,
UploadError
from
slapos.signature
import
parseArgument
,
\
createPrivateKeyAndCertificateFile
...
...
@@ -72,6 +72,21 @@ class NCHandler(BaseHTTPServer.BaseHTTPRequestHandler):
self
.
wfile
.
write
(
cksum
)
return
class
NCHandlerPOST200
(
NCHandler
):
def
do_POST
(
self
):
self
.
send_response
(
200
)
return
class
NCHandlerReturnWrong
(
NCHandler
):
def
do_POST
(
self
):
cksum
=
'incorrect'
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
class
Server
(
BaseHTTPServer
.
HTTPServer
):
def
__init__
(
self
,
tree
,
*
args
):
BaseHTTPServer
.
HTTPServer
.
__init__
(
self
,
*
args
)
...
...
@@ -116,17 +131,19 @@ def wait(host, port):
else
:
raise
class
OnlineTest
(
unittest
.
TestCase
):
"""Online tests against real HTTP server"""
def
setUp
(
self
):
self
.
host
=
"127.0.0.1"
self
.
port
=
8080
self
.
tree
=
tempfile
.
mkdtemp
()
class
OnlineMixin
:
def
_start_nc
(
self
):
self
.
thread
=
threading
.
Thread
(
target
=
_run_nc
,
args
=
(
self
.
tree
,
self
.
host
,
self
.
port
))
self
.
thread
.
setDaemon
(
True
)
self
.
thread
.
start
()
wait
(
self
.
host
,
self
.
port
)
def
setUp
(
self
):
self
.
host
=
"127.0.0.1"
self
.
port
=
8080
self
.
tree
=
tempfile
.
mkdtemp
()
self
.
_start_nc
()
self
.
url
=
'http://%s:%s/'
%
(
self
.
host
,
self
.
port
)
self
.
shacache
=
os
.
environ
.
get
(
'TEST_SHA_CACHE'
,
self
.
url
+
'shacache'
)
...
...
@@ -140,24 +157,21 @@ class OnlineTest(unittest.TestCase):
self
.
test_data
.
seek
(
0
)
def
tearDown
(
self
):
httplib
.
HTTPConnection
(
self
.
host
,
self
.
port
).
request
(
'KILL'
,
'/'
)
try
:
httplib
.
HTTPConnection
(
self
.
host
,
self
.
port
).
request
(
'KILL'
,
'/'
)
except
Exception
:
pass
if
self
.
thread
is
not
None
:
self
.
thread
.
join
()
shutil
.
rmtree
(
self
.
tree
)
class
OnlineTest
(
OnlineMixin
,
unittest
.
TestCase
):
"""Online tests against real HTTP server"""
def
test_upload
(
self
):
nc
=
NetworkcacheClient
(
self
.
shacache
,
self
.
shadir
)
nc
.
upload
(
self
.
test_data
)
def
test_upload_wrong_return_code
(
self
):
"""Check reaction on HTTP return code different then 201"""
raise
NotImplementedError
def
test_upload_wrong_return_sha
(
self
):
"""Check reaction in case of wrong sha returned"""
raise
NotImplementedError
def
test_upload_shadir
(
self
):
"""Check scenario with shadir used"""
nc
=
NetworkcacheClient
(
self
.
shacache
,
self
.
shadir
)
...
...
@@ -198,6 +212,44 @@ class OnlineTest(unittest.TestCase):
# is it correctly downloaded
self
.
assertEqual
(
result
.
read
(),
self
.
test_string
)
def
_run_nc_POST200
(
tree
,
host
,
port
):
server_address
=
(
host
,
port
)
httpd
=
Server
(
tree
,
server_address
,
NCHandlerPOST200
)
httpd
.
serve_forever
()
class
OnlineTestPOST200
(
OnlineMixin
,
unittest
.
TestCase
):
def
_start_nc
(
self
):
self
.
thread
=
threading
.
Thread
(
target
=
_run_nc_POST200
,
args
=
(
self
.
tree
,
self
.
host
,
self
.
port
))
self
.
thread
.
setDaemon
(
True
)
self
.
thread
.
start
()
wait
(
self
.
host
,
self
.
port
)
def
test_upload_wrong_return_code
(
self
):
"""Check reaction on HTTP return code different then 201"""
nc
=
NetworkcacheClient
(
self
.
shacache
,
self
.
shadir
)
self
.
assertRaises
(
UploadError
,
nc
.
upload
,
self
.
test_data
)
def
_run_nc_POSTWrongChecksum
(
tree
,
host
,
port
):
server_address
=
(
host
,
port
)
httpd
=
Server
(
tree
,
server_address
,
NCHandlerReturnWrong
)
httpd
.
serve_forever
()
class
OnlineTestWrongChecksum
(
OnlineMixin
,
unittest
.
TestCase
):
def
_start_nc
(
self
):
self
.
thread
=
threading
.
Thread
(
target
=
_run_nc_POSTWrongChecksum
,
args
=
(
self
.
tree
,
self
.
host
,
self
.
port
))
self
.
thread
.
setDaemon
(
True
)
self
.
thread
.
start
()
wait
(
self
.
host
,
self
.
port
)
def
test_upload_wrong_return_sha
(
self
):
"""Check reaction in case of wrong sha returned"""
httplib
.
HTTPConnection
(
self
.
host
,
self
.
port
).
request
(
'SPECIAL'
,
'/cksum/invalid'
)
nc
=
NetworkcacheClient
(
self
.
shacache
,
self
.
shadir
)
self
.
assertRaises
(
UploadError
,
nc
.
upload
,
self
.
test_data
)
class
LibNetworkCacheMixin
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
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