def test_require_permissions_not_logged_in(self, mock_user, mock_jinja, mock_other_user):
        mock_user.return_value = None
        mock_other_user.return_value = None

        fn = mock.Mock(name="fn")
        fn.__name__ = 'fn'

        wrapped = permissions.require_permissions(['officer'])(fn)
        wrapped()
        self.assertEqual(fn.call_count, 0)
        mock_jinja.assert_called_with('nologin.html', {'message': 'Not logged in'})
    def test_require_permissions_valid(self, mock_user, mock_jinja, mock_other_user):
        class MockUser():
            user_permissions = []
        user = MockUser()
        user.user_permissions = ['user', 'officer']
        mock_user.return_value = user
        mock_other_user.return_value = user

        fn = mock.Mock(name="fn")
        fn.__name__ = "fn"

        wrapped = permissions.require_permissions(['user', 'officer'])(fn)
        wrapped()
        self.assertEqual(fn.call_count, 1)
    def test_require_permissions_not_officer(self, mock_user, mock_jinja, mock_other_user):
        class MockUser():
            user_permissions = []
        user = MockUser()
        user.user_permissions = ['user']
        mock_user.return_value = user
        mock_other_user.return_value = user

        fn = mock.Mock(name="fn")
        fn.__name__ = "fn"

        wrapped = permissions.require_permissions(['officer'])(fn)
        wrapped()
        self.assertEqual(fn.call_count, 0)
        mock_jinja.assert_called_with('nopermission.html',
                                      {'perms': ['officer'],
                                       'message': "Don't have permission"})