def test_present_choices_widget(self): from pyramid_bimt.models import Group groups = [Group(id=1, name='one'), Group(id=2, name='two')] group = mock.Mock(name='test_group', product_id=1) group.upgrade_groups = groups kw = mock.MagicMock() kw.get.return_value.user.product_group = group widget = self.widget(None, kw) self.assertEqual(widget.values[0], (groups[0].id, groups[0].name)) self.assertEqual(widget.values[1], (groups[1].id, groups[1].name)) self.assertEqual(widget.template, 'upgrade_select')
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))
def _make_group( id=1, name='foo', ): return Group( id=id, name=name, )
def test_use_billing_email(self, ClickbankAPI): self.request.registry.settings['bimt.clickbank_dev_key'] = 'dev' self.request.registry.settings['bimt.clickbank_api_key'] = 'key' self.request.user.product_group.product_id = 'foo' self.request.user.email = '*****@*****.**' self.request.user.billing_email = None self.view._change_clickbank_subscription( Group(id=1, name='bar', product_id='baz')) ClickbankAPI.return_value.change_user_subscription.assert_called_with( '*****@*****.**', 'foo', 'baz') self.request.user.email = '*****@*****.**' self.request.user.billing_email = '*****@*****.**' self.view._change_clickbank_subscription( Group(id=1, name='bar', product_id='baz')) ClickbankAPI.return_value.change_user_subscription.assert_called_with( '*****@*****.**', 'foo', 'baz')
def _make_ipn_group(): group = Group( name='monthly', product_id=1, validity=31, trial_validity=7, ) Session.add(group) return group
def _make_group( id=1, name='foo', users=None, ): if users is None: users = [_make_user()] return Group( id=id, name=name, users=users, )
def add_groups(): """Init the 'admins', 'enabled', 'trial', 'unsubscribed' groups.""" with transaction.manager: admins = Group( name='admins', properties=[ GroupProperty(key=u'bimt', value=u'on'), ], ) Session.add(admins) staff = Group( name='staff', properties=[ GroupProperty(key=u'bimt', value=u'on'), ], ) Session.add(staff) enabled = Group( name='enabled', properties=[ GroupProperty(key=u'bimt', value=u'on'), ], ) Session.add(enabled) trial = Group( name='trial', properties=[ GroupProperty(key=u'bimt', value=u'on'), ], ) Session.add(trial) unsubscribed = Group( name='unsubscribed', properties=[ GroupProperty(key=u'bimt', value=u'on'), ], ) Session.add(unsubscribed) impersonators = Group( name='impersonators', properties=[ GroupProperty( key=u'description', value=u'Members can impersonate other users with login-as' ), ], ) Session.add(impersonators)
def setUp(self): settings = { 'bimt.app_title': 'BIMT', } self.request = testing.DummyRequest() self.config = testing.setUp(request=self.request, settings=settings) self.config.include('pyramid_mailer.testing') self.config.include('pyramid_chameleon') self.mailer = get_mailer(self.request) initTestingDB(users=True, groups=True) self.group = Group(name='foo') Session.add(self.group) self.user = User(email='*****@*****.**') Session.add(self.user) self.user.groups = [ self.group, ] Session.flush()
def _make_group( name='foo', product_id=13, validity=31, trial_validity=7, addon=True, forward_ipn_to_url='http://example.com', properties=None, ): if not properties: # pragma: no branch properties = [_make_property()] return Group( name=name, product_id=product_id, validity=validity, trial_validity=trial_validity, addon=addon, forward_ipn_to_url='http://example.com', properties=properties, )
def test_disable_expired_addon(self, mocked_date): mocked_date.today.return_value = date(2013, 12, 30) user = User.by_email('*****@*****.**') user.valid_to = date(2013, 12, 31) user.set_property('addon_1_valid_to', date(2013, 12, 29)) user.groups.append(Group(name='foo', product_id=1)) transaction.commit() expire_subscriptions() user = User.by_email('*****@*****.**') self.assertTrue(user.enabled) self.assertEqual([g.name for g in user.groups], ['admins', 'enabled']) self.assertEqual(len(user.audit_log_entries), 1) self.assertEqual(user.audit_log_entries[0].event_type.name, u'UserDisabled') self.assertEqual( user.audit_log_entries[0].comment, u'Addon "foo" disabled for user [email protected] (1) because its ' u'valid_to (2013-12-29) has expired.', )
def _make_group(name='foo', **kwargs): group = Group(name=name, **kwargs) Session.add(group) return group