def test_member_join_publishes_join_event(self, db_session, users): publish = mock.Mock(spec_set=[]) svc = GroupsService(db_session, users.get, publish=publish) group = Group(name='Donkey Trust', creator=users['cazimir']) group.pubid = 'abc123' svc.member_join(group, 'theresa') publish.assert_called_once_with('group-join', 'abc123', 'theresa')
def test_member_leave_publishes_leave_event(self, service, users, publish): group = Group(name='Donkey Trust', authority='foobari.com', creator=users['theresa']) group.members.append(users['cazimir']) group.pubid = 'abc123' service.member_leave(group, 'cazimir') publish.assert_called_once_with('group-leave', 'abc123', 'cazimir')
def test_member_leave_publishes_leave_event(self, db_session, users): publish = mock.Mock(spec_set=[]) svc = GroupService(db_session, users.get, publish=publish) group = Group(name='Donkey Trust', authority='foobari.com', creator=users['theresa']) group.members.append(users['cazimir']) group.pubid = 'abc123' svc.member_leave(group, 'cazimir') publish.assert_called_once_with('group-leave', 'abc123', 'cazimir')
def test_post_sets_group_properties(self, form_validating_to, pyramid_request): creator = User(username='******', authority='example.org') group = Group(name='Birdwatcher Community', description='We watch birds all day long', creator=creator) group.pubid = 'the-test-pubid' controller = views.GroupEditController(group, pyramid_request) controller.form = form_validating_to({ 'name': 'Alligatorwatcher Comm.', 'description': 'We are all about the alligators now', }) controller.post() assert group.name == 'Alligatorwatcher Comm.' assert group.description == 'We are all about the alligators now'
def test_get_reads_group_properties(self, pyramid_request): pyramid_request.create_form.return_value = FakeForm() creator = User(username='******', authority='example.org') group = Group(name='Birdwatcher Community', description='We watch birds all day long', creator=creator) group.pubid = 'the-test-pubid' result = views.GroupEditController(group, pyramid_request).get() assert result == { 'form': { 'name': 'Birdwatcher Community', 'description': 'We watch birds all day long', }, 'group_path': '/g/the-test-pubid/birdwatcher-community' }
def test_get_reads_group_properties(self, pyramid_request): pyramid_request.create_form.return_value = FakeForm() creator = User(username="******", authority="example.org") group = Group( name="Birdwatcher Community", authority="foobar.com", description="We watch birds all day long", creator=creator, ) group.pubid = "the-test-pubid" result = views.GroupEditController(group, pyramid_request).get() assert result == { "form": { "name": "Birdwatcher Community", "description": "We watch birds all day long", }, "group_path": "/g/the-test-pubid/birdwatcher-community", }
def test_post_sets_group_properties(self, form_validating_to, pyramid_request): creator = User(username="******", authority="example.org") group = Group( name="Birdwatcher Community", authority="foobar.com", description="We watch birds all day long", creator=creator, ) group.pubid = "the-test-pubid" controller = views.GroupEditController(group, pyramid_request) controller.form = form_validating_to( { "name": "Alligatorwatcher Comm.", "description": "We are all about the alligators now", } ) controller.post() assert group.name == "Alligatorwatcher Comm." assert group.description == "We are all about the alligators now"
def test_post_sets_group_properties(self, form_validating_to, pyramid_request): creator = User(username="******", authority="example.org") group = Group( name="Birdwatcher Community", authority="foobar.com", description="We watch birds all day long", creator=creator, ) group.pubid = "the-test-pubid" controller = views.GroupEditController(group, pyramid_request) controller.form = form_validating_to({ "name": "Alligatorwatcher Comm.", "description": "We are all about the alligators now", }) controller.post() assert group.name == "Alligatorwatcher Comm." assert group.description == "We are all about the alligators now"
def test_update_memberships_adds_and_remove_members( self, factories, publish, service, users): group = Group(name='Donkey Trust', authority='example.com', creator=users['theresa']) group.pubid = 'abc123' service.member_join = mock.Mock() service.member_leave = mock.Mock() group.members.append(users['cazimir']) group.members.append(users['theresa']) group.members.append(users['ali']) service.update_membership(group, [ users['henry'].username, users['poppy'].username, users['theresa'].username ]) assert len(service.member_leave.call_args_list) == 2 service.member_leave.assert_any_call(group, users['cazimir'].userid) service.member_leave.assert_any_call(group, users['ali'].userid) assert len(service.member_join.call_args_list) == 2 service.member_join.assert_any_call(group, users['henry'].userid) service.member_join.assert_any_call(group, users['poppy'].userid)