예제 #1
0
 def test_addon_group(self):
     User.by_email('*****@*****.**').groups = [
         _make_group(name='foo', product_id='foo'),
         _make_group(name='bar', product_id='bar', addon=True),
     ]
     self.assertEqual(
         User.by_email('*****@*****.**').product_group.name, 'foo')
예제 #2
0
    def test_group_cant_be_upgrade_group_to_its_upgrade_group(self):
        from pyramid_bimt.tests.test_group_model import _make_group
        self.request.context = _make_group(name='test1', product_id=1)
        group2 = _make_group(name='test2', product_id=2)
        group2.upgrade_groups = [self.request.context]
        view = self.view(self.request)

        self.assertNotIn((str(group2.id), group2.name),
                         view.schema.get('upgrade_groups').widget.values)
예제 #3
0
    def test_multiple_product_groups(self):
        product_group_foo = _make_group(name='foo', product_id='foo')
        product_group_bar = _make_group(name='bar', product_id='bar')
        product_group_foo.users.append(User.by_email('*****@*****.**'))
        product_group_bar.users.append(User.by_email('*****@*****.**'))

        from sqlalchemy.orm.exc import MultipleResultsFound
        with self.assertRaises(MultipleResultsFound):
            User.by_email('*****@*****.**').product_group
예제 #4
0
    def setUp(self):
        from pyramid_bimt.tests.test_group_model import _make_group
        initTestingDB(groups=True, users=True, auditlog_types=True)
        self.config = testing.setUp(request=testing.DummyRequest())
        configure(self.config)
        self.request = get_current_request()
        self.request.user = User.by_id(1)
        self.group1 = _make_group(name='group1', product_id='1')
        self.group2 = _make_group(name='group2', product_id='2')
        self.request.user.groups = [self.group1, ]

        from pyramid_layout.layout import LayoutManager

        self.request.layout_manager = LayoutManager('context', 'requestr')
예제 #5
0
    def test_non_product_group_cant_have_upgrade_groups(self):
        from pyramid_bimt.tests.test_group_model import _make_group
        self.request.context = _make_group(name='test', product_id=None)
        view = self.view(self.request)

        self.assertIn(self.request.context, Group.get_all().all())
        self.assertIsNone(view.schema.get('upgrade_groups'))
예제 #6
0
 def test_user_in_group_and_exclude_group(self):
     group1 = _make_group()
     group2 = _make_group(name='bar')
     _make_user(groups=[
         group1,
         group2,
     ])
     _make_portlet(name='foo',
                   groups=[
                       group1,
                   ],
                   exclude_groups=[
                       group2,
                   ],
                   position='above_content')
     portlets = Portlet.by_user_and_position(User.by_id(1), 'above_content')
     self.assertEqual(len(portlets), 0)
예제 #7
0
 def test_no_group(self):
     group = _make_group()
     _make_user(groups=[
         group,
     ])
     _make_portlet(name='foo', groups=[], position='above_content')
     portlets = Portlet.by_user_and_position(User.by_id(1), 'above_content')
     self.assertEqual(len(portlets), 0)
예제 #8
0
 def test_group_filter(self):
     group = _make_group()
     other_group = _make_group(name='other')
     _make_user(groups=[
         group,
     ])
     _make_portlet(name='foo', groups=[
         group,
     ], position='above_content')
     _make_portlet(name='bar',
                   groups=[
                       other_group,
                   ],
                   position='above_content')  # noqa
     portlets = Portlet.by_user_and_position(User.by_id(1), 'above_content')
     self.assertEqual(len(portlets), 1)
     self.assertEqual(portlets[0].name, 'foo')
예제 #9
0
    def test_group_cant_be_upgrade_group_to_itself(self):
        from pyramid_bimt.tests.test_group_model import _make_group
        self.request.context = _make_group(name='test1', product_id=1)
        view = self.view(self.request)

        self.assertIn(self.request.context, Group.get_all().all())
        self.assertNotIn((str(
            (self.request.context.id)), self.request.context.name),
                         view.schema.get('upgrade_groups').widget.values)
예제 #10
0
 def test_acl_admin(self):
     from pyramid.security import ALL_PERMISSIONS
     user = _make_user(email='*****@*****.**')
     user.groups = [_make_group(name='admins')]
     self.assertEqual(
         user.__acl__,
         [
             (Allow, 'g:admins', ALL_PERMISSIONS),
             DENY_ALL,
         ])
예제 #11
0
    def test_result(self, Group):
        group = _make_group()
        Group.get_all.return_value.all.return_value = [
            group,
        ]
        result = self.view.list()

        self.assertEqual(result, {
            'groups': [
                group,
            ],
        })
예제 #12
0
 def test_appstruct_full_context(self):
     from pyramid_bimt.tests.test_group_model import _make_group
     self.request.context = _make_group(
         name='foo',
         product_id=13,
         validity=31,
         trial_validity=7,
         addon=True,
         forward_ipn_to_url='http://example.com')
     self.request.context.set_property('foo', u'bar')
     self.request.context.users = [
         User.by_email('*****@*****.**'),
     ]
     self.request.context.upgrade_groups = [
         _make_group(name='group2'),
     ]
     self.assertEqual(
         self.view(self.request).appstruct(), {
             'name': 'foo',
             'product_id': 13,
             'validity': 31,
             'trial_validity': 7,
             'addon': True,
             'forward_ipn_to_url': 'http://example.com',
             'users': [
                 '3',
             ],
             'upgrade_groups': [
                 '8',
             ],
             'properties': [
                 {
                     'key': u'foo',
                     'value': u'bar'
                 },
             ],
         })
예제 #13
0
 def test_appstruct_base_context(self):
     from pyramid_bimt.tests.test_group_model import _make_group
     self.request.context = _make_group(name='test')
     self.assertEqual(self.view(self.request).appstruct(), {'name': 'test'})
예제 #14
0
 def test_single_product_group(self):
     product_group = _make_group(name='foo', product_id='foo')
     product_group.users.append(User.by_email('*****@*****.**'))
     self.assertEqual(
         User.by_email('*****@*****.**').product_group.name, 'foo')