Commit 5e0fcfd6 authored by Lucas Carvalho's avatar Lucas Carvalho

Added new tests for NetworkcacheClient class.

This is the first version has only basic tests.

The new test class aims to test the behavior of NetworkcacheClient
class. And it is forbidden to change any behavior of
NetworkcacheClient without writting/editing the tests.

NOTE: still WIP...
parent aedb3d92
...@@ -81,3 +81,59 @@ class GenerateSignatureScriptTest(LibNetworkCacheMixin): ...@@ -81,3 +81,59 @@ class GenerateSignatureScriptTest(LibNetworkCacheMixin):
''' '''
self.assertTrue(os.path.exists(self.signature_certificate_file)) self.assertTrue(os.path.exists(self.signature_certificate_file))
self.assertTrue(os.path.exists(self.signature_private_key_file)) self.assertTrue(os.path.exists(self.signature_private_key_file))
class TestNetworkcacheClient(LibNetworkCacheMixin):
"""
Class to test the NetworkcacheClient implementation.
"""
def setUp(self):
""" Setup the test. """
LibNetworkCacheMixin.setUp(self)
self.host = 'localhost'
self.port = 8000
self.shacache_path = '/shacache'
self.shadir_path = '/shadir'
url = 'http://%s:%s' % (self.host, self.port)
self.shacache_url = url + self.shacache_path
self.shadir_url = url + self.shadir_path
self.nc = NetworkcacheClient(shacache=self.shacache_url,
shadir=self.shadir_url)
def test_init_method_normal_http_url(self):
"""
Check if the init method is setting the attributes correctly.
"""
self.assertEquals({'Content-Type': 'application/json'}, \
self.nc.shacache_header_dict)
self.assertEquals(self.host, self.nc.shacache_host)
self.assertEquals(self.shacache_path, self.nc.shacache_path)
self.assertEquals(self.port, self.nc.shacache_port)
self.assertEquals(self.shacache_url, self.nc.shacache_url)
self.assertEquals({'Content-Type': 'application/json'}, \
self.nc.shadir_header_dict)
self.assertEquals(self.host, self.nc.shadir_host)
self.assertEquals(self.shadir_path, self.nc.shadir_path)
self.assertEquals(self.port, self.nc.shadir_port)
def test_signature_creation_without_private_key_file(self):
"""
Without the private key file, it is not possible to create the
signature so it must
"""
nc = NetworkcacheClient(
shacache=self.shacache_url,
shadir=self.shadir_url)
self.assertEquals('', nc._getSignatureString())
def test_signature_creation_with_private_key_file(self):
"""
Check if the signature creation does not have any error.
"""
nc = NetworkcacheClient(
shacache=self.shacache_url,
shadir=self.shadir_url,
signature_private_key_file=self.signature_private_key_file)
self.assertNotEquals('', nc._getSignatureString())
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