# Path: gdcdatamodel/validators/json_validators.py
# class GDCJSONValidator(object):
#     def __init__(self):
#         self.schemas = gdcdictionary
# 
#     def iter_errors(self, doc):
#         # Note whenever gdcdictionary use a newer version of jsonschema
#         # we need to update the Validator
#         validator = Draft4Validator(self.schemas.schema[doc['type']])
#         return validator.iter_errors(doc)
# 
#     def record_errors(self, entities):
#         for entity in entities:
#             json_doc = entity.doc
#             if 'type' not in json_doc:
#                 entity.record_error(
#                     "'type' is a required property", keys=['type'])
#                 break
#             if json_doc['type'] not in self.schemas.schema:
#                 entity.record_error(
#                     "specified type: {} is not in the current data model"
#                     .format(json_doc['type']), keys=['type'])
#                 break
#             for error in self.iter_errors(json_doc):
#                 # the key will be  property.sub property for nested properties
#                 errors = [str(e) for e in error.path if error.path]
#                 keys = ['.'.join(errors)] if errors else []
#                 if not keys:
#                     keys = get_keys(error.message)
#                 message = error.message
#                 if error.context:
#                     message += ': {}'.format(' and '.join([c.message for c in error.context]))
#                 entity.record_error(message, keys=keys)
#             # additional validators go here
# 
# Path: gdcdatamodel/validators/graph_validators.py
# class GDCGraphValidator(object):
#     '''
#     Validator that validates entities' relationship with existing nodes in
#     database.
# 
#     '''
#     def __init__(self):
#         self.schemas = gdcdictionary
#         self.required_validators = {
#             'links_validator': GDCLinksValidator(),
#             'uniqueKeys_validator': GDCUniqueKeysValidator()
#         }
#         self.optional_validators = {}
# 
#     def record_errors(self, graph, entities):
#         for validator in self.required_validators.values():
#             validator.validate(entities, graph)
# 
#         for entity in entities:
#             schema = self.schemas.schema[entity.node.label]
#             validators = schema.get('validators')
#             if validators:
#                 for validator_name in validators:
#                     self.optional_validators[validator_name].validate()
# 
# Path: test/conftest.py
# class BaseTestCase(unittest.TestCase):
#     def setUp(self):
#         truncate(self.g.engine)
# 
#     def tearDown(self):
#         truncate(self.g.engine)


import uuid
from copy import copy
from gdcdatamodel.validators import GDCJSONValidator, GDCGraphValidator
from gdcdatamodel.models import *
from test.conftest import BaseTestCase




class MockSubmissionEntity(object):
    def __init__(self):
        self.errors = []
        self.node = None
        self.doc = {}

    def record_error(self, message, **kwargs):
        self.errors.append(dict(message=message, **kwargs))


class TestValidators(BaseTestCase):
    def setUp(self):
        super(TestValidators, self).setUp()


# Path: gdcdatamodel/validators/json_validators.py
# class GDCJSONValidator(object):
#     def __init__(self):
#         self.schemas = gdcdictionary
# 
#     def iter_errors(self, doc):
#         # Note whenever gdcdictionary use a newer version of jsonschema
#         # we need to update the Validator
#         validator = Draft4Validator(self.schemas.schema[doc['type']])
#         return validator.iter_errors(doc)
# 
#     def record_errors(self, entities):
#         for entity in entities:
#             json_doc = entity.doc
#             if 'type' not in json_doc:
#                 entity.record_error(
#                     "'type' is a required property", keys=['type'])
#                 break
#             if json_doc['type'] not in self.schemas.schema:
#                 entity.record_error(
#                     "specified type: {} is not in the current data model"
#                     .format(json_doc['type']), keys=['type'])
#                 break
#             for error in self.iter_errors(json_doc):
#                 # the key will be  property.sub property for nested properties
#                 errors = [str(e) for e in error.path if error.path]
#                 keys = ['.'.join(errors)] if errors else []
#                 if not keys:
#                     keys = get_keys(error.message)
#                 message = error.message
#                 if error.context:
#                     message += ': {}'.format(' and '.join([c.message for c in error.context]))
#                 entity.record_error(message, keys=keys)
#             # additional validators go here
# 
# Path: gdcdatamodel/validators/graph_validators.py
# class GDCGraphValidator(object):
#     '''
#     Validator that validates entities' relationship with existing nodes in
#     database.
# 
#     '''
#     def __init__(self):
#         self.schemas = gdcdictionary
#         self.required_validators = {
#             'links_validator': GDCLinksValidator(),
#             'uniqueKeys_validator': GDCUniqueKeysValidator()
#         }
#         self.optional_validators = {}
# 
#     def record_errors(self, graph, entities):
#         for validator in self.required_validators.values():
#             validator.validate(entities, graph)
# 
#         for entity in entities:
#             schema = self.schemas.schema[entity.node.label]
#             validators = schema.get('validators')
#             if validators:
#                 for validator_name in validators:
#                     self.optional_validators[validator_name].validate()
# 
# Path: test/conftest.py
# class BaseTestCase(unittest.TestCase):
#     def setUp(self):
#         truncate(self.g.engine)
# 
#     def tearDown(self):
#         truncate(self.g.engine)


# Path: test/test_validators.py
import uuid
from copy import copy
from gdcdatamodel.validators import GDCJSONValidator, GDCGraphValidator
from gdcdatamodel.models import *
from test.conftest import BaseTestCase





class MockSubmissionEntity(object):
    def __init__(self):
        self.errors = []
        self.node = None
        self.doc = {}

    def record_error(self, message, **kwargs):
        self.errors.append(dict(message=message, **kwargs))


class TestValidators(BaseTestCase):
    def setUp(self):
        super(TestValidators, self).setUp()


        self.graph_validator = GDCGraphValidator()