Skip to content

Commit

Permalink
Merge pull request #5236 from hypothesis/default-null-org-in-tests
Browse files Browse the repository at this point in the history
Default to groups with no organization in test factories
  • Loading branch information
seanh committed Oct 2, 2018
2 parents e5ddf13 + fcf3648 commit cf661aa
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
6 changes: 0 additions & 6 deletions tests/common/factories/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
from .user import User


def default_organization():
from tests.common.factories.base import SESSION
return models.Organization.default(SESSION)


class Group(ModelFactory):

class Meta:
Expand All @@ -30,7 +25,6 @@ class Meta:
readable_by = ReadableBy.members
writeable_by = WriteableBy.members
members = factory.LazyAttribute(lambda obj: [obj.creator])
organization = factory.LazyFunction(default_organization)

@factory.post_generation
def scopes(self, create, scopes=0, **kwargs):
Expand Down
18 changes: 12 additions & 6 deletions tests/h/presenters/group_json_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
class TestGroupJSONPresenter(object):
def test_private_group_asdict(self, factories, GroupContext, links_svc):
group = factories.Group(name='My Group',
pubid='mygroup')
pubid='mygroup',
organization=factories.Organization())
group_context = GroupContext(group)
presenter = GroupJSONPresenter(group_context)

Expand All @@ -29,7 +30,8 @@ def test_private_group_asdict(self, factories, GroupContext, links_svc):

def test_open_group_asdict(self, factories, GroupContext, links_svc):
group = factories.OpenGroup(name='My Group',
pubid='mygroup')
pubid='mygroup',
organization=factories.Organization())
group_context = GroupContext(group)
presenter = GroupJSONPresenter(group_context)

Expand All @@ -46,7 +48,8 @@ def test_open_group_asdict(self, factories, GroupContext, links_svc):
def test_open_scoped_group_asdict(self, factories, GroupContext, links_svc):
group = factories.OpenGroup(name='My Group',
pubid='groupy',
scopes=[factories.GroupScope(origin='http://foo.com')])
scopes=[factories.GroupScope(origin='http://foo.com')],
organization=factories.Organization())
group_context = GroupContext(group)
presenter = GroupJSONPresenter(group_context)

Expand Down Expand Up @@ -83,7 +86,8 @@ def test_it_sets_organization_None_if_group_has_no_organization(self, factories,

def test_it_does_not_expand_by_default(self, factories, GroupContext):
group = factories.OpenGroup(name='My Group',
pubid='mygroup')
pubid='mygroup',
organization=factories.Organization())
group_context = GroupContext(group)
presenter = GroupJSONPresenter(group_context)

Expand All @@ -93,7 +97,8 @@ def test_it_does_not_expand_by_default(self, factories, GroupContext):

def test_it_expands_organizations(self, factories, GroupContext, OrganizationJSONPresenter):
group = factories.OpenGroup(name='My Group',
pubid='mygroup')
pubid='mygroup',
organization=factories.Organization())
group_context = GroupContext(group)
presenter = GroupJSONPresenter(group_context)

Expand All @@ -114,7 +119,8 @@ def test_expanded_organizations_None_if_missing(self, factories, GroupContext, O

def test_it_ignores_unrecognized_expands(self, factories, GroupContext):
group = factories.OpenGroup(name='My Group',
pubid='mygroup')
pubid='mygroup',
organization=factories.Organization())
group_context = GroupContext(group)
presenter = GroupJSONPresenter(group_context)

Expand Down
12 changes: 10 additions & 2 deletions tests/h/traversal/contexts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,20 @@ def test_it_returns_pubid_as_id(self, factories, pyramid_request):

assert group_context.id == group.pubid # NOT the group.id

def test_it_expands_organization(self, factories, pyramid_request):
def test_organization_is_None_if_the_group_has_no_organization(self, factories, pyramid_request):
group = factories.Group()

group_context = GroupContext(group, pyramid_request)

assert isinstance(group_context.organization, OrganizationContext)
assert group_context.organization is None

def test_it_expands_organization_if_the_group_has_one(self, factories, pyramid_request):
organization = factories.Organization()
group = factories.Group(organization=organization)

group_context = GroupContext(group, pyramid_request)

assert group_context.organization.organization == organization

def test_it_returns_None_for_missing_organization_relation(self, factories, pyramid_request):
group = factories.Group()
Expand Down
3 changes: 1 addition & 2 deletions tests/h/views/activity_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ def test_search_returns_group_info_if_user_has_read_permissions(
assert group_info['description'] == test_group.description
assert group_info['name'] == test_group.name
assert group_info['pubid'] == test_group.pubid
assert group_info['organization']['logo'] == OrganizationContext(None, None).logo
assert group_info['organization']['name'] == default_org.name
assert group_info['organization'] is None

@pytest.mark.parametrize('test_group,test_user',
[('no_organization_group', 'member')],
Expand Down
13 changes: 10 additions & 3 deletions tests/h/views/admin/groups_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,12 @@ def call_on_success(request, form, on_success, on_failure):
assert [s.origin for s in group.scopes] == updated_origins
assert ctx['form'] == self._expected_form(group)

def test_update_updates_group_members_on_success(self, factories, pyramid_request, group_svc, user_svc, handle_form_submission):
group = factories.RestrictedGroup(pubid='testgroup')
def test_update_updates_group_members_on_success(self, factories, pyramid_request, group_svc, user_svc, handle_form_submission, list_orgs_svc):
group = factories.RestrictedGroup(
pubid='testgroup',
organization=factories.Organization(),
)
list_orgs_svc.organizations.return_value = [group.organization]

pyramid_request.matchdict = {'pubid': group.pubid}

Expand Down Expand Up @@ -296,7 +300,10 @@ def test_delete_deletes_group(self, group, delete_group_svc, pyramid_request, ro

@pytest.fixture
def group(self, factories):
return factories.OpenGroup(pubid='testgroup')
return factories.OpenGroup(
pubid='testgroup',
organization=factories.Organization(),
)

def _expected_form(self, group):
return {'creator': group.creator.username if group.creator else '',
Expand Down

0 comments on commit cf661aa

Please sign in to comment.