# Path: timestream/parse/validate.py
# def validate_timestream_manifest(manifest):
#     """Validtes a json manifest, and returns the validated ``dict``
# 
#     :param dict manifest: The raw json manifest from ``json.load`` or similar.
#     :returns: The validated and type-converted manifest as a ``dict``
#     :rtype: dict
#     :raises: TypeError, MultipleInvalid
#     """
#     if not isinstance(manifest, dict):
#         raise TypeError("Manfiest should be in ``dict`` form.")
#     sch = Schema({
#         Required("name"): All(str, Length(min=1)),
#         Required("version"): All(v_num_str, Range(min=1, max=2)),
#         Required("start_datetime"): v_datetime,
#         Required("end_datetime"): v_datetime,
#         Required("image_type"): Any(*IMAGE_TYPE_CONSTANTS),
#         Required("extension"): Any(*IMAGE_EXT_CONSTANTS),
#         Required("interval", default=1): All(v_num_str, Range(min=1)),
#         "missing": list,
#     })
#     return sch(manifest)
# 
# Path: timestream/util/validation.py
# def v_date(x, format="%Y_%m_%d"):
#     """Validate string contains a date in ``fmt`` strptime-compatible format,
#     and coerce to a ``datetime.datetime`` object.
# 
#     :arg str x: String to validate.
#     :keyword str fmt: String date format to strip time with.
#     :returns:  the parsed object
#     :rtype: datetime.datetime
#     :raises: ``ValueError``
#     """
#     if isinstance(x, datetime.datetime):
#         return x
#     else:
#         return datetime.datetime.strptime(x, format)


import datetime as dt
from unittest import TestCase
from voluptuous import MultipleInvalid
from timestream.parse.validate import (
    validate_timestream_manifest,
)
from timestream.util.validation import v_date


class TestValidateTimestreamManfiest(TestCase):

    """Tests for ts.parse.validate.validate_timestream_manifest"""
    str_dict = {
        "name": "BVZ0022-GC05L-CN650D-Cam07~fullres-orig",
        "start_datetime": "2013_10_30_03_00_00",
        "end_datetime": "2013_10_30_06_00_00",
        "version": "1",
        "image_type": "jpg",
        "extension": "JPG",
        "interval": "30",
        "missing": [],
    }
    val_dict = {
        "name": "BVZ0022-GC05L-CN650D-Cam07~fullres-orig",
        "start_datetime": dt.datetime(2013, 10, 30, 3, 0, 0),
        "end_datetime": dt.datetime(2013, 10, 30, 6, 0, 0),
        "version": 1,
        "image_type": "jpg",
        "extension": "JPG",
        "interval": 30,
        "missing": [],
    }

    def test_validate_valid(self):
        """Test validate_timestream_manifest with valid manfests"""
        self.assertDictEqual(validate_timestream_manifest(self.str_dict),
                             self.val_dict)

# Path: timestream/parse/validate.py
# def validate_timestream_manifest(manifest):
#     """Validtes a json manifest, and returns the validated ``dict``
# 
#     :param dict manifest: The raw json manifest from ``json.load`` or similar.
#     :returns: The validated and type-converted manifest as a ``dict``
#     :rtype: dict
#     :raises: TypeError, MultipleInvalid
#     """
#     if not isinstance(manifest, dict):
#         raise TypeError("Manfiest should be in ``dict`` form.")
#     sch = Schema({
#         Required("name"): All(str, Length(min=1)),
#         Required("version"): All(v_num_str, Range(min=1, max=2)),
#         Required("start_datetime"): v_datetime,
#         Required("end_datetime"): v_datetime,
#         Required("image_type"): Any(*IMAGE_TYPE_CONSTANTS),
#         Required("extension"): Any(*IMAGE_EXT_CONSTANTS),
#         Required("interval", default=1): All(v_num_str, Range(min=1)),
#         "missing": list,
#     })
#     return sch(manifest)
# 
# Path: timestream/util/validation.py
# def v_date(x, format="%Y_%m_%d"):
#     """Validate string contains a date in ``fmt`` strptime-compatible format,
#     and coerce to a ``datetime.datetime`` object.
# 
#     :arg str x: String to validate.
#     :keyword str fmt: String date format to strip time with.
#     :returns:  the parsed object
#     :rtype: datetime.datetime
#     :raises: ``ValueError``
#     """
#     if isinstance(x, datetime.datetime):
#         return x
#     else:
#         return datetime.datetime.strptime(x, format)


# Path: tests/test_parse_validate.py
import datetime as dt
from unittest import TestCase
from voluptuous import MultipleInvalid
from timestream.parse.validate import (
    validate_timestream_manifest,
)
from timestream.util.validation import v_date



class TestValidateTimestreamManfiest(TestCase):

    """Tests for ts.parse.validate.validate_timestream_manifest"""
    str_dict = {
        "name": "BVZ0022-GC05L-CN650D-Cam07~fullres-orig",
        "start_datetime": "2013_10_30_03_00_00",
        "end_datetime": "2013_10_30_06_00_00",
        "version": "1",
        "image_type": "jpg",
        "extension": "JPG",
        "interval": "30",
        "missing": [],
    }
    val_dict = {
        "name": "BVZ0022-GC05L-CN650D-Cam07~fullres-orig",
        "start_datetime": dt.datetime(2013, 10, 30, 3, 0, 0),
        "end_datetime": dt.datetime(2013, 10, 30, 6, 0, 0),
        "version": 1,
        "image_type": "jpg",
        "extension": "JPG",
        "interval": 30,
        "missing": [],
    }

    def test_validate_valid(self):
        """Test validate_timestream_manifest with valid manfests"""
        self.assertDictEqual(validate_timestream_manifest(self.str_dict),
                             self.val_dict)

        self.assertDictEqual(validate_timestream_manifest(self.val_dict),