Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
K
kedifa
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
Aurel
kedifa
Commits
2cd28eac
Commit
2cd28eac
authored
Mar 28, 2019
by
Łukasz Nowak
Committed by
Łukasz Nowak
Apr 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: Restructure
In order for further development and features create mixin.
parent
6c731311
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
54 deletions
+54
-54
kedifa/test.py
kedifa/test.py
+54
-54
No files found.
kedifa/test.py
View file @
2cd28eac
...
@@ -60,7 +60,16 @@ def captured_output():
...
@@ -60,7 +60,16 @@ def captured_output():
sys
.
stdout
,
sys
.
stderr
=
old_out
,
old_err
sys
.
stdout
,
sys
.
stderr
=
old_out
,
old_err
class
KedifaIntegrationTest
(
unittest
.
TestCase
):
class
KedifaMixin
(
object
):
def
setUp
(
self
):
self
.
testdir
=
tempfile
.
mkdtemp
()
def
cleanTestDir
():
shutil
.
rmtree
(
self
.
testdir
)
self
.
addCleanup
(
cleanTestDir
)
class
KedifaMixinCaucase
(
KedifaMixin
):
def
createKey
(
self
):
def
createKey
(
self
):
key
=
rsa
.
generate_private_key
(
key
=
rsa
.
generate_private_key
(
public_exponent
=
65537
,
key_size
=
2048
,
backend
=
default_backend
())
public_exponent
=
65537
,
key_size
=
2048
,
backend
=
default_backend
())
...
@@ -231,40 +240,6 @@ class KedifaIntegrationTest(unittest.TestCase):
...
@@ -231,40 +240,6 @@ class KedifaIntegrationTest(unittest.TestCase):
else
:
else
:
raise
raise
def
_getter_get
(
self
,
url
,
certificate
,
destination
):
getter
(
url
,
'--out'
,
destination
,
'--server-ca-certificate'
,
self
.
ca_crt_pem
,
'--identity'
,
certificate
)
def
getter_get_raises
(
self
,
url
,
certificate
):
destination
=
tempfile
.
NamedTemporaryFile
(
dir
=
self
.
testdir
).
name
with
self
.
assertRaises
(
SystemExit
)
as
assertRaisesContext
:
self
.
_getter_get
(
url
,
certificate
,
destination
)
return
destination
,
assertRaisesContext
.
exception
.
code
def
getter_get
(
self
,
url
,
certificate
):
destination
=
tempfile
.
NamedTemporaryFile
(
dir
=
self
.
testdir
).
name
self
.
_getter_get
(
url
,
certificate
,
destination
)
return
destination
def
_updater_get
(
self
,
url
,
certificate
,
destination
):
mapping
=
tempfile
.
NamedTemporaryFile
(
dir
=
self
.
testdir
,
delete
=
False
)
mapping
.
write
(
"%s %s"
%
(
url
,
destination
))
mapping
.
close
()
updater
(
'--once'
,
'--server-ca-certificate'
,
self
.
ca_crt_pem
,
'--identity'
,
certificate
,
mapping
.
name
,
)
def
updater_get
(
self
,
url
,
certificate
):
destination
=
tempfile
.
NamedTemporaryFile
(
dir
=
self
.
testdir
).
name
self
.
_updater_get
(
url
,
certificate
,
destination
)
return
destination
def
reserveReference
(
self
,
*
args
,
**
kwargs
):
def
reserveReference
(
self
,
*
args
,
**
kwargs
):
result
=
requests
.
post
(
result
=
requests
.
post
(
self
.
kedifa_url
+
'reserve-id'
,
self
.
kedifa_url
+
'reserve-id'
,
...
@@ -291,19 +266,9 @@ class KedifaIntegrationTest(unittest.TestCase):
...
@@ -291,19 +266,9 @@ class KedifaIntegrationTest(unittest.TestCase):
return
reserved_reference
return
reserved_reference
def
requests_get
(
self
,
*
args
,
**
kwargs
):
return
requests
.
get
(
verify
=
self
.
ca_crt_pem
,
*
args
,
**
kwargs
)
def
requests_put
(
self
,
*
args
,
**
kwargs
):
return
requests
.
put
(
verify
=
self
.
ca_crt_pem
,
*
args
,
**
kwargs
)
def
setUp
(
self
):
def
setUp
(
self
):
super
(
KedifaMixinCaucase
,
self
).
setUp
()
self
.
createPem
()
self
.
createPem
()
self
.
testdir
=
tempfile
.
mkdtemp
()
def
cleanTestDir
():
shutil
.
rmtree
(
self
.
testdir
)
self
.
addCleanup
(
cleanTestDir
)
self
.
setUpCaucase
()
self
.
setUpCaucase
()
self
.
kedifa_ip
=
os
.
environ
[
'SLAPOS_TEST_IPV6'
]
self
.
kedifa_ip
=
os
.
environ
[
'SLAPOS_TEST_IPV6'
]
...
@@ -312,6 +277,48 @@ class KedifaIntegrationTest(unittest.TestCase):
...
@@ -312,6 +277,48 @@ class KedifaIntegrationTest(unittest.TestCase):
self
.
setUpKedifa
(
self
.
kedifa_ip
)
self
.
setUpKedifa
(
self
.
kedifa_ip
)
self
.
reference
=
self
.
reserveReference
()
self
.
reference
=
self
.
reserveReference
()
def
requests_get
(
self
,
*
args
,
**
kwargs
):
return
requests
.
get
(
verify
=
self
.
ca_crt_pem
,
*
args
,
**
kwargs
)
def
requests_put
(
self
,
*
args
,
**
kwargs
):
return
requests
.
put
(
verify
=
self
.
ca_crt_pem
,
*
args
,
**
kwargs
)
class
KedifaIntegrationTest
(
KedifaMixinCaucase
,
unittest
.
TestCase
):
def
_getter_get
(
self
,
url
,
certificate
,
destination
):
getter
(
url
,
'--out'
,
destination
,
'--server-ca-certificate'
,
self
.
ca_crt_pem
,
'--identity'
,
certificate
)
def
getter_get_raises
(
self
,
url
,
certificate
):
destination
=
tempfile
.
NamedTemporaryFile
(
dir
=
self
.
testdir
).
name
with
self
.
assertRaises
(
SystemExit
)
as
assertRaisesContext
:
self
.
_getter_get
(
url
,
certificate
,
destination
)
return
destination
,
assertRaisesContext
.
exception
.
code
def
getter_get
(
self
,
url
,
certificate
):
destination
=
tempfile
.
NamedTemporaryFile
(
dir
=
self
.
testdir
).
name
self
.
_getter_get
(
url
,
certificate
,
destination
)
return
destination
def
_updater_get
(
self
,
url
,
certificate
,
destination
):
mapping
=
tempfile
.
NamedTemporaryFile
(
dir
=
self
.
testdir
,
delete
=
False
)
mapping
.
write
(
"%s %s"
%
(
url
,
destination
))
mapping
.
close
()
updater
(
'--once'
,
'--server-ca-certificate'
,
self
.
ca_crt_pem
,
'--identity'
,
certificate
,
mapping
.
name
,
)
def
updater_get
(
self
,
url
,
certificate
):
destination
=
tempfile
.
NamedTemporaryFile
(
dir
=
self
.
testdir
).
name
self
.
_updater_get
(
url
,
certificate
,
destination
)
return
destination
def
test_GET_root
(
self
):
def
test_GET_root
(
self
):
result
=
self
.
requests_get
(
self
.
kedifa_url
)
result
=
self
.
requests_get
(
self
.
kedifa_url
)
# KeDiFa does not support nothing on / so for now it just raises
# KeDiFa does not support nothing on / so for now it just raises
...
@@ -1081,14 +1088,7 @@ class KedifaIntegrationTest(unittest.TestCase):
...
@@ -1081,14 +1088,7 @@ class KedifaIntegrationTest(unittest.TestCase):
)
)
class KedifaUpdaterTest(unittest.TestCase):
class KedifaUpdaterMappingTest(KedifaMixin, unittest.TestCase):
def setUp(self):
self.testdir = tempfile.mkdtemp()
def cleanTestDir():
shutil.rmtree(self.testdir)
self.addCleanup(cleanTestDir)
def setupMapping(self, mapping_content=''):
def setupMapping(self, mapping_content=''):
mapping = tempfile.NamedTemporaryFile(dir=self.testdir, delete=False)
mapping = tempfile.NamedTemporaryFile(dir=self.testdir, delete=False)
mapping.write(mapping_content)
mapping.write(mapping_content)
...
...
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