Chain subFactory calls SubFactories now can call in a nested fashion to populate attributes in dependant entities.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4d54820a Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4d54820a Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4d54820a Branch: refs/heads/marvin_refactor Commit: 4d54820aa9e8ba5851e946779610f77ded80849c Parents: dce00d4 Author: Prasanna Santhanam <[email protected]> Authored: Thu Apr 25 16:58:24 2013 +0530 Committer: Prasanna Santhanam <[email protected]> Committed: Thu Apr 25 16:58:24 2013 +0530 ---------------------------------------------------------------------- tools/marvin/marvin/base/Account.py | 4 +++- tools/marvin/marvin/factory/AccountFactory.py | 13 ++++++++++--- .../marvin/marvin/factory/CloudStackBaseFactory.py | 2 +- tools/marvin/marvin/factory/UserFactory.py | 14 +++++++------- tools/marvin/marvin/factory/test/testFactories.py | 2 +- tools/marvin/marvin/factory/test/test_factories.py | 2 +- 6 files changed, 23 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4d54820a/tools/marvin/marvin/base/Account.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/base/Account.py b/tools/marvin/marvin/base/Account.py index aaf72ed..32744c9 100644 --- a/tools/marvin/marvin/base/Account.py +++ b/tools/marvin/marvin/base/Account.py @@ -14,6 +14,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. + from marvin.base import CloudStackEntity from marvin.cloudstackAPI import enableAccount from marvin.cloudstackAPI import lockAccount @@ -24,8 +25,8 @@ from marvin.cloudstackAPI import disableAccount from marvin.cloudstackAPI import deleteAccount from marvin.cloudstackAPI import markDefaultZoneForAccount -class Account(CloudStackEntity.CloudStackEntity): +class Account(CloudStackEntity.CloudStackEntity): def __init__(self, items): self.__dict__.update(items) @@ -91,6 +92,7 @@ class Account(CloudStackEntity.CloudStackEntity): account = apiclient.deleteAccount(cmd) return account + def mark(self, apiclient, zoneid, **kwargs): cmd = markDefaultZoneForAccount.markDefaultZoneForAccountCmd() cmd.id = self.id http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4d54820a/tools/marvin/marvin/factory/AccountFactory.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/factory/AccountFactory.py b/tools/marvin/marvin/factory/AccountFactory.py index 3c07683..db38732 100644 --- a/tools/marvin/marvin/factory/AccountFactory.py +++ b/tools/marvin/marvin/factory/AccountFactory.py @@ -20,11 +20,18 @@ from marvin.factory.CloudStackBaseFactory import CloudStackBaseFactory from marvin.base import Account from marvin.utils import random_gen [email protected]_strategy(new_strategy=factory.BUILD_STRATEGY) class AccountFactory(CloudStackBaseFactory): FACTORY_FOR = Account.Account + accounttype = None + firstname = None + lastname = None + email = None + username = None + password = None + +class UserAccountFactory(AccountFactory): accounttype = 0 firstname = factory.Sequence(lambda n: random_gen()) lastname = factory.Sequence(lambda n: random_gen()) @@ -33,10 +40,10 @@ class AccountFactory(CloudStackBaseFactory): password = 'password' -class AdminAccountFactory(AccountFactory): +class AdminAccountFactory(UserAccountFactory): accounttype = 1 -class DomainAdminFactory(AccountFactory): +class DomainAdminFactory(UserAccountFactory): accounttype = 2 domainid = None http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4d54820a/tools/marvin/marvin/factory/CloudStackBaseFactory.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/factory/CloudStackBaseFactory.py b/tools/marvin/marvin/factory/CloudStackBaseFactory.py index 499dbc2..c4a7c77 100644 --- a/tools/marvin/marvin/factory/CloudStackBaseFactory.py +++ b/tools/marvin/marvin/factory/CloudStackBaseFactory.py @@ -32,7 +32,7 @@ class CloudStackBaseFactory(factory.Factory): @classmethod def _create(cls, target_class, *args, **kwargs): - if cls.apiclient: + if hasattr(cls, 'apiclient'): members = inspect.getmembers(target_class, predicate=inspect.ismethod) creators = filter(lambda x: x[0] in CREATORS, members) http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4d54820a/tools/marvin/marvin/factory/UserFactory.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/factory/UserFactory.py b/tools/marvin/marvin/factory/UserFactory.py index f70089d..4981ca4 100644 --- a/tools/marvin/marvin/factory/UserFactory.py +++ b/tools/marvin/marvin/factory/UserFactory.py @@ -23,12 +23,12 @@ class UserFactory(CloudStackBaseFactory): FACTORY_FOR = User.User - account = factory.SubFactory(AccountFactory, apiclient=factory.SelfAttribute('..apiclient')).factory() - email = account.email - firstname = account.firstname - lastname = account.lastname - password = account.password - username = account.username + account = factory.SubFactory(AccountFactory, apiclient=factory.SelfAttribute('..apiclient')) + email = factory.SelfAttribute('account.email') + firstname = factory.SelfAttribute('account.firstname') + lastname = factory.SelfAttribute('account.lastname') + password = factory.SelfAttribute('account.password') + username = factory.SelfAttribute('account.name') class AdminUserFactory(UserFactory): - account = factory.SubFactory(AccountFactory, accounttype=1).factory() + account = factory.SubFactory(AccountFactory, accounttype=1) http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4d54820a/tools/marvin/marvin/factory/test/testFactories.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/factory/test/testFactories.py b/tools/marvin/marvin/factory/test/testFactories.py index d4e947e..c798bb4 100644 --- a/tools/marvin/marvin/factory/test/testFactories.py +++ b/tools/marvin/marvin/factory/test/testFactories.py @@ -147,7 +147,7 @@ class UserFactorySubFactoryTest(unittest.TestCase): def test_userSubFactory(self): uf = UserFactory.create(apiclient=self.apiClient) - user = User.list(apiclient=self.apiClient, username=uf.username) + user = User.list(apiclient=self.apiClient, username=uf.account.username) self.assert_(uf.username == user[0].username, msg="Usernames don't match") http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4d54820a/tools/marvin/marvin/factory/test/test_factories.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/factory/test/test_factories.py b/tools/marvin/marvin/factory/test/test_factories.py index 31cdb40..56903ff 100644 --- a/tools/marvin/marvin/factory/test/test_factories.py +++ b/tools/marvin/marvin/factory/test/test_factories.py @@ -43,7 +43,7 @@ class BuildVsCreateStrategyTest(unittest.TestCase): def test_buildUserAccountFactory(self): af = UserAccountFactory() - self.assert_(af.name is not None, msg="Acount factory didn't initialize") + self.assert_(af.account is not None, msg="Acount factory didn't initialize") def test_createAccountFactory(self): af = AccountFactory.create(apiclient=self.apiClient)
