def test_join_member_group_unknown_group(self, m_a_u): 'Test joining an unknown group' m_a_u().getGroupNames.return_value = ['ethel_member', 'frog_member', ] j = JoiningUser(MagicMock()) with self.assertRaises(ValueError): j.join_member_group('violence_member')
def test_moderate_member(self): 'Cope with the ``moderated_members`` property being present' durk = MagicMock() durk.id = 'durk' mailingList = MagicMock() mList = mailingList.mlist mList.hasProperty.return_value = True dinsdale = MagicMock() dinsdale.id = 'dinsdale' mailingList.moderatees = [ dinsdale, ] groupInfo = MagicMock() auditor = MagicMock() j = JoiningUser(MagicMock()) j.moderate_member(durk, mailingList, groupInfo, auditor) mList.manage_changeProperties.assert_called_once_with( moderated_members=[ 'dinsdale', 'durk', ])
def test_moderate_member_property_missing(self): 'Cope with the ``moderated_members`` property missing' durk = MagicMock() durk.id = 'durk' mailingList = MagicMock() mList = mailingList.mlist mList.hasProperty.return_value = False dinsdale = MagicMock() dinsdale.id = 'dinsdale' mailingList.moderatees = [ dinsdale, ] groupInfo = MagicMock() auditor = MagicMock() j = JoiningUser(MagicMock()) j.moderate_member(durk, mailingList, groupInfo, auditor) mList.manage_addProperty.assert_called_once_with( 'moderated_members', [ 'dinsdale', 'durk', ], 'lines')
def init_group(container, admin_email, emailDomain): '''Initialise the first group.''' acl_users = container.site_root().acl_users site = getattr(container.Content, SITE_ID, None) if not site: m = 'No site "{0}" found in "{1}"'.format(SITE_ID, container) raise ValueError(m) siteInfo = createObject('groupserver.SiteInfo', site) starter = MoiraeForGroup(siteInfo) groupId = 'example_group' # We want the userInfo in the context of the site admin = acl_users.get_userByEmail(admin_email) adminInfo = createObject('groupserver.UserFromId', site, admin.getId()) try: groupInfo = starter.create('Example group', groupId, 'public', emailDomain, adminInfo) except BadRequest: mumble_exists_mumble('init_group', 'groups/%s' % groupId) m = 'init_group: Skipping the rest of the group configuration.' log.warning(m) else: ju = JoiningUser(adminInfo) # Silent Join is used so if the SMTP config is borken everything # still works. ju.silent_join(groupInfo)
def test_join_member_group_unknown_group(self, m_a_u): 'Test joining an unknown group' m_a_u().getGroupNames.return_value = [ 'ethel_member', 'frog_member', ] j = JoiningUser(MagicMock()) with self.assertRaises(ValueError): j.join_member_group('violence_member')
def test_join_member_group(self, m_a_u): 'Test joining a group' acl_users = m_a_u() acl_users.getGroupNames.return_value = ['ethel_member', 'frog_member', ] userInfo = MagicMock() userInfo.id = 'dinsdale' j = JoiningUser(userInfo) j.join_member_group('ethel_member') acl_users.addGroupsToUser.assert_called_once_with(['ethel_member', ], 'dinsdale')
def test_set_moderation_site_admin(self, m_m_m, m_cO, m_u_d_a_o_g): 'Ensure that site-administrators are not moderated' mailingList = m_cO() mailingList.is_moderated = True mailingList.is_moderate_new = True m_u_d_a_o_g.return_value = True userInfo = MagicMock() userInfo.id = 'dinsdale' j = JoiningUser(userInfo) j.set_moderation(MagicMock(), MagicMock()) self.assertEqual(0, m_m_m.call_count)
def test_set_moderation_moderate_new(self, m_m_m, m_cO, m_u_d_a_o_g): 'Ensure that we moderate new members' mailingList = m_cO() mailingList.is_moderated = True mailingList.is_moderate_new = True m_u_d_a_o_g.return_value = False userInfo = MagicMock() userInfo.id = 'dinsdale' j = JoiningUser(userInfo) groupInfo = MagicMock() auditor = MagicMock() j.set_moderation(groupInfo, auditor) m_m_m.assert_called_once_with(userInfo, mailingList, groupInfo, auditor)
def test_set_moderation_moderate_some(self, m_m_m, m_cO, m_u_d_a_o_g): 'Ensure that we skip setting moderation if we only moderate some members' mailingList = m_cO() mailingList.is_moderated = True mailingList.is_moderate_new = False m_u_d_a_o_g.return_value = False userInfo = MagicMock() userInfo.id = 'dinsdale' j = JoiningUser(userInfo) groupInfo = MagicMock() auditor = MagicMock() j.set_moderation(groupInfo, auditor) self.assertEqual(0, m_m_m.call_count)
def test_join_member_group(self, m_a_u): 'Test joining a group' acl_users = m_a_u() acl_users.getGroupNames.return_value = [ 'ethel_member', 'frog_member', ] userInfo = MagicMock() userInfo.id = 'dinsdale' j = JoiningUser(userInfo) j.join_member_group('ethel_member') acl_users.addGroupsToUser.assert_called_once_with([ 'ethel_member', ], 'dinsdale')
def test_moderate_member_already(self, m_l): 'Ensure we cope if someone is already moderated' j = JoiningUser(MagicMock()) durk = MagicMock() durk.id = 'durk' mailingList = MagicMock() dinsdale = MagicMock() dinsdale.id = 'dinsdale' mailingList.moderatees = [durk, dinsdale, ] groupInfo = MagicMock() auditor = MagicMock() j.moderate_member(durk, mailingList, groupInfo, auditor) self.assertEqual(1, m_l.warn.call_count) self.assertEqual(0, mailingList.hasProperty.call_count)
def test_moderate_member_property_missing(self): 'Cope with the ``moderated_members`` property missing' durk = MagicMock() durk.id = 'durk' mailingList = MagicMock() mList = mailingList.mlist mList.hasProperty.return_value = False dinsdale = MagicMock() dinsdale.id = 'dinsdale' mailingList.moderatees = [dinsdale, ] groupInfo = MagicMock() auditor = MagicMock() j = JoiningUser(MagicMock()) j.moderate_member(durk, mailingList, groupInfo, auditor) mList.manage_addProperty.assert_called_once_with( 'moderated_members', ['dinsdale', 'durk', ], 'lines')
def test_moderate_member(self): 'Cope with the ``moderated_members`` property being present' durk = MagicMock() durk.id = 'durk' mailingList = MagicMock() mList = mailingList.mlist mList.hasProperty.return_value = True dinsdale = MagicMock() dinsdale.id = 'dinsdale' mailingList.moderatees = [dinsdale, ] groupInfo = MagicMock() auditor = MagicMock() j = JoiningUser(MagicMock()) j.moderate_member(durk, mailingList, groupInfo, auditor) mList.manage_changeProperties.assert_called_once_with( moderated_members=['dinsdale', 'durk', ])
def test_moderate_member_already(self, m_l): 'Ensure we cope if someone is already moderated' j = JoiningUser(MagicMock()) durk = MagicMock() durk.id = 'durk' mailingList = MagicMock() dinsdale = MagicMock() dinsdale.id = 'dinsdale' mailingList.moderatees = [ durk, dinsdale, ] groupInfo = MagicMock() auditor = MagicMock() j.moderate_member(durk, mailingList, groupInfo, auditor) self.assertEqual(1, m_l.warn.call_count) self.assertEqual(0, mailingList.hasProperty.call_count)