コード例 #1
0
    def test_save_success(self):
        self.request.context = User.by_id(2)

        # add a property that will get updated on save_success()
        self.request.context.set_property(key=u'foo', value=u'var')

        result = self.view.save_success(self.APPSTRUCT)
        self.assertIsInstance(result, HTTPFound)
        self.assertEqual(result.location, '/user/2/')

        user = User.by_id(2)
        self.assertEqual(user.email, '*****@*****.**')
        self.assertTrue(verify('new_secret', user.password))
        self.assertEqual(user.fullname, u'Foö Bar')
        self.assertEqual(user.affiliate, u'Aff')
        self.assertEqual(user.billing_email, '*****@*****.**')
        self.assertEqual(user.valid_to, date(2014, 2, 1))
        self.assertEqual(user.last_payment, date(2014, 1, 1))
        self.assertEqual(user.groups,
                         [Group.by_id(1), Group.by_id(3)
                          ])  # enabled user stays enabled  # noqa
        self.assertEqual(user.get_property('foo'), 'bar')
        self.assertEqual(user.get_property('baz'), 'bam')
        self.assertEqual(user.get_property('empty'), None)
        with self.assertRaises(KeyError):
            user.get_property('bimt')  # removed property

        self.assertEqual(
            self.request.session.pop_flash(),
            [u'User "*****@*****.**" modified.'],
        )
コード例 #2
0
    def test_submit_success(self):
        result = self.view.submit_success(self.APPSTRUCT)
        self.assertIsInstance(result, HTTPFound)
        self.assertEqual(result.location, '/portlet/1/edit/')

        portlet = Portlet.by_id(1)
        self.assertEqual(portlet.name, 'foo')
        self.assertEqual(portlet.groups, [Group.by_id(1)])
        self.assertEqual(portlet.exclude_groups, [Group.by_id(2)])
        self.assertEqual(portlet.position, PortletPositions.below_sidebar.name)
        self.assertEqual(portlet.weight, 10)
        self.assertEqual(portlet.html, u'Foo')

        self.assertEqual(self.request.session.pop_flash(),
                         [u'Portlet "foo" added.'])
コード例 #3
0
    def submit_success(self, appstruct):
        user = User(
            email=appstruct.get('email'),
            fullname=appstruct.get('fullname'),
            affiliate=appstruct.get('affiliate'),
            billing_email=appstruct.get('billing_email'),
            valid_to=appstruct.get('valid_to'),
            last_payment=appstruct.get('last_payment'),
            groups=[Group.by_id(group_id) for group_id in appstruct.get('groups', [])],  # noqa
            properties=[UserProperty(key=prop.get('key'), value=prop.get('value'))  # noqa
                        for prop in appstruct.get('properties', [])],
        )

        if appstruct.get('password'):  # pragma: no branch
            user.password = encrypt(appstruct['password'])

        Session.add(user)
        Session.flush()
        self.request.registry.notify(
            UserCreated(
                self.request,
                user,
                appstruct.get('password'),
                u'Created manually by {}'.format(self.request.user.email)
            )
        )
        self.request.session.flash(u'User "{}" added.'.format(user.email))
        return HTTPFound(
            location=self.request.route_path('user_view', user_id=user.id))
コード例 #4
0
    def setUp(self):
        self.config = testing.setUp()
        initTestingDB(groups=True)
        Group.by_id(1).product_id = 'old_id'
        Session.flush()

        self.request = testing.DummyRequest()
コード例 #5
0
    def submit_success(self, appstruct):
        group = Group(
            name=appstruct.get('name'),
            product_id=appstruct.get('product_id'),
            validity=appstruct.get('validity'),
            trial_validity=appstruct.get('trial_validity'),
            addon=appstruct.get('addon'),
            forward_ipn_to_url=appstruct.get('forward_ipn_to_url'),
            users=[
                User.by_id(user_id) for user_id in appstruct.get('users', [])
            ],  # noqa
            upgrade_groups=[
                Group.by_id(group_id)
                for group_id in appstruct.get('upgrade_groups', [])
            ],  # noqa
            properties=[
                GroupProperty(key=prop['key'], value=prop['value'])
                for prop in appstruct.get('properties', [])
            ],
        )

        Session.add(group)
        Session.flush()
        self.request.session.flash(u'Group "{}" added.'.format(group.name))
        return HTTPFound(
            location=self.request.route_path('group_edit', group_id=group.id))
