From f39aea31a84988df7f4a9773c1cf2c911c288fcd Mon Sep 17 00:00:00 2001 From: Sunil Basker Balashunmugam Date: Thu, 16 Jan 2014 21:00:24 +0530 Subject: [PATCH] Fix for (Config) api-server's unit test --- src/config/api-server/tests/fab_tasks.py | 2 +- src/config/api-server/tests/test_common.py | 2 + .../api-server/tests/test_crud_basic.py | 5 +- src/config/common/test_utils.py | 51 +++++++++++++++++++ 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/config/api-server/tests/fab_tasks.py b/src/config/api-server/tests/fab_tasks.py index b897624bd5b..92ca5c9132f 100644 --- a/src/config/api-server/tests/fab_tasks.py +++ b/src/config/api-server/tests/fab_tasks.py @@ -70,7 +70,7 @@ def run_tests(build_top = "../../../../../build"): with prefix("source bin/activate"): pyver = "%s.%s" % (sys.version_info[0], sys.version_info[1]) local( - "cp ../../../../../src/config/api-server/tests/" + "cp ../../../../../controller/src/config/api-server/tests/" "test_crud_basic.py lib/python%s/site-packages/" "vnc_cfg_api_server/" % (pyver)) local( diff --git a/src/config/api-server/tests/test_common.py b/src/config/api-server/tests/test_common.py index b4844a75548..603c5c1ad68 100644 --- a/src/config/api-server/tests/test_common.py +++ b/src/config/api-server/tests/test_common.py @@ -8,6 +8,7 @@ import cfgm_common.ifmap.client as ifmap_client import cfgm_common.ifmap.response as ifmap_response import discovery.client as disc_client +from cfgm_common.discovery import DiscoveryService import vnc_cfg_api_server @@ -40,6 +41,7 @@ def setup_flexmock(): flexmock(disc_client.DiscoveryClient, __init__=stub) flexmock(disc_client.DiscoveryClient, publish_obj=stub) + flexmock(DiscoveryService, __new__=DiscoveryServiceMock) flexmock(redis.StrictRedis, __new__=FakeRedis) #end setup_flexmock diff --git a/src/config/api-server/tests/test_crud_basic.py b/src/config/api-server/tests/test_crud_basic.py index ffa4cadade4..e15546b41ea 100644 --- a/src/config/api-server/tests/test_crud_basic.py +++ b/src/config/api-server/tests/test_crud_basic.py @@ -180,7 +180,8 @@ def test_fixture_ref(self): self.assertThat(policy_name, Equals('policy2222')) # ipam referring to virtual dns - vdns_data = VirtualDnsType(domain_name='abc.net') + vdns_data = VirtualDnsType(domain_name='abc.net', record_order='fixed', + default_ttl_seconds=360) vdns_fixt = self.useFixture( VirtualDnsTestFixtureGen(self._vnc_lib, virtual_DNS_name='vdns1', virtual_DNS_data=vdns_data)) @@ -189,7 +190,7 @@ def test_fixture_ref(self): dns_server = IpamDnsAddressType( virtual_dns_server_name=vdns_fixt.getObj().get_fq_name_str()) ipam_mgmt = IpamType( - ipam_dns_method='vdns-server', ipam_dns_server=dns_server) + ipam_dns_method=dns_method, ipam_dns_server=dns_server) ipam_fixt = self.useFixture( NetworkIpamTestFixtureGen( self._vnc_lib, network_ipam_name='ipam1', diff --git a/src/config/common/test_utils.py b/src/config/common/test_utils.py index 0b9cd11a59e..7d3a1543046 100644 --- a/src/config/common/test_utils.py +++ b/src/config/common/test_utils.py @@ -574,3 +574,54 @@ def Fake_uuid_to_time(time_uuid_in_db): ts = time.mktime(time_uuid_in_db.timetuple()) return ts # end of Fake_uuid_to_time + +class DiscoveryServiceMock(object): + + def __init__(self, *args, **kwargs): + self._count = 0 + self._values = {} + # end __init__ + + def alloc_from(self, path, max_id): + self._count = self._count + 1 + return self._count + # end alloc_from + + def alloc_from_str(self, path, value=''): + self._count = self._count + 1 + zk_val = "%(#)010d" % {'#': self._count} + self._values[path + zk_val] = value + return zk_val + # end alloc_from_str + + def delete(self, path): + del self._values[path] + # end delete + + def read(self, path): + try: + return self._values[path] + except Exception as err: + raise pycassa.NotFoundException + # end read + + def get_children(self, path): + return [] + # end get_children + + def read_node(self, path): + try: + return self.read(path) + except pycassa.NotFoundException: + return None + # end read_node + + def create_node(self, path, value=''): + self._values[path] = value + # end create_node + + def delete_node(self, path): + del self._values[path] + # end delete_node +# end Class DiscoveryServiceMock +