Skip to content

Commit

Permalink
Fix for (Config) api-server's unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sunilbasker-jnpr committed Jan 16, 2014
1 parent 6097a68 commit f39aea3
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/config/api-server/tests/fab_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions src/config/api-server/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
5 changes: 3 additions & 2 deletions src/config/api-server/tests/test_crud_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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',
Expand Down
51 changes: 51 additions & 0 deletions src/config/common/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f39aea3

Please sign in to comment.