Commit 1c08c506 authored by Lucas Carvalho's avatar Lucas Carvalho

Moved the methods setUp and tearDown, for a mixin class.

Well, the LibNetworkCacheMixin has been created to avoid any kind of
code duplication inside of this test suite.

This mixin class is gonna be used by TestNetworkCacheClient.

Some variables have been renamed for a better understanding, but the
behavior of the code still the same.
parent e7d517bd
......@@ -15,9 +15,7 @@ class OfflineTest(unittest.TestCase):
nc = NetworkcacheClient('http://127.0.0.1:0', 'http://127.0.0.1:0')
self.assertRaises(IOError, nc.upload, content)
class GenerateSignatureScriptTest(unittest.TestCase):
''' Class which must test the signature.py script. '''
class LibNetworkCacheMixin(unittest.TestCase):
def setUp(self):
''' Setup the test. '''
......@@ -25,21 +23,26 @@ class GenerateSignatureScriptTest(unittest.TestCase):
self.priv_file_descritor = tempfile.NamedTemporaryFile()
self.signature_certificate_file = self.pub_file_descriptor.name
self.signature_private_key_file = self.priv_file_descritor.name
self.arg_list = ('--signature-certificate-file', self.signature_certificate_file,
'--signature-private-key-file', self.signature_private_key_file,
'--country', 'BR, aze, AEAZE, ZEAZE',
'--state-name', 'Campos',
'--locality-name', 'Rio de Janeiro',
'--organization-name', 'Nexedi',
'--organization-unit-name', 'Dev',
'--common-name', 'R500.com',
'--email', 'test@example.com')
self.signature_creation_argument_list = \
('--signature-certificate-file', self.signature_certificate_file,
'--signature-private-key-file', self.signature_private_key_file,
'--country', 'BR',
'--state-name', 'Campos',
'--locality-name', 'Rio de Janeiro',
'--organization-name', 'Nexedi',
'--organization-unit-name', 'Dev',
'--common-name', 'R500.com',
'--email', 'test@example.com')
def tearDown(self):
''' Remove the files which have been created during the test. '''
self.priv_file_descritor.close()
self.pub_file_descriptor.close()
class GenerateSignatureScriptTest(LibNetworkCacheMixin):
''' Class which must test the signature.py script. '''
def test_parse_argument_with_empty_list(self):
'''
If the argument list is empty, then the parseArgument method should
......@@ -60,18 +63,22 @@ class GenerateSignatureScriptTest(unittest.TestCase):
'''
Check if the argument is properly set.
'''
option_dict = parseArgument(*self.arg_list)
option_dict = parseArgument(*self.signature_creation_argument_list)
size_argument_list = len(self.signature_creation_argument_list)/2
size_option_dict = len(option_dict)
self.assertEquals(size_argument_list, size_option_dict,
"Argument list should have the same size of option dict.")
self.assertEquals(len(self.arg_list)/2, len(option_dict))
# Assert if the values are equals.
for value in option_dict.values():
self.assertTrue(value in self.arg_list, '%s is not in %s.' %
(value, self.arg_list))
self.assertTrue(value in self.signature_creation_argument_list,\
'%s is not in %s.' % (value, self.signature_creation_argument_list))
def test_key_and_certificate_file_creation(self):
'''
Check if key file and the certificate file are being created correctly.
'''
option_dict = parseArgument(*self.arg_list)
option_dict = parseArgument(*self.signature_creation_argument_list)
cert_as_text = createPrivateKeyAndCertificateFile(**option_dict)
self.assertTrue(os.path.exists(self.signature_certificate_file))
......
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