# Path: launchkey/entities/validation.py
# class AuthorizeValidator(Schema):
#     """Authorize entity validator"""
#     auth_request = validators.String(not_empty=True)
#     push_package = validators.String(if_missing=None, not_empty=True)
#     device_ids = ForEach(validators.String(), if_missing=None)
#     allow_extra_fields = True
# 
# class ConditionalGeoFenceValidator(Schema):
#     """Validates conditional geofence policies"""
#     allow_extra_fields = True
#     inside = validators.NotEmpty(accept_iterator=True)
#     outside = validators.NotEmpty(accept_iterator=True)
#     fences = ForEach(not_empty=True)
# 
#     @staticmethod
#     def _validate_python(value, state):
#         if 'inside' in value and 'outside' in value:
#             value['inside'] = PolicyBaseValidator().to_python(
#                 value['inside'], state)
#             value['outside'] = PolicyBaseValidator().to_python(
#                 value['outside'], state)
#         return value
# 
# class PolicyFenceValidator(Schema):
#     """Validates fence objects in policies"""
#     allow_extra_fields = True
#     type = validators.String(not_empty=True)
#     name = validators.String(if_missing=None, not_empty=True)
# 
#     @staticmethod
#     def _validate_other(value, state):
#         if "type" in value:
#             if value["type"] == "TERRITORY":
#                 value.update(PolicyTerritoryValidator().to_python(
#                     value, state))
#             elif value["type"] == "GEO_CIRCLE":
#                 value.update(PolicyGeoCircleValidator().to_python(
#                     value, state))
#         return value
# 
# class FenceValidator(Schema):
#     """Fence validator"""
#     allow_extra_fields = True
#     type = validators.OneOf(["GEO_CIRCLE", "TERRITORY"], if_missing=None)
#     name = validators.String(if_missing=None)
# 
#     @staticmethod
#     def _validate_python(value, _state):
#         if not value["type"]:
#             del value["type"]
#             GeoFenceValidator().to_python(value)
# 
#         elif value["type"] == "GEO_CIRCLE":
#             GeoCircleFenceValidator().to_python(value)
# 
#         elif value["type"] == "TERRITORY":
#             TerritoryFenceValidator().to_python(value)
# 
# class GeoFenceValidator(Schema):
#     """ GeoFence Validator, can represent both GeoFence and GeoCircleFence """
#     name = validators.String(if_missing=None)
#     latitude = validators.Number()
#     longitude = validators.Number()
#     radius = validators.Number()
# 
# class TerritoryFenceValidator(Schema):
#     """ TerritoryFence Validator"""
#     name = validators.String(if_missing=None)
#     type = validators.OneOf(["TERRITORY"], if_missing=None)
#     country = validators.Regex(r"^[A-Z]{2}$", not_empty=True)
#     administrative_area = validators.Regex(r"^[A-Z]{2}-[A-Z]{2}[A-Z]?$",
#                                            if_missing=None)
#     postal_code = validators.String(if_missing=None, if_empty=None)
# 
#     @staticmethod
#     def _validate_python(value, _state):
#         if not value["administrative_area"]:
#             del value["administrative_area"]
# 
#         if not value["postal_code"]:
#             del value["postal_code"]
# 
# class GeoCircleFenceValidator(GeoFenceValidator):
#     """ GeoFence Validator, can represent ONLY GeoCircleFence """
#     type = validators.OneOf(["GEO_CIRCLE"])
# 
# class DirectoryUserTOTPValidator(Schema):
#     """Directory TOTP post validator"""
#     algorithm = validators.String()
#     digits = validators.Int()
#     period = validators.Int()
#     secret = validators.String()
#     allow_extra_fields = True
# 
# class ServiceTOTPVerificationValidator(Schema):
#     """Service TOTP verification validation"""
#     valid = validators.Bool()
#     allow_extra_fields = True
# 
# class PublicKeyValidator(Schema):
#     """Public Key entity Validator"""
#     id = validators.String()
#     active = validators.Bool()
#     date_created = ValidateISODate()
#     date_expires = ValidateISODate()
#     public_key = validators.String()
#     key_type = validators.Int(if_missing=0, if_empty=0)
#     allow_extra_fields = True
# 
# Path: launchkey/exceptions/validation.py
# class AuthorizationInProgressValidator(Schema):
#     """Pre-existing auth (Busy Signal) validation"""
#     auth_request = validators.String()
#     expires = ValidateISODate()
#     from_same_service = validators.Bool()
#     allow_extra_fields = True


