Commit 2cd28eac by Ł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():
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):
key = rsa.generate_private_key(
public_exponent=65537, key_size=2048, backend=default_backend())
......@@ -231,40 +240,6 @@ class KedifaIntegrationTest(unittest.TestCase):
else:
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):
result = requests.post(
self.kedifa_url + 'reserve-id',
......@@ -291,19 +266,9 @@ class KedifaIntegrationTest(unittest.TestCase):
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):
super(KedifaMixinCaucase, self).setUp()
self.createPem()
self.testdir = tempfile.mkdtemp()
def cleanTestDir():
shutil.rmtree(self.testdir)
self.addCleanup(cleanTestDir)
self.setUpCaucase()
self.kedifa_ip = os.environ['SLAPOS_TEST_IPV6']
......@@ -312,6 +277,48 @@ class KedifaIntegrationTest(unittest.TestCase):
self.setUpKedifa(self.kedifa_ip)
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):
result = self.requests_get(self.kedifa_url)
# KeDiFa does not support nothing on / so for now it just raises
......@@ -1081,14 +1088,7 @@ class KedifaIntegrationTest(unittest.TestCase):
)
class KedifaUpdaterTest(unittest.TestCase):
def setUp(self):
self.testdir = tempfile.mkdtemp()
def cleanTestDir():
shutil.rmtree(self.testdir)
self.addCleanup(cleanTestDir)
class KedifaUpdaterMappingTest(KedifaMixin, unittest.TestCase):
def setupMapping(self, mapping_content=''):
mapping = tempfile.NamedTemporaryFile(dir=self.testdir, delete=False)
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 sign in to comment