Commit 2cd28eac authored by Łukasz Nowak's avatar Łukasz Nowak Committed by Łukasz Nowak

tests: Restructure

In order for further development and features create mixin.
parent 6c731311
...@@ -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)
......
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