from datetime import datetime
from unittest import TestCase
from dateutil.tz import tzutc
from ddt import data, ddt
from formencode import Invalid
from launchkey.entities.validation import AuthorizeValidator, \
    ConditionalGeoFenceValidator, PolicyFenceValidator, FenceValidator, \
    GeoFenceValidator, TerritoryFenceValidator, GeoCircleFenceValidator, \
    DirectoryUserTOTPValidator, ServiceTOTPVerificationValidator, \
    PublicKeyValidator
from launchkey.exceptions.validation import AuthorizationInProgressValidator
            parsed['from_same_service'],
            from_same_service
        )

    def test_expires(self):
        self.data['expires'] = "2018-11-28T22:04:44Z"
        parsed = AuthorizationInProgressValidator().to_python(self.data)
        self.assertEqual(
            parsed['expires'],
            datetime(2018, 11, 28, 22, 4, 44, tzinfo=tzutc())
        )


@ddt
class TestPolicyFenceValidator(TestCase):
    def setUp(self):
        self._validator = PolicyFenceValidator()
        self._data = {}

    def test_name_is_optional(self):
        self._data = {
            "type": "TERRITORY",
            "country": "US"
        }
        parsed = self._validator.to_python(self._data)
        self.assertIsNone(parsed["name"])

    @data("United States", "Home Town", "Las Vegas")
    def test_valid_names(self, name):
        self._data = {

# Path: launchkey/entities/validation.py
# class AuthorizeValidator(Schema):
#     """Authorize entity validator"""
#     auth_request = validators.String(not_empty=True)
#     push_package = validators.String(if_missing=None, not_empty=True)
#     device_ids = ForEach(validators.String(), if_missing=None)
#     allow_extra_fields = True
# 
# class ConditionalGeoFenceValidator(Schema):
#     """Validates conditional geofence policies"""
#     allow_extra_fields = True
#     inside = validators.NotEmpty(accept_iterator=True)
#     outside = validators.NotEmpty(accept_iterator=True)
#     fences = ForEach(not_empty=True)
# 
#     @staticmethod
#     def _validate_python(value, state):
#         if 'inside' in value and 'outside' in value:
#             value['inside'] = PolicyBaseValidator().to_python(
#                 value['inside'], state)
#             value['outside'] = PolicyBaseValidator().to_python(
#                 value['outside'], state)
#         return value
# 
# class PolicyFenceValidator(Schema):
#     """Validates fence objects in policies"""
#     allow_extra_fields = True
#     type = validators.String(not_empty=True)
#     name = validators.String(if_missing=None, not_empty=True)
# 
#     @staticmethod
#     def _validate_other(value, state):
#         if "type" in value:
#             if value["type"] == "TERRITORY":
#                 value.update(PolicyTerritoryValidator().to_python(
#                     value, state))
#             elif value["type"] == "GEO_CIRCLE":
#                 value.update(PolicyGeoCircleValidator().to_python(
#                     value, state))
#         return value
# 
# class FenceValidator(Schema):
#     """Fence validator"""
#     allow_extra_fields = True
#     type = validators.OneOf(["GEO_CIRCLE", "TERRITORY"], if_missing=None)
#     name = validators.String(if_missing=None)
# 
#     @staticmethod
#     def _validate_python(value, _state):
#         if not value["type"]:
#             del value["type"]
#             GeoFenceValidator().to_python(value)
# 
#         elif value["type"] == "GEO_CIRCLE":
#             GeoCircleFenceValidator().to_python(value)
# 
#         elif value["type"] == "TERRITORY":
#             TerritoryFenceValidator().to_python(value)
# 
# class GeoFenceValidator(Schema):
#     """ GeoFence Validator, can represent both GeoFence and GeoCircleFence """
#     name = validators.String(if_missing=None)
#     latitude = validators.Number()
#     longitude = validators.Number()
#     radius = validators.Number()
# 
# class TerritoryFenceValidator(Schema):
#     """ TerritoryFence Validator"""
#     name = validators.String(if_missing=None)
#     type = validators.OneOf(["TERRITORY"], if_missing=None)
#     country = validators.Regex(r"^[A-Z]{2}$", not_empty=True)
#     administrative_area = validators.Regex(r"^[A-Z]{2}-[A-Z]{2}[A-Z]?$",
#                                            if_missing=None)
#     postal_code = validators.String(if_missing=None, if_empty=None)
# 
#     @staticmethod
#     def _validate_python(value, _state):
#         if not value["administrative_area"]:
#             del value["administrative_area"]
# 
#         if not value["postal_code"]:
#             del value["postal_code"]
# 
# class GeoCircleFenceValidator(GeoFenceValidator):
#     """ GeoFence Validator, can represent ONLY GeoCircleFence """
#     type = validators.OneOf(["GEO_CIRCLE"])
# 
# class DirectoryUserTOTPValidator(Schema):
#     """Directory TOTP post validator"""
#     algorithm = validators.String()
#     digits = validators.Int()
#     period = validators.Int()
#     secret = validators.String()
#     allow_extra_fields = True
# 
# class ServiceTOTPVerificationValidator(Schema):
#     """Service TOTP verification validation"""
#     valid = validators.Bool()
#     allow_extra_fields = True
# 
# class PublicKeyValidator(Schema):
#     """Public Key entity Validator"""
#     id = validators.String()
#     active = validators.Bool()
#     date_created = ValidateISODate()
#     date_expires = ValidateISODate()
#     public_key = validators.String()
#     key_type = validators.Int(if_missing=0, if_empty=0)
#     allow_extra_fields = True
# 
# Path: launchkey/exceptions/validation.py
# class AuthorizationInProgressValidator(Schema):
#     """Pre-existing auth (Busy Signal) validation"""
#     auth_request = validators.String()
#     expires = ValidateISODate()
#     from_same_service = validators.Bool()
#     allow_extra_fields = True


# Path: tests/test_validation.py
from datetime import datetime
from unittest import TestCase
from dateutil.tz import tzutc
from ddt import data, ddt
from formencode import Invalid
from launchkey.entities.validation import AuthorizeValidator, \
    ConditionalGeoFenceValidator, PolicyFenceValidator, FenceValidator, \
    GeoFenceValidator, TerritoryFenceValidator, GeoCircleFenceValidator, \
    DirectoryUserTOTPValidator, ServiceTOTPVerificationValidator, \
    PublicKeyValidator
from launchkey.exceptions.validation import AuthorizationInProgressValidator

            parsed['from_same_service'],
            from_same_service
        )

    def test_expires(self):
        self.data['expires'] = "2018-11-28T22:04:44Z"
        parsed = AuthorizationInProgressValidator().to_python(self.data)
        self.assertEqual(
            parsed['expires'],
            datetime(2018, 11, 28, 22, 4, 44, tzinfo=tzutc())
        )


@ddt
class TestPolicyFenceValidator(TestCase):
    def setUp(self):
        self._validator = PolicyFenceValidator()
        self._data = {}

    def test_name_is_optional(self):
        self._data = {
            "type": "TERRITORY",
            "country": "US"
        }
        parsed = self._validator.to_python(self._data)
        self.assertIsNone(parsed["name"])

    @data("United States", "Home Town", "Las Vegas")
    def test_valid_names(self, name):
        self._data = {

            "type": "TERRITORY",