Exemplo n.º 1
0
    def setUp(self):
        self.config = testing.setUp()

        from pyramid_bimt.views.user import UserView
        self.context = testing.DummyResource()
        self.request = testing.DummyRequest(layout_manager=mock.Mock())
        self.view = UserView(self.context, self.request)
Exemplo n.º 2
0
class TestUserList(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp()

        from pyramid_bimt.views.user import UserView
        self.context = testing.DummyResource()
        self.request = testing.DummyRequest(layout_manager=mock.Mock())
        self.view = UserView(self.context, self.request)

    def tearDown(self):
        Session.remove()
        testing.tearDown()

    @mock.patch('pyramid_bimt.views.user.User')
    @mock.patch('pyramid_bimt.views.user.app_assets')
    @mock.patch('pyramid_bimt.views.user.table_assets')
    def test_view_setup(self, table_assets, app_assets, User):
        self.view.__init__(self.context, self.request)
        self.view.list()

        self.assertTrue(self.request.layout_manager.layout.hide_sidebar)
        app_assets.need.assert_called_with()
        table_assets.need.assert_called_with()

    @mock.patch('pyramid_bimt.views.user.User')
    def test_result(self, User):
        User.get_all.return_value.count.return_value = 5
        result = self.view.list()

        self.assertEqual(result, {'count': 5})
Exemplo n.º 3
0
class TestUserUnsubscribe(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp()
        add_routes_user(self.config)
        initTestingDB(users=True, groups=True, auditlog_types=True)

        from pyramid_bimt.views.user import UserView
        self.context = User.by_id(2)
        self.request = testing.DummyRequest(layout_manager=mock.Mock(),
                                            user=self.context)
        self.context.request = self.request
        self.view = UserView(self.context, self.request)

    def tearDown(self):
        Session.remove()
        testing.tearDown()

    def test_unsubscribe(self):
        self.assertFalse(self.context.unsubscribed)

        result = self.view.unsubscribe()
        self.assertTrue(self.context.unsubscribed)
        self.assertIsInstance(result, HTTPFound)
        self.assertEqual(result.location, '/')
        self.assertEqual(self.request.session.pop_flash(),
                         [u'You have been unsubscribed from newsletter.'])

        result = self.view.unsubscribe()
        self.assertTrue(self.context.unsubscribed)
        self.assertIsInstance(result, HTTPFound)
        self.assertEqual(result.location, '/')
        self.assertEqual(self.request.session.pop_flash(),
                         [u'You are already unsubscribed from newsletter.'])
Exemplo n.º 4
0
class TestUserView(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp()

        from pyramid_bimt.views.user import UserView
        self.context = _make_user()
        self.request = testing.DummyRequest(layout_manager=mock.Mock())
        self.view = UserView(self.context, self.request)

    def tearDown(self):
        Session.remove()
        testing.tearDown()

    @mock.patch('pyramid_bimt.views.user.app_assets')
    @mock.patch('pyramid_bimt.views.user.table_assets')
    def test_view_setup(self, table_assets, app_assets):
        self.view.__init__(self.context, self.request)
        self.view.list()

        self.assertTrue(self.request.layout_manager.layout.hide_sidebar)
        app_assets.need.assert_called_with()
        table_assets.need.assert_called_with()

    def test_result(self):
        result = self.view.view()
        self.assertEqual(
            result, {
                'user': self.context,
                'audit_log_entries': self.context.audit_log_entries,
                'properties': self.context.properties,
            })
Exemplo n.º 5
0
    def setUp(self):
        self.config = testing.setUp()
        add_routes_user(self.config)
        initTestingDB(users=True, groups=True, auditlog_types=True)

        from pyramid_bimt.views.user import UserView
        self.context = User.by_email('*****@*****.**')
        self.request = testing.DummyRequest(
            layout_manager=mock.Mock(), user=User.by_email('*****@*****.**'))
        self.view = UserView(self.context, self.request)
Exemplo n.º 6
0
class TestUserEnable(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp()
        add_routes_user(self.config)
        initTestingDB(users=True, groups=True, auditlog_types=True)

        from pyramid_bimt.views.user import UserView
        self.context = User.by_email('*****@*****.**')
        self.request = testing.DummyRequest(
            layout_manager=mock.Mock(), user=User.by_email('*****@*****.**'))
        self.view = UserView(self.context, self.request)

    def tearDown(self):
        Session.remove()
        testing.tearDown()

    def test_enable_enabled(self):
        self.assertTrue(self.context.enabled)

        result = self.view.enable()
        self.assertTrue(self.context.enabled)
        self.assertIsInstance(result, HTTPFound)
        self.assertEqual(result.location, '/users/')
        self.assertEqual(self.request.session.pop_flash(),
                         [u'User "*****@*****.**" already enabled, skipping.'])

    def test_enable_disabled(self):
        self.context.disable()
        self.assertFalse(self.context.enabled)

        result = self.view.enable()
        self.assertTrue(self.context.enabled)
        self.assertIsInstance(result, HTTPFound)
        self.assertEqual(result.location, '/users/')
        self.assertEqual(self.request.session.pop_flash(),
                         [u'User "*****@*****.**" enabled.'])

        entries = self.context.audit_log_entries
        self.assertEqual(len(entries), 1)
        self.assertEqual(entries[0].user.email, '*****@*****.**')
        self.assertEqual(entries[0].event_type.name, 'UserEnabled')
        self.assertEqual(entries[0].comment,
                         u'Manually enabled by [email protected].')

    def test_disable_disabled(self):
        self.context.disable()
        self.assertFalse(self.context.enabled)

        result = self.view.disable()
        self.assertFalse(self.context.enabled)
        self.assertIsInstance(result, HTTPFound)
        self.assertEqual(result.location, '/users/')
        self.assertEqual(self.request.session.pop_flash(),
                         [u'User "*****@*****.**" already disabled, skipping.'])

    def test_disable_enabled(self):
        self.assertTrue(self.context.enabled)

        result = self.view.disable()
        self.assertFalse(self.context.enabled)
        self.assertIsInstance(result, HTTPFound)
        self.assertEqual(result.location, '/users/')
        self.assertEqual(self.request.session.pop_flash(),
                         [u'User "*****@*****.**" disabled.'])

        entries = self.context.audit_log_entries
        self.assertEqual(len(entries), 1)
        self.assertEqual(entries[0].user.email, '*****@*****.**')
        self.assertEqual(entries[0].event_type.name, 'UserDisabled')
        self.assertEqual(entries[0].comment,
                         u'Manually disabled by [email protected].')