# Path: habitat/views/flight.py
# def validate(new, old, userctx, secobj):
# def end_start_including_payloads_map(doc):
# def launch_time_including_payloads_map(doc):
# def unapproved_name_including_payloads_map(doc):
# def all_name_map(doc):
# 
# Path: habitat/views/utils.py
# def read_json_schema(schemaname):
#     mypath = os.path.dirname(inspect.getfile(inspect.currentframe()))
#     path = os.path.join(mypath, "..", "..", "couchdb", "schemas", schemaname)
#     with open(path) as f:
#         schema = json.load(f)
#     return schema


from ...views import flight
from ...views.utils import read_json_schema
from couch_named_python import ForbiddenError, UnauthorizedError
from copy import deepcopy
from nose.tools import assert_raises
import mox
        assert_raises(UnauthorizedError, flight.validate, approved, unapproved,
                {'roles': []}, {})
        assert_raises(UnauthorizedError, flight.validate, approved, approved,
                {'roles': []}, {})
        flight.validate(unapproved, approved, {'roles': ['manager']}, {})
        flight.validate(approved, approved, {'roles': ['manager']}, {})

    def test_only_managers_edit_docs(self):
        new = deepcopy(doc)
        new['name'] = "Edited Launch"
        assert_raises(UnauthorizedError, flight.validate, new, doc,
                {'roles': []}, {})
        flight.validate(new, doc, {'roles': ['manager']}, {})

    def test_start_before_end(self):
        mydoc = deepcopy(doc)
        # start at the same local time but in UTC not +01:00, so 'after'
        mydoc['start'] = "2012-07-15T00:00:00Z"
        assert_raises(ForbiddenError, flight.validate, mydoc, {},
                {'roles': []}, {})

    def test_window_less_than_a_week(self):
        mydoc = deepcopy(doc)
        mydoc['start'] = "2012-07-07T00:00:00+01:00"
        assert_raises(ForbiddenError, flight.validate, mydoc, {},
                {'roles': []}, {})

    def test_extend(self):
        new = deepcopy(doc)
        new['end'] = "2012-08-07T00:00:00+01:00"

# Path: habitat/views/flight.py
# def validate(new, old, userctx, secobj):
# def end_start_including_payloads_map(doc):
# def launch_time_including_payloads_map(doc):
# def unapproved_name_including_payloads_map(doc):
# def all_name_map(doc):
# 
# Path: habitat/views/utils.py
# def read_json_schema(schemaname):
#     mypath = os.path.dirname(inspect.getfile(inspect.currentframe()))
#     path = os.path.join(mypath, "..", "..", "couchdb", "schemas", schemaname)
#     with open(path) as f:
#         schema = json.load(f)
#     return schema


# Path: habitat/tests/test_views/test_flight.py
from ...views import flight
from ...views.utils import read_json_schema
from couch_named_python import ForbiddenError, UnauthorizedError
from copy import deepcopy
from nose.tools import assert_raises
import mox

        assert_raises(UnauthorizedError, flight.validate, approved, unapproved,
                {'roles': []}, {})
        assert_raises(UnauthorizedError, flight.validate, approved, approved,
                {'roles': []}, {})
        flight.validate(unapproved, approved, {'roles': ['manager']}, {})
        flight.validate(approved, approved, {'roles': ['manager']}, {})

    def test_only_managers_edit_docs(self):
        new = deepcopy(doc)
        new['name'] = "Edited Launch"
        assert_raises(UnauthorizedError, flight.validate, new, doc,
                {'roles': []}, {})
        flight.validate(new, doc, {'roles': ['manager']}, {})

    def test_start_before_end(self):
        mydoc = deepcopy(doc)
        # start at the same local time but in UTC not +01:00, so 'after'
        mydoc['start'] = "2012-07-15T00:00:00Z"
        assert_raises(ForbiddenError, flight.validate, mydoc, {},
                {'roles': []}, {})

    def test_window_less_than_a_week(self):
        mydoc = deepcopy(doc)
        mydoc['start'] = "2012-07-07T00:00:00+01:00"
        assert_raises(ForbiddenError, flight.validate, mydoc, {},
                {'roles': []}, {})

    def test_extend(self):
        new = deepcopy(doc)
        new['end'] = "2012-08-07T00:00:00+01:00"

        assert_raises(UnauthorizedError, flight.validate, new, doc,