Skip to content

Commit

Permalink
Improve coverage of unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
enolfc committed May 4, 2015
1 parent 507c2ef commit 9e8e2df
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 0 deletions.
120 changes: 120 additions & 0 deletions ooi/tests/occi/test_occi_infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from ooi.occi.core import mixin
from ooi.occi.core import resource
from ooi.occi.infrastructure import compute
from ooi.occi.infrastructure import network
from ooi.occi.infrastructure import network_link
from ooi.occi.infrastructure import storage
from ooi.occi.infrastructure import storage_link
from ooi.occi.infrastructure import templates
Expand Down Expand Up @@ -198,3 +200,121 @@ def test_resource_tpl(self):
mixin.Mixin)
self.assertEqual("resource_tpl",
templates.resource_tpl.term)


class TestOCCINetwork(base.TestCase):
def test_network_class(self):
n = network.NetworkResource
self.assertIn(network.up, n.actions)
self.assertIn(network.down, n.actions)
self.assertIn("occi.core.id", n.attributes)
self.assertIn("occi.core.summary", n.attributes)
self.assertIn("occi.core.title", n.attributes)
self.assertIn("occi.network.vlan", n.attributes)
self.assertIn("occi.network.label", n.attributes)
self.assertIn("occi.network.state", n.attributes)
self.assertIn(resource.Resource.kind, n.kind.related)
# TODO(aloga): We need to check that the attributes are actually set
# after we get an object (we have to check this for this but also for
# the other resources)

def test_network(self):
id = uuid.uuid4().hex
n = network.NetworkResource("foo",
summary="This is a summary",
id=id)
self.assertEqual("foo", n.title)
self.assertEqual(id, n.id)
self.assertEqual("This is a summary", n.summary)
self.assertIsNone(n.vlan)
self.assertIsNone(n.label)
self.assertIsNone(n.state)

def test_setters(self):
n = network.NetworkResource("foo")
n.vlan = "bar"
self.assertEqual("bar", n.attributes["occi.network.vlan"].value)
n.label = "baz"
self.assertEqual("baz", n.attributes["occi.network.label"].value)

def test_getters(self):
n = network.NetworkResource("foo", vlan="bar", label="baz",
state="foobar")
self.assertEqual("bar", n.vlan)
self.assertEqual("baz", n.label)
self.assertEqual("foobar", n.state)


class TestNetwokrMixins(base.TestCase):
def test_ip_network(self):
self.assertIsInstance(network.ip_network,
mixin.Mixin)
self.assertEqual("ipnetwork",
network.ip_network.term)
self.assertIn("occi.network.address", network.ip_network.attributes)
self.assertIn("occi.network.gateway", network.ip_network.attributes)
self.assertIn("occi.network.allocation", network.ip_network.attributes)

def test_ip_network_interface(self):
self.assertIsInstance(network_link.ip_network_interface,
mixin.Mixin)
self.assertEqual("ipnetworkinterface",
network_link.ip_network_interface.term)
self.assertIn("occi.networkinterface.address",
network_link.ip_network_interface.attributes)
self.assertIn("occi.networkinterface.gateway",
network_link.ip_network_interface.attributes)
self.assertIn("occi.networkinterface.allocation",
network_link.ip_network_interface.attributes)


class TestOCCINetworkInterface(base.TestCase):
def test_networkinterface_class(self):
l = network_link.NetworkInterface
self.assertIn("occi.core.id", l.attributes)
self.assertIn("occi.core.title", l.attributes)
self.assertIn("occi.core.source", l.attributes)
self.assertIn("occi.core.target", l.attributes)
self.assertIn("occi.networkinterface.interface", l.attributes)
self.assertIn("occi.networkinterface.mac", l.attributes)
self.assertIn("occi.networkinterface.state", l.attributes)
self.assertIn(link.Link.kind, l.kind.related)

def test_networkinterface(self):
c = compute.ComputeResource("foo",
summary="This is a summary",
id=uuid.uuid4().hex)
n = network.NetworkResource("bar",
summary="This is a summary",
id=uuid.uuid4().hex)
l = network_link.NetworkInterface([], c, n)
self.assertEqual(c, l.source)
self.assertEqual(n, l.target)
self.assertIsNone(l.interface)
self.assertIsNone(l.mac)
self.assertIsNone(l.state)

