# Path: habitat/views/utils.py
# def read_json_schema(schemaname):
# def must_be_admin(user,
#                   msg="Only server administrators may edit this document."):
# def _validate_timestr(data):
# def _validate_base64(data):
# def _validate_timezone(data):
# def _validate_formats(data, schema):
# def validate_doc(data, schema):
# def only_validates(doc_type):
#     def decorator(func):
#         def wrapped(new, old, userctx, secobj):


import copy
from nose.tools import assert_raises
from couch_named_python import UnauthorizedError, ForbiddenError
from ...views import utils
#
# This file is part of habitat.
#
# habitat is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# habitat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with habitat.  If not, see <http://www.gnu.org/licenses/>.

"""
Unit tests for the view function utilities
"""




def test_must_be_admin():
    nonadmin = {'roles': ['not an admin']}
    noroles = {'noroles': True}
    oddroles = {'roles': 12}
    admin = {'roles': ['_admin']}
    alsoadmin = {'roles': ['lowly', '_admin']}


# Path: habitat/views/utils.py
# def read_json_schema(schemaname):
# def must_be_admin(user,
#                   msg="Only server administrators may edit this document."):
# def _validate_timestr(data):
# def _validate_base64(data):
# def _validate_timezone(data):
# def _validate_formats(data, schema):
# def validate_doc(data, schema):
# def only_validates(doc_type):
#     def decorator(func):
#         def wrapped(new, old, userctx, secobj):


# Path: habitat/tests/test_views/test_utils.py
import copy
from nose.tools import assert_raises
from couch_named_python import UnauthorizedError, ForbiddenError
from ...views import utils

#
# This file is part of habitat.
#
# habitat is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# habitat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with habitat.  If not, see <http://www.gnu.org/licenses/>.

"""
Unit tests for the view function utilities
"""




def test_must_be_admin():
    nonadmin = {'roles': ['not an admin']}
    noroles = {'noroles': True}
    oddroles = {'roles': 12}
    admin = {'roles': ['_admin']}
    alsoadmin = {'roles': ['lowly', '_admin']}


    assert_raises(UnauthorizedError, utils.must_be_admin, nonadmin)