fixed shebangs in non executable .py files
[nepi.git] / test / core / design.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 from nepi.core.design import ExperimentDescription, FactoriesProvider
5 from nepi.util import tags
6 import mock.metadata
7 import sys
8 import unittest
9
10 class DesignTestCase(unittest.TestCase):
11     def setUp(self):
12         # hack to add the mock testbed on the correct module path
13         sys.modules["nepi.testbeds.mock.metadata"] = mock.metadata
14
15     def test_design(self):
16         exp_desc = ExperimentDescription()
17         testbed_id = "mock"
18         provider = FactoriesProvider(testbed_id)
19         desc = exp_desc.add_testbed_description(provider)
20         desc.set_attribute_value("fake", True)
21         node1 = desc.create("Node")
22         node2 = desc.create("Node")
23         iface1 = desc.create("Interface")
24         iface1.set_attribute_value("fake", True)
25         addr1 = iface1.add_address()
26         addr2 = iface1.add_address()
27         addr3 = iface1.add_address()
28         self.assertRaises(RuntimeError, iface1.add_address)
29         node1.connector("devs").connect(iface1.connector("node"))
30         iface2 = desc.create("Interface")
31         iface2.set_attribute_value("fake", True)
32         node2.connector("devs").connect(iface2.connector("node"))
33         iface1.connector("iface").connect(iface2.connector("iface"))
34         app = desc.create("Application")
35         app.connector("node").connect(node1.connector("apps"))
36         app.enable_trace("fake")
37
38         self.assertEquals(node1.tags, [tags.MOBILE, tags.NODE, tags.ALLOW_ROUTES])
39
40         xml = exp_desc.to_xml()
41         exp_desc2 = ExperimentDescription()
42         exp_desc2.from_xml(xml)
43         xml2 = exp_desc2.to_xml()
44         self.assertTrue(xml == xml2)
45
46 if __name__ == '__main__':
47     unittest.main()
48