コード例 #6
0
    def test_submit_success(self):
        result = self.view.submit_success(self.APPSTRUCT)
        self.assertIsInstance(result, HTTPFound)
        self.assertEqual(result.location, '/mailing/1/edit/')

        mailing = Mailing.by_id(1)
        self.assertEqual(mailing.name, 'foo')
        self.assertEqual(mailing.groups, [Group.by_id(1)])
        self.assertEqual(mailing.exclude_groups, [Group.by_id(2)])
        self.assertEqual(mailing.trigger, MailingTriggers.never.name)
        self.assertEqual(mailing.days, 30)
        self.assertEqual(mailing.subject, u'Foö')
        self.assertEqual(mailing.body, u'Bär')

        self.assertEqual(self.request.session.pop_flash(),
                         [u'Mailing "foo" added.'])
コード例 #7
0
    def save_success(self, appstruct):
        group = self.request.context

        group.name = appstruct.get('name')
        group.product_id = appstruct.get('product_id')
        group.validity = appstruct.get('validity')
        group.trial_validity = appstruct.get('trial_validity')
        group.addon = appstruct.get('addon')
        group.forward_ipn_to_url = appstruct.get('forward_ipn_to_url')

        group.users = [
            User.by_id(user_id) for user_id in appstruct.get('users', [])
        ]  # noqa
        group.upgrade_groups = [
            Group.by_id(group_id)
            for group_id in appstruct.get('upgrade_groups', [])
        ]  # noqa

        # remove properties that are not present in appstruct
        for prop in copy.copy(group.properties):
            if prop.key not in [p['key'] for p in appstruct['properties']]:
                group.properties.remove(prop)

        # update/create properties present in appstruct
        for prop in appstruct['properties']:
            if group.get_property(prop['key'], None) is not None:
                group.set_property(key=prop['key'], value=prop['value'])
            else:
                group.properties.append(
                    GroupProperty(key=prop['key'], value=prop['value']))

        self.request.session.flash(u'Group "{}" modified.'.format(group.name))
        return HTTPFound(
            location=self.request.route_path('group_edit', group_id=group.id))
コード例 #8
0
    def upgrade_subscription_success(self, appstruct):
        old_group = self.request.user.product_group
        new_group = Group.by_id(
            appstruct['change_subscription']['upgrade_subscription'])

        try:
            receipt = self._change_clickbank_subscription(new_group)
        except ClickbankException as exc:
            comment = (
                u'Your upgrade has not completed successfully. Support team '
                'has been notified and they are looking into the problem.')
            self.request.session.flash(comment)
            self.request.registry.notify(
                UserSubscriptionChangeFailed(self.request,
                                             self.request.user,
                                             comment=comment))
            logger.exception(exc)
            return HTTPFound(location=self.request.path_url)

        self.request.user.groups.remove(old_group)
        self.request.user.groups.append(new_group)
        comment = (u'Your subscription ({}) has been upgraded '
                   'from {} to {}.'.format(receipt, old_group.name,
                                           new_group.name))
        self.request.user.set_property('upgrade_completed', True)
        self.request.session.flash(comment)
        self.request.registry.notify(
            UserSubscriptionChanged(self.request,
                                    self.request.user,
                                    comment=comment))
        return HTTPFound(location=self.request.path_url)
コード例 #9
0
    def test_save_success(self):
        self.request.context = Mailing.by_id(1)

        result = self.view.save_success(self.APPSTRUCT)
        self.assertIsInstance(result, HTTPFound)
        self.assertEqual(result.location, '/mailing/1/edit/')

        mailing = Mailing.by_id(1)
        self.assertEqual(mailing.name, 'bar')
        self.assertEqual(mailing.groups, [Group.by_id(1), Group.by_id(2)])
        self.assertEqual(mailing.exclude_groups, [Group.by_id(3)])
        self.assertEqual(mailing.trigger, MailingTriggers.after_created.name)
        self.assertEqual(mailing.days, 7)
        self.assertEqual(mailing.subject, u'Bär')
        self.assertEqual(mailing.body, u'Bän')
        self.assertEqual(self.request.session.pop_flash(),
                         [u'Mailing "bar" modified.'])
コード例 #10
0
 def __getitem__(self, key):
     group = Group.by_id(key)
     if group:
         group.__parent__ = self
         group.__name__ = key
         return group
     else:
         raise KeyError
コード例 #11
0
    def save_success(self, appstruct):
        portlet = self.request.context

        portlet.name = appstruct['name']
        portlet.groups = [
            Group.by_id(group_id) for group_id in appstruct['groups']
        ]  # noqa
        portlet.exclude_groups = [
            Group.by_id(group_id) for group_id in appstruct['exclude_groups']
        ]  # noqa
        portlet.position = appstruct['position']
        portlet.weight = appstruct['weight']
        portlet.html = appstruct['html']

        self.request.session.flash(u'Portlet "{}" modified.'.format(
            portlet.name))
        return HTTPFound(location=self.request.route_path(
            'portlet_edit', portlet_id=portlet.id))
