marvin_refactor: include an example with should-dsl Signed-off-by: Prasanna Santhanam <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/73102758 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/73102758 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/73102758 Branch: refs/heads/marvin_refactor Commit: 73102758b53616b4879d03e92e9c0c5f135c4290 Parents: dad9ce2 Author: Prasanna Santhanam <[email protected]> Authored: Fri Sep 13 15:58:33 2013 +0530 Committer: Prasanna Santhanam <[email protected]> Committed: Thu Oct 31 13:54:24 2013 +0530 ---------------------------------------------------------------------- tools/marvin/marvin/test/test_factories.py | 110 +++++++++++++----------- 1 file changed, 62 insertions(+), 48 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/73102758/tools/marvin/marvin/test/test_factories.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/test/test_factories.py b/tools/marvin/marvin/test/test_factories.py index 81e78a7..c2c823c 100644 --- a/tools/marvin/marvin/test/test_factories.py +++ b/tools/marvin/marvin/test/test_factories.py @@ -18,6 +18,7 @@ import unittest import logging from nose.plugins.attrib import attr +from should_dsl import should, should_not from marvin.cloudstackTestClient import cloudstackTestClient @@ -31,16 +32,15 @@ from marvin.factory.data.network import * from marvin.factory.virtualmachine import * from marvin.entity.serviceoffering import ServiceOffering +from marvin.entity.networkoffering import NetworkOffering from marvin.entity.zone import Zone from marvin.entity.account import Account from marvin.entity.template import Template from marvin.entity.user import User from marvin.entity.network import Network - from marvin.entity.ipaddress import IpAddress - class BuildVsCreateStrategyTest(unittest.TestCase): def setUp(self): self.apiClient = cloudstackTestClient(mgtSvr='localhost', logging=logging.getLogger('factory.cloudstack')).getApiClient() @@ -115,6 +115,65 @@ class NetworkOfferingFactoryTest(unittest.TestCase): pass +class UserFactorySubFactoryTest(unittest.TestCase): + def setUp(self): + self.apiClient = cloudstackTestClient(mgtSvr='localhost', logging=logging.getLogger('factory.cloudstack')).getApiClient() + + def tearDown(self): + pass + + @unittest.skip("This is a chicken and egg problem") + def test_userSubFactory(self): + """ + Skip because users are contained in accounts but + cannot be created until accounts exist + + A subfactory is unsuitable as the semantics of the + caller is not to create the user before creating the account + @return: + """ + uf = UserFactory(apiclient=self.apiClient) + user = User.list(apiclient=self.apiClient, username=uf.username) + self.assert_(uf.username == user[0].username, msg="Usernames don't match") + + +class NetworkFactoryTest(unittest.TestCase): + def setUp(self): + self.apiClient = cloudstackTestClient(mgtSvr='localhost', + logging=logging.getLogger('factory.cloudstack')).getApiClient() + + def tearDown(self): + self.accnt.delete(apiclient=self.apiClient) + + @attr(tags='network') + def test_isolatedGuestNetwork(self): + """Test to create a network within a guest account + @return: + """ + self.accnt = UserAccountFactory(apiclient=self.apiClient) + zones = Zone.list(apiclient=self.apiClient) + network = GuestIsolatedNetworkFactory( + apiclient=self.apiClient, + zoneid=zones[0].id + ) + logging.getLogger('factory.cloudstack').debug("network created with id %s, name %s" %(network.id, network.name)) + + +class NetworkOfferingFactoryWithMultiplePostHooksTest(unittest.TestCase): + def setUp(self): + self.apiClient = cloudstackTestClient(mgtSvr='localhost', + logging=logging.getLogger('factory.cloudstack')).getApiClient() + + @attr(tags='post') + def test_multiplePostHooksNetworkOffering(self): + sharedOffering = DefaultSharedNetworkOfferingFactory(apiclient=self.apiClient) + sharedOffering |should| be_instance_of(NetworkOffering) + sharedOffering |should_not| equal_to(None) + sharedOffering.state |should| equal_to('Enabled') + logging.getLogger('factory.cloudstack').debug("networkoffering created with id %s, name %s, state %s" + %(sharedOffering.id, sharedOffering.name, sharedOffering.state)) + + class VirtualMachineFactoryTest(unittest.TestCase): def setUp(self): self.apiClient = cloudstackTestClient(mgtSvr='localhost', logging=logging.getLogger('factory.cloudstack')).getApiClient() @@ -139,29 +198,6 @@ class VirtualMachineFactoryTest(unittest.TestCase): domainid = accnt.domainid) - -class UserFactorySubFactoryTest(unittest.TestCase): - def setUp(self): - self.apiClient = cloudstackTestClient(mgtSvr='localhost', logging=logging.getLogger('factory.cloudstack')).getApiClient() - - def tearDown(self): - pass - - @unittest.skip("This is a chicken and egg problem") - def test_userSubFactory(self): - """ - Skip because users are contained in accounts but - cannot be created until accounts exist - - A subfactory is unsuitable as the semantics of the - caller is not to create the user before creating the account - @return: - """ - uf = UserFactory(apiclient=self.apiClient) - user = User.list(apiclient=self.apiClient, username=uf.username) - self.assert_(uf.username == user[0].username, msg="Usernames don't match") - - class IpAddressFactoryTest(unittest.TestCase): def setUp(self): self.apiClient = cloudstackTestClient(mgtSvr='localhost', @@ -192,26 +228,4 @@ class IpAddressFactoryTest(unittest.TestCase): firstip = all_ips[0] networks = Network.list(apiclient=self.apiClient, account = accnt.name, domainid = accnt.domainid) - firstip.associate(apiclient=self.apiClient, networkid = networks[0].id) - - -class NetworkFactoryTest(unittest.TestCase): - def setUp(self): - self.apiClient = cloudstackTestClient(mgtSvr='localhost', - logging=logging.getLogger('factory.cloudstack')).getApiClient() - - def tearDown(self): - self.accnt.delete(apiclient=self.apiClient) - - @attr(tags='network') - def test_isolatedGuestNetwork(self): - """Test to create a network within a guest account - @return: - """ - self.accnt = UserAccountFactory(apiclient=self.apiClient) - zones = Zone.list(apiclient=self.apiClient) - network = GuestIsolatedNetworkFactory( - apiclient=self.apiClient, - zoneid=zones[0].id - ) - logging.getLogger('factory.cloudstack').debug("network created with id %s, name %s" %(network.id, network.name)) \ No newline at end of file + firstip.associate(apiclient=self.apiClient, networkid = networks[0].id) \ No newline at end of file
