The previous version was specific to a port dict and would
fail if str() was called on other models. This iterates over
and logs all values of the dict instead so it works under any
dictionary.
Change-Id: I630b39338e4e67080e100a9f32c9b6e341a93472
Closes-Bug: #
1512753
del self[name]
def __str__(self):
- return "id=%s, network_id=%s" % (self.id, self.network_id)
+ pairs = ['%s=%s' % (k, v) for k, v in self.items()]
+ return ', '.join(sorted(pairs))
class NetModel(DictModel):
mgr.driver.init_l3.assert_called_with('ns-XXX',
['192.168.0.6/24'],
namespace='qdhcp-ns')
+
+
+class TestDictModel(base.BaseTestCase):
+
+ def test_string_representation_port(self):
+ port = dhcp.DictModel({'id': 'id', 'network_id': 'net_id'})
+ self.assertEqual('id=id, network_id=net_id', str(port))
+
+ def test_string_representation_network(self):
+ net = dhcp.DictModel({'id': 'id', 'name': 'myname'})
+ self.assertEqual('id=id, name=myname', str(net))