use _adjust_kwargs for cleaning

_adjust_kwargs is useful for any pre-generation cleaning of **kwargs by
factory_boy


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/46bc06e2
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/46bc06e2
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/46bc06e2

Branch: refs/heads/marvin_refactor
Commit: 46bc06e2544797e8b7042f6c2ffd27bc0043f36b
Parents: a936b9f
Author: Prasanna Santhanam <[email protected]>
Authored: Sun Apr 21 12:16:07 2013 +0530
Committer: Prasanna Santhanam <[email protected]>
Committed: Sun Apr 21 12:16:07 2013 +0530

----------------------------------------------------------------------
 .../lib/factory/CloudStackBaseFactory.py           |   22 +++++++++-----
 1 files changed, 14 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/46bc06e2/tools/marvin/marvin/integration/lib/factory/CloudStackBaseFactory.py
----------------------------------------------------------------------
diff --git 
a/tools/marvin/marvin/integration/lib/factory/CloudStackBaseFactory.py 
b/tools/marvin/marvin/integration/lib/factory/CloudStackBaseFactory.py
index ff10754..499dbc2 100644
--- a/tools/marvin/marvin/integration/lib/factory/CloudStackBaseFactory.py
+++ b/tools/marvin/marvin/integration/lib/factory/CloudStackBaseFactory.py
@@ -32,18 +32,24 @@ class CloudStackBaseFactory(factory.Factory):
 
     @classmethod
     def _create(cls, target_class, *args, **kwargs):
-        if "apiclient" in kwargs:
+        if cls.apiclient:
             members = inspect.getmembers(target_class,
-                                         predicate=inspect.ismethod)
+                predicate=inspect.ismethod)
             creators = filter(lambda x: x[0] in CREATORS, members)
             assert creators, "How do I bring this guy into existence?"
             assert inspect.ismethod(creators[0][1])
             creator = creators[0][1]
-            apiclient = kwargs["apiclient"]
+            return creator(cls.apiclient, factory=cls._build(target_class,
+                *args, **kwargs))
+        else:
+            cls._build(target_class, *args, **kwargs)
+
+    @classmethod
+    def _adjust_kwargs(cls, **kwargs):
+        if "apiclient" in kwargs:
+            cls.apiclient = kwargs["apiclient"]
             clean_kwargs = dict((k, v) for k, v in kwargs.iteritems()
-                                if k != "apiclient")
-            return creator(apiclient, factory=cls._build(target_class,
-                                                         *args, **clean_kwargs)
-                                                        )
+                if k != "apiclient")
+            return clean_kwargs
         else:
-            cls._build(target_class, *args, **kwargs)
\ No newline at end of file
+            return kwargs
\ No newline at end of file

Reply via email to