# Path: django_make_app/exceptions.py
# class SchemaError(Exception):
#     pass
# 
# Path: django_make_app/schema.py
# def normalize_schema(innn):
#     """
#     :type innn: dict
#     :rtype: dict
#     """
#     app_name = innn.get(YamlSchemaKeywords.APP_NAME)
#     normalized_models = [i for i in normalize_models(innn.get(YamlSchemaKeywords.MODELS))]
# 
#     for model in normalized_models:
#         for field in model.get('fields'):
#             field['class'] = field['class'].replace("__app__", app_name)
# 
#     return {
#         YamlSchemaKeywords.APP_NAME: app_name,
#         YamlSchemaKeywords.MODELS: normalized_models
#     }
# 
# def validate_model_name(model_name):
#     if not re.search(MODEL_NAME_RE, model_name):
#         raise SchemaError("\"{}\" is not a valid name of Django model.".format(model_name))
# 
# def normalize_single_field(field):
#     """
#     :type field: unicode
#     :rtype: dict
#     """
#     field_name, field_type = field.split(":")
# 
#     if not field_type or field_type not in MAPPINGS:
#         raise SchemaError("Type {} is invalid".format(field_type))
# 
#     field_class = MAPPINGS.get(field_type)
# 
#     return {
#         "name": field_name,
#         "class": field_class(field_name) if is_callable(field_class) else field_class
#     }


from unittest import TestCase
from django_make_app.exceptions import SchemaError
from django_make_app.schema import normalize_schema, validate_model_name, normalize_single_field
import yaml
# -*- encoding: utf-8 -*-
# ! python2

from __future__ import (absolute_import, division, print_function, unicode_literals)





class SchemaTestCase(TestCase):
    def test_validate_model_name(self):
        wrong_model_name = "Book - library:fk"

        self.assertRaises(SchemaError, validate_model_name, wrong_model_name)

        validate_model_name("OkName")
        validate_model_name("Book")
        validate_model_name("Library")

    def test_normalize_single_field(self):
        expected_value = {"name": "my_name", "class": "IntegerField()"}
        self.assertDictEqual(expected_value, normalize_single_field("my_name:integer"))

# Path: django_make_app/exceptions.py
# class SchemaError(Exception):
#     pass
# 
# Path: django_make_app/schema.py
# def normalize_schema(innn):
#     """
#     :type innn: dict
#     :rtype: dict
#     """
#     app_name = innn.get(YamlSchemaKeywords.APP_NAME)
#     normalized_models = [i for i in normalize_models(innn.get(YamlSchemaKeywords.MODELS))]
# 
#     for model in normalized_models:
#         for field in model.get('fields'):
#             field['class'] = field['class'].replace("__app__", app_name)
# 
#     return {
#         YamlSchemaKeywords.APP_NAME: app_name,
#         YamlSchemaKeywords.MODELS: normalized_models
#     }
# 
# def validate_model_name(model_name):
#     if not re.search(MODEL_NAME_RE, model_name):
#         raise SchemaError("\"{}\" is not a valid name of Django model.".format(model_name))
# 
# def normalize_single_field(field):
#     """
#     :type field: unicode
#     :rtype: dict
#     """
#     field_name, field_type = field.split(":")
# 
#     if not field_type or field_type not in MAPPINGS:
#         raise SchemaError("Type {} is invalid".format(field_type))
# 
#     field_class = MAPPINGS.get(field_type)
# 
#     return {
#         "name": field_name,
#         "class": field_class(field_name) if is_callable(field_class) else field_class
#     }


# Path: tests/test_schema.py
from unittest import TestCase
from django_make_app.exceptions import SchemaError
from django_make_app.schema import normalize_schema, validate_model_name, normalize_single_field
import yaml

# -*- encoding: utf-8 -*-
# ! python2

from __future__ import (absolute_import, division, print_function, unicode_literals)





class SchemaTestCase(TestCase):
    def test_validate_model_name(self):
        wrong_model_name = "Book - library:fk"

        self.assertRaises(SchemaError, validate_model_name, wrong_model_name)

        validate_model_name("OkName")
        validate_model_name("Book")
        validate_model_name("Library")

    def test_normalize_single_field(self):
        expected_value = {"name": "my_name", "class": "IntegerField()"}
        self.assertDictEqual(expected_value, normalize_single_field("my_name:integer"))

        self.assertRaises(SchemaError, normalize_single_field, "my_name:this_type_does_not_exist")