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