Skip to content

Commit

Permalink
Allow specifying user when creating a group using the factory
Browse files Browse the repository at this point in the history
With this, we're able to create a group owned by a specific user.
  • Loading branch information
vitorbaptista authored and amercader committed Jun 19, 2014
1 parent cb0674c commit 987c090
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ckan/new_tests/factories.py
Expand Up @@ -117,6 +117,8 @@ class Group(factory.Factory):
# Generate a different group name param for each user that gets created.
name = factory.Sequence(lambda n: 'test_group_{n}'.format(n=n))

user = factory.LazyAttribute(lambda _: helpers.call_action('get_site_user'))

@classmethod
def _build(cls, target_class, *args, **kwargs):
raise NotImplementedError(".build() isn't supported in CKAN")
Expand All @@ -126,11 +128,10 @@ def _create(cls, target_class, *args, **kwargs):
if args:
assert False, "Positional args aren't supported, use keyword args."

#TODO: we will need to be able to define this when creating the
# instance perhaps passing a 'user' param?
context = {
'user': helpers.call_action('get_site_user')['name']
'user': kwargs['user']['name']
}
del kwargs['user']

group_dict = helpers.call_action('group_create',
context=context,
Expand Down

0 comments on commit 987c090

Please sign in to comment.