コード例 #12
0
    def test_save_success(self):
        self.request.context = Portlet.by_id(1)

        result = self.view.save_success(self.APPSTRUCT)
        self.assertIsInstance(result, HTTPFound)
        self.assertEqual(result.location, '/portlet/1/edit/')

        portlet = Portlet.by_id(1)
        self.assertEqual(portlet.name, 'bar')
        self.assertEqual(portlet.groups, [Group.by_id(2), Group.by_id(3)])
        self.assertEqual(portlet.exclude_groups, [
            Group.by_id(4),
        ])
        self.assertEqual(portlet.position, PortletPositions.above_content.name)
        self.assertEqual(portlet.weight, -10)
        self.assertEqual(portlet.html, u'Bar')
        self.assertEqual(self.request.session.pop_flash(),
                         [u'Portlet "bar" modified.'])
コード例 #13
0
    def save_success(self, appstruct):
        mailing = self.request.context

        mailing.name = appstruct['name']
        mailing.groups = [
            Group.by_id(group_id) for group_id in appstruct['groups']
        ]  # noqa
        mailing.exclude_groups = [
            Group.by_id(group_id) for group_id in appstruct['exclude_groups']
        ]  # noqa
        mailing.trigger = appstruct['trigger']
        mailing.days = appstruct['days']
        mailing.subject = appstruct['subject']
        mailing.body = appstruct['body']

        self.request.session.flash(u'Mailing "{}" modified.'.format(
            mailing.name))
        return HTTPFound(location=self.request.route_path(
            'mailing_edit', mailing_id=mailing.id))
コード例 #14
0
    def submit_success(self, appstruct):
        portlet = Portlet(
            name=appstruct.get('name'),
            groups=[
                Group.by_id(group_id) for group_id in appstruct.get('groups')
            ],  # noqa
            exclude_groups=[
                Group.by_id(group_id)
                for group_id in appstruct.get('exclude_groups')
            ],  # noqa
            position=appstruct.get('position'),
            weight=appstruct.get('weight'),
            html=appstruct.get('html'),
        )

        Session.add(portlet)
        Session.flush()
        self.request.session.flash(u'Portlet "{}" added.'.format(portlet.name))
        return HTTPFound(location=self.request.route_path(
            'portlet_edit', portlet_id=portlet.id))
コード例 #15
0
    def test_save_success_remove_properties(self):
        self.request.context = Group.by_id(1)

        self.APPSTRUCT['properties'] = []
        result = self.view(self.request).save_success(self.APPSTRUCT)
        self.assertIsInstance(result, HTTPFound)
        self.assertEqual(result.location, '/group/1/edit/')

        group = Group.by_id(1)
        self.assertEqual(group.name, 'foo')
        self.assertEqual(group.product_id, 13)
        self.assertEqual(group.validity, 31)
        self.assertEqual(group.trial_validity, 7)
        self.assertEqual(group.addon, True)
        self.assertEqual(group.forward_ipn_to_url, 'http://example.com')
        self.assertEqual(group.users, [
            User.by_id(2),
        ])
        self.assertIsNone(group.get_property('foo', None))
        self.assertEqual(self.request.session.pop_flash(),
                         [u'Group "foo" modified.'])
コード例 #16
0
    def submit_success(self, appstruct):
        mailing = Mailing(
            name=appstruct['name'],
            groups=[
                Group.by_id(group_id) for group_id in appstruct.get('groups')
            ],  # noqa
            exclude_groups=[
                Group.by_id(group_id)
                for group_id in appstruct.get('exclude_groups')
            ],  # noqa
            trigger=appstruct['trigger'],
            days=appstruct['days'],
            subject=appstruct['subject'],
            body=appstruct['body'],
        )

        Session.add(mailing)
        Session.flush()
        self.request.session.flash(u'Mailing "{}" added.'.format(mailing.name))
        return HTTPFound(location=self.request.route_path(
            'mailing_edit', mailing_id=mailing.id))