def test_setters(self):
c = compute.ComputeResource("foo",
summary="This is a summary",
id=uuid.uuid4().hex)
n = network.NetworkResource("bar",
summary="This is a summary",
id=uuid.uuid4().hex)
l = network_link.NetworkInterface([], c, n)
l.mac = "00:00:00:00:00:00"
self.assertEqual("00:00:00:00:00:00",
l.attributes["occi.networkinterface.mac"].value)

def test_getters(self):
c = compute.ComputeResource("foo",
summary="This is a summary",
id=uuid.uuid4().hex)
n = network.NetworkResource("bar",
summary="This is a summary",
id=uuid.uuid4().hex)
l = network_link.NetworkInterface([], c, n, interface="eth1",
mac="00:01:02:03:04:05", state="foo")
self.assertEqual("eth1", l.interface)
self.assertEqual("00:01:02:03:04:05", l.mac)
self.assertEqual("foo", l.state)
64 changes: 64 additions & 0 deletions ooi/tests/occi/test_openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

import uuid

from ooi.occi.infrastructure import compute
from ooi.occi.infrastructure import network
from ooi.occi.infrastructure import network_link
from ooi.occi.infrastructure import templates as occi_templates
from ooi.openstack import contextualization
from ooi.openstack import helpers
from ooi.openstack import network as os_network
from ooi.openstack import templates
from ooi.tests import base

Expand Down Expand Up @@ -97,3 +101,63 @@ def test_os_userdata(self):
self.assertTrue(mxn.scheme.startswith(helpers._PREFIX))
self.assertEqual(key_name, mxn.name)
self.assertEqual(key_data, mxn.data)


class TestOSNetworkInterface(base.TestCase):
def test_osnetwork_interface(self):
c = compute.ComputeResource("foo",
summary="This is a summary",
id=uuid.uuid4().hex)
n = network.NetworkResource("bar",
summary="This is a summary",
id=uuid.uuid4().hex)
i = os_network.OSNetworkInterface(c, n, "00:01:02:03:04:05",
"127.0.0.1")
self.assertEqual('_'.join([c.id, "127.0.0.1"]), i.id)
self.assertEqual(i.address, "127.0.0.1")
self.assertEqual(i.interface, "eth0")
self.assertEqual(i.mac, "00:01:02:03:04:05")
self.assertEqual(i.state, "active")
self.assertIsNone(i.gateway)
self.assertEqual(network_link.NetworkInterface.kind, i.kind)
self.assertIn(network_link.ip_network_interface, i.mixins)
# contains kind and mixins attributes
for att in network_link.NetworkInterface.kind.attributes:
self.assertIn(att, i.attributes)
for att in network_link.ip_network_interface.attributes:
self.assertIn(att, i.attributes)

def test_setters(self):
c = compute.ComputeResource("foo",
summary="This is a summary",
id=uuid.uuid4().hex)
n = network.NetworkResource("bar",
summary="This is a summary",
id=uuid.uuid4().hex)
i = os_network.OSNetworkInterface(c, n, "00:01:02:03:04:05",
"127.0.0.1")
i.address = "192.163.1.2"
self.assertEqual(
"192.163.1.2", i.attributes["occi.networkinterface.address"].value)
i.gateway = "192.163.1.1"
self.assertEqual(
"192.163.1.1", i.attributes["occi.networkinterface.gateway"].value)
i.allocation = "static"
self.assertEqual(
"static", i.attributes["occi.networkinterface.allocation"].value)

def test_getters(self):
c = compute.ComputeResource("foo",
summary="This is a summary",
id=uuid.uuid4().hex)
n = network.NetworkResource("bar",
summary="This is a summary",
id=uuid.uuid4().hex)
i = os_network.OSNetworkInterface(c, n, "00:01:02:03:04:05",
"127.0.0.1")
i.attributes["occi.networkinterface.address"].value = "192.163.1.2"
self.assertEqual("192.163.1.2", i.address)
i.attributes["occi.networkinterface.gateway"].value = "192.163.1.1"
self.assertEqual("192.163.1.1", i.gateway)
i.attributes["occi.networkinterface.allocation"].value = "static"
self.assertEqual("static", i.allocation)

0 comments on commit 9e8e2df

Please sign in to comment.