Commit 1f273c26 authored by Łukasz Nowak's avatar Łukasz Nowak Committed by Łukasz Nowak

test: Import once

It will make further testing much easier
parent d48b47a4
...@@ -45,10 +45,8 @@ from cryptography.x509.oid import NameOID ...@@ -45,10 +45,8 @@ from cryptography.x509.oid import NameOID
import caucase.cli import caucase.cli
import caucase.http import caucase.http
from cli import getter import cli
from cli import http import updater
from cli import updater
from updater import Updater
@contextlib.contextmanager @contextlib.contextmanager
...@@ -216,7 +214,7 @@ class KedifaMixinCaucase(KedifaMixin): ...@@ -216,7 +214,7 @@ class KedifaMixinCaucase(KedifaMixin):
self.pidfile = os.path.join(self.testdir, 'kedifa.pid') self.pidfile = os.path.join(self.testdir, 'kedifa.pid')
port = '16080' port = '16080'
self.kedifa_runtime = multiprocessing.Process( self.kedifa_runtime = multiprocessing.Process(
target=http, target=cli.http,
args=( args=(
'--ip', ip, '--ip', ip,
'--port', port, '--port', port,
...@@ -288,7 +286,7 @@ class KedifaMixinCaucase(KedifaMixin): ...@@ -288,7 +286,7 @@ class KedifaMixinCaucase(KedifaMixin):
class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase): class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase):
def _getter_get(self, url, certificate, destination): def _getter_get(self, url, certificate, destination):
getter( cli.getter(
url, url,
'--out', destination, '--out', destination,
'--server-ca-certificate', self.ca_crt_pem, '--server-ca-certificate', self.ca_crt_pem,
...@@ -311,7 +309,7 @@ class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase): ...@@ -311,7 +309,7 @@ class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase):
mapping.close() mapping.close()
state = tempfile.NamedTemporaryFile(dir=self.testdir, delete=False) state = tempfile.NamedTemporaryFile(dir=self.testdir, delete=False)
state.close() state.close()
updater( cli.updater(
'--once', '--once',
'--server-ca-certificate', self.ca_crt_pem, '--server-ca-certificate', self.ca_crt_pem,
'--identity', certificate, '--identity', certificate,
...@@ -1111,44 +1109,51 @@ class KedifaUpdaterMixin(KedifaMixin): ...@@ -1111,44 +1109,51 @@ class KedifaUpdaterMixin(KedifaMixin):
class KedifaUpdaterMappingTest(KedifaUpdaterMixin, unittest.TestCase): class KedifaUpdaterMappingTest(KedifaUpdaterMixin, unittest.TestCase):
def test_updateMapping_empty(self): def test_updateMapping_empty(self):
self.setupMapping() self.setupMapping()
u = Updater(1, self.mapping, self.state, None, None, None, None, True) u = updater.Updater(1, self.mapping, self.state, None, None, None, None,
True)
u.updateMapping() u.updateMapping()
self.assertEqual(u.mapping, {}) self.assertEqual(u.mapping, {})
def test_updateMapping_normal(self): def test_updateMapping_normal(self):
self.setupMapping('url file') self.setupMapping('url file')
u = Updater(1, self.mapping, self.state, None, None, None, None, True) u = updater.Updater(1, self.mapping, self.state, None, None, None, None,
True)
u.updateMapping() u.updateMapping()
self.assertEqual(u.mapping, {'file': ('url', None)}) self.assertEqual(u.mapping, {'file': ('url', None)})
def test_updateMapping_morewhite(self): def test_updateMapping_morewhite(self):
self.setupMapping('url \t file') self.setupMapping('url \t file')
u = Updater(1, self.mapping, self.state, None, None, None, None, True) u = updater.Updater(1, self.mapping, self.state, None, None, None, None,
True)
u.updateMapping() u.updateMapping()
self.assertEqual(u.mapping, {'file': ('url', None)}) self.assertEqual(u.mapping, {'file': ('url', None)})
def test_updateMapping_one_empty(self): def test_updateMapping_one_empty(self):
self.setupMapping('url file\n \n') self.setupMapping('url file\n \n')
u = Updater(1, self.mapping, self.state, None, None, None, None, True) u = updater.Updater(1, self.mapping, self.state, None, None, None, None,
True)
u.updateMapping() u.updateMapping()
self.assertEqual(u.mapping, {'file': ('url', None)}) self.assertEqual(u.mapping, {'file': ('url', None)})
def test_updateMapping_one_not_enough(self): def test_updateMapping_one_not_enough(self):
self.setupMapping('url file\nbuzz\n') self.setupMapping('url file\nbuzz\n')
u = Updater(1, self.mapping, self.state, None, None, None, None, True) u = updater.Updater(1, self.mapping, self.state, None, None, None, None,
True)
u.updateMapping() u.updateMapping()
self.assertEqual(u.mapping, {'file': ('url', None)}) self.assertEqual(u.mapping, {'file': ('url', None)})
def test_updateMapping_with_fallback(self): def test_updateMapping_with_fallback(self):
self.setupMapping('url file\nbuzz oink fallback\n') self.setupMapping('url file\nbuzz oink fallback\n')
u = Updater(1, self.mapping, self.state, None, None, None, None, True) u = updater.Updater(1, self.mapping, self.state, None, None, None, None,
True)
u.updateMapping() u.updateMapping()
self.assertEqual( self.assertEqual(
u.mapping, {'file': ('url', None), 'oink': ('buzz', 'fallback')}) u.mapping, {'file': ('url', None), 'oink': ('buzz', 'fallback')})
def test_updateMapping_one_comment(self): def test_updateMapping_one_comment(self):
self.setupMapping('url file\n#buzz uff\n') self.setupMapping('url file\n#buzz uff\n')
u = Updater(1, self.mapping, self.state, None, None, None, None, True) u = updater.Updater(1, self.mapping, self.state, None, None, None, None,
True)
u.updateMapping() u.updateMapping()
self.assertEqual(u.mapping, {'file': ('url', None)}) self.assertEqual(u.mapping, {'file': ('url', None)})
...@@ -1175,13 +1180,13 @@ class KedifaUpdaterUpdateCertificateTest( ...@@ -1175,13 +1180,13 @@ class KedifaUpdaterUpdateCertificateTest(
if fallback_file: if fallback_file:
mapping = '%s %s' % (mapping, fallback_file.name) mapping = '%s %s' % (mapping, fallback_file.name)
self.setupMapping(mapping) self.setupMapping(mapping)
u = Updater( u = updater.Updater(
1, self.mapping, self.state, '/master/certificate/file', None, None, 1, self.mapping, self.state, '/master/certificate/file', None, None,
None, True) None, True)
u.updateMapping() u.updateMapping()
u.readState() u.readState()
with mock.patch.object( with mock.patch.object(
Updater, 'fetchCertificate', return_value=fetch): updater.Updater, 'fetchCertificate', return_value=fetch):
result = u.updateCertificate(self.certificate_file_name, master_content) result = u.updateCertificate(self.certificate_file_name, master_content)
u.writeState() u.writeState()
return open(self.certificate_file_name, 'r').read(), result return open(self.certificate_file_name, 'r').read(), result
......
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