コード例 #17
0
    def test_submit_success(self):
        result = self.view.submit_success(self.APPSTRUCT)
        self.assertIsInstance(result, HTTPFound)
        self.assertEqual(result.location, '/group/7/edit/')

        group = Group.by_id(7)
        self.assertEqual(group.name, 'foo')
        self.assertEqual(group.product_id, '13')
        self.assertEqual(group.validity, 30)
        self.assertEqual(group.trial_validity, 7)
        self.assertEqual(group.addon, False)
        self.assertEqual(group.forward_ipn_to_url, 'http://example.com')
        self.assertEqual(group.users, [
            User.by_id(1),
        ])
        self.assertEqual(group.upgrade_groups, [
            Group.by_id(1),
        ])
        self.assertEqual(group.get_property('foo'), 'bar')

        self.assertEqual(self.request.session.pop_flash(),
                         [u'Group "foo" added.'])
コード例 #18
0
    def test_save_success(self):
        self.request.context = Group.by_id(1)

        # add a property that will get updated on save_success()
        self.request.context.set_property(key=u'foo', value=u'var')

        result = self.view(self.request).save_success(self.APPSTRUCT)
        self.assertIsInstance(result, HTTPFound)
        self.assertEqual(result.location, '/group/1/edit/')

        group = Group.by_id(1)
        self.assertEqual(group.name, 'foo')
        self.assertEqual(group.product_id, 13)
        self.assertEqual(group.validity, 31)
        self.assertEqual(group.trial_validity, 7)
        self.assertEqual(group.addon, True)
        self.assertEqual(group.forward_ipn_to_url, 'http://example.com')
        self.assertEqual(group.users, [
            User.by_id(2),
        ])
        self.assertEqual(group.get_property('foo'), 'bar')
        self.assertEqual(group.get_property('baz'), 'bam')
        self.assertEqual(self.request.session.pop_flash(),
                         [u'Group "foo" modified.'])
コード例 #19
0
    def test_save_success_disabled_stays_disabled(self):
        self.request.context = User.by_id(2)
        self.request.context.disable()

        result = self.view.save_success(self.APPSTRUCT)
        self.assertIsInstance(result, HTTPFound)
        self.assertEqual(result.location, '/user/2/')

        user = User.by_id(2)

        self.assertEqual(user.groups, [Group.by_id(1)])
        self.assertEqual(
            self.request.session.pop_flash(),
            [u'User "*****@*****.**" modified.'],
        )
コード例 #20
0
    def test_submit_success(self, UserCreated):
        result = self.view.submit_success(self.APPSTRUCT)
        self.assertIsInstance(result, HTTPFound)
        self.assertEqual(result.location, '/user/4/')
        self.assertTrue(self.request.registry.notify.called)

        user = User.by_id(4)
        self.assertEqual(user.email, '*****@*****.**')
        self.assertTrue(verify('secret', user.password))
        self.assertEqual(user.fullname, u'Foö Bar')
        self.assertEqual(user.affiliate, u'Aff')
        self.assertEqual(user.billing_email, '*****@*****.**')
        self.assertEqual(user.valid_to, date(2014, 2, 1))
        self.assertEqual(user.last_payment, date(2014, 1, 1))
        self.assertEqual(user.groups, [
            Group.by_id(1),
        ])
        self.assertEqual(user.get_property('foo'), 'bar')
        UserCreated.assert_called_with(self.request, user, 'secret',
                                       u'Created manually by [email protected]')

        self.assertEqual(self.request.session.pop_flash(),
                         [u'User "*****@*****.**" added.'])
コード例 #21
0
    def save_success(self, appstruct):
        user = self.request.context

        user.email = appstruct.get('email')
        user.fullname = appstruct.get('fullname')
        user.affiliate = appstruct.get('affiliate')
        user.billing_email = appstruct.get('billing_email')
        user.valid_to = appstruct.get('valid_to')
        user.last_payment = appstruct.get('last_payment')

        if appstruct.get('password'):
            user.password = encrypt(appstruct['password'])

        groups = [Group.by_id(group_id) for group_id in appstruct['groups']]
        enabled = Group.by_name('enabled')
        if enabled in user.groups:
            groups.append(enabled)
        user.groups = groups

        # remove properties that are not present in appstruct
        for prop in copy.copy(user.properties):
            if prop.key not in [p['key'] for p in appstruct['properties']]:
                user.properties.remove(prop)

        # update/create properties present in appstruct
        for prop in appstruct['properties']:
            if user.has_property(prop['key']):
                user.set_property(key=prop['key'], value=prop.get('value'))
            else:
                user.properties.append(
                    UserProperty(key=prop['key'], value=prop.get('value')))

        self.request.session.flash(
            u'User "{}" modified.'.format(user.email))
        return HTTPFound(
            location=self.request.route_path(
                'user_view', user_id=user.id))