Exemplo n.º 1
0
    def test_submit_form(self):
        from repoze.sendmail.interfaces import IMailDelivery
        karltesting.registerDummyRenderer("templates/join_community.pt")

        c = karltesting.DummyCommunity()
        c.moderator_names = set(["moderator1", "moderator2"])
        site = c.__parent__.__parent__
        profiles = site["profiles"] = testing.DummyModel()
        profiles["user"] = karltesting.DummyProfile()
        profiles["moderator1"] = karltesting.DummyProfile()
        profiles["moderator2"] = karltesting.DummyProfile()

        mailer = karltesting.DummyMailer()
        karltesting.registerUtility(mailer, IMailDelivery)

        karltesting.registerDummySecurityPolicy("user")
        request = testing.DummyRequest({
            "form.submitted": "1",
            "message": "Message text.",
        })
        karltesting.registerDummyRenderer(
            'karl.views:templates/email_join_community.pt')
        response = self._callFUT(c, request)

        self.assertEqual(response.location,
                         "http://example.com/communities/community/"
                         "?status_message=Your+request+has+been+sent+"
                         "to+the+moderators.")
        self.assertEqual(len(mailer), 1)
        msg = mailer.pop()
        self.assertEqual(msg.mto, ["*****@*****.**",
                                   "*****@*****.**"])
Exemplo n.º 2
0
 def test___call__with_userid_get(self):
     from repoze.sendmail.interfaces import IMailDelivery
     request = testing.DummyRequest({"user_id": "admin"})
     context = self._getContext()
     mailer = karltesting.DummyMailer()
     karltesting.registerUtility(mailer, IMailDelivery)
     controller = self._makeOne(context, request)
     karltesting.registerDummyRenderer(
         'karl.views:templates/email_add_existing.pt')
     response = controller()
     self.assertEqual(context.users.added_groups, [('admin', 'members')])
     self.assertEqual(mailer[0].mto[0], '*****@*****.**')
     self.failUnless(
         response.location.startswith('http://example.com/manage.html'))
Exemplo n.º 3
0
 def test_handle_submit_success(self):
     from repoze.sendmail.interfaces import IMailDelivery
     request = testing.DummyRequest()
     context = self._getContext()
     mailer = karltesting.DummyMailer()
     karltesting.registerUtility(mailer, IMailDelivery)
     controller = self._makeOne(context, request)
     converted = {'users': (u'admin', ), 'text': 'some_text'}
     karltesting.registerDummyRenderer(
         'karl.views:templates/email_add_existing.pt')
     response = controller.handle_submit(converted)
     self.assertEqual(context.users.added_groups, [('admin', 'members')])
     self.assertEqual(mailer[0].mto[0], '*****@*****.**')
     self.failUnless(
         response.location.startswith('http://example.com/manage.html'))
Exemplo n.º 4
0
 def _registerMailer(self):
     from repoze.sendmail.interfaces import IMailDelivery
     mailer = karltesting.DummyMailer()
     karltesting.registerUtility(mailer, IMailDelivery)
     return mailer
Exemplo n.º 5
0
    def test_handle_submit_success(self):
        from karl.models.interfaces import IProfile
        from repoze.lemonade.testing import registerContentFactory
        from repoze.sendmail.interfaces import IMailDelivery
        from repoze.workflow.testing import registerDummyWorkflow
        from karl.models.interfaces import ICommunity
        from zope.interface import directlyProvides
        workflow = registerDummyWorkflow('security')
        mailer = karltesting.DummyMailer()
        karltesting.registerUtility(mailer, IMailDelivery)
        registerContentFactory(DummyContent, IProfile)

        class DummyWhoPlugin(object):
            def remember(self, environ, identity):
                self.identity = identity
                return []

        request = self._makeRequest()
        community = testing.DummyModel()
        profiles = testing.DummyModel()
        community['profiles'] = profiles
        community.users = karltesting.DummyUsers()
        community.members_group_name = 'community:members'
        directlyProvides(community, ICommunity)
        context = self._makeContext()
        community['invite'] = context
        community.title = 'Community'
        community.description = 'Community'
        community.sessions = DummySessions()
        context.email = '*****@*****.**'
        controller = self._makeOne(context, request)
        converted = {
            'password': '******',
            'password_confirm': '1',
            'username': '******',
            'firstname': 'firstname',
            'lastname': 'lastname',
            'phone': 'phone',
            'extension': 'extension',
            'department': 'department',
            'position': 'position',
            'organization': 'organization',
            'location': 'location',
            'country': 'country',
            'websites': ['website'],
            'languages': 'languages',
            'date_format': 'en-US',
            'biography': 'bio',
        }
        karltesting.registerDummyRenderer(
            'karl.views:templates/email_accept_invitation.pt')
        response = controller.handle_submit(converted)
        self.assertEqual(response.location,
                         'http://example.com/?status_message=Welcome%21')
        self.assertEqual(community.users.added,
                         ('username', 'username', '1', ['community:members']))
        profiles = community['profiles']
        self.failUnless('username' in profiles)
        self.assertEqual(workflow.initialized, [profiles['username']])
        profile = profiles['username']
        self.assertEqual('phone', profile.phone)
        self.assertEqual('firstname', profile.firstname)
        self.assertEqual('lastname', profile.lastname)
        self.assertEqual('bio', profile.biography)
        self.failIf('invite' in community)
        self.assertEqual(len(mailer), 1)