<commit_before>from django.db import models
from django.test import TestCase

from multi_import.mappings import Mapping, BoundMapping


class Person(models.Model):
    first_name = models.CharField()
    last_name = models.CharField()
    partner = models.ForeignKey('Person', related_name='person_partner')
    children = models.ManyToManyField('Person', related_name='person_children')

    @property
    def name(self):
        return self.first_name + ' ' + self.last_name


class MappingTests(TestCase):

    def test_simple_field(self):
        mapping = Mapping('first_name')
        bound_mapping = BoundMapping.bind_mapping(mapping, Person)

        self.assertEqual(bound_mapping.model, Person)
        self.assertEqual(bound_mapping.column_name, 'first_name')
        self.assertEqual(bound_mapping.field_name, 'first_name')
        self.assertEqual(bound_mapping.readonly, False)
        self.assertEqual(bound_mapping.model_init, True)

    def test_custom_column_name(self):
        mapping = Mapping('name', 'first_name')
        bound_mapping = BoundMapping.bind_mapping(mapping, Person)

        self.assertEqual(bound_mapping.model, Person)
        self.assertEqual(bound_mapping.column_name, 'name')
        self.assertEqual(bound_mapping.field_name, 'first_name')
        self.assertEqual(bound_mapping.readonly, False)
        self.assertEqual(bound_mapping.model_init, True)

    def test_readonly(self):
        mapping = Mapping('first_name', readonly=True)
        bound_mapping = BoundMapping.bind_mapping(mapping, Person)

        self.assertEqual(bound_mapping.model, Person)
        self.assertEqual(bound_mapping.column_name, 'first_name')
        self.assertEqual(bound_mapping.field_name, 'first_name')
        self.assertEqual(bound_mapping.readonly, True)
        self.assertEqual(bound_mapping.model_init, False)

    def test_property(self):
        mapping = Mapping('name')
        bound_mapping = BoundMapping.bind_mapping(mapping, Person)

        self.assertEqual(bound_mapping.model, Person)
        self.assertEqual(bound_mapping.column_name, 'name')
        self.assertEqual(bound_mapping.field_name, 'name')
        self.assertEqual(bound_mapping.readonly, True)
        self.assertEqual(bound_mapping.model_init, False)

    def test_foreign_key(self):
        mapping = Mapping('partner')
        bound_mapping = BoundMapping.bind_mapping(mapping, Person)

        self.assertEqual(bound_mapping.model, Person)
        self.assertEqual(bound_mapping.column_name, 'partner')
        self.assertEqual(bound_mapping.field_name, 'partner')
        self.assertEqual(bound_mapping.readonly, False)
        self.assertEqual(bound_mapping.model_init, True)
        self.assertEqual(bound_mapping.is_relationship, True)
        self.assertEqual(bound_mapping.is_foreign_key, True)

    def test_many_to_many(self):
        mapping = Mapping('children')
        bound_mapping = BoundMapping.bind_mapping(mapping, Person)

        self.assertEqual(bound_mapping.model, Person)
        self.assertEqual(bound_mapping.column_name, 'children')
        self.assertEqual(bound_mapping.field_name, 'children')
        self.assertEqual(bound_mapping.readonly, False)
        self.assertEqual(bound_mapping.model_init, False)
        self.assertEqual(bound_mapping.is_relationship, True)
        self.assertEqual(bound_mapping.is_one_to_many, True)
<commit_msg>Added max_length attribute to test model fields<commit_after>from django.db import models
from django.test import TestCase

from multi_import.mappings import Mapping, BoundMapping


class Person(models.Model):
    first_name = models.CharField(max_length=100)
    last_name = models.CharField(max_length=100)
    partner = models.ForeignKey('Person', related_name='person_partner')
    children = models.ManyToManyField('Person', related_name='person_children')

    @property
    def name(self):
        return self.first_name + ' ' + self.last_name


class MappingTests(TestCase):

    def test_simple_field(self):
        mapping = Mapping('first_name')
        bound_mapping = BoundMapping.bind_mapping(mapping, Person)

        self.assertEqual(bound_mapping.model, Person)
        self.assertEqual(bound_mapping.column_name, 'first_name')
        self.assertEqual(bound_mapping.field_name, 'first_name')
        self.assertEqual(bound_mapping.readonly, False)
        self.assertEqual(bound_mapping.model_init, True)

    def test_custom_column_name(self):
        mapping = Mapping('name', 'first_name')
        bound_mapping = BoundMapping.bind_mapping(mapping, Person)

        self.assertEqual(bound_mapping.model, Person)
        self.assertEqual(bound_mapping.column_name, 'name')
        self.assertEqual(bound_mapping.field_name, 'first_name')
        self.assertEqual(bound_mapping.readonly, False)
        self.assertEqual(bound_mapping.model_init, True)

    def test_readonly(self):
        mapping = Mapping('first_name', readonly=True)
        bound_mapping = BoundMapping.bind_mapping(mapping, Person)

        self.assertEqual(bound_mapping.model, Person)
        self.assertEqual(bound_mapping.column_name, 'first_name')
        self.assertEqual(bound_mapping.field_name, 'first_name')
        self.assertEqual(bound_mapping.readonly, True)
        self.assertEqual(bound_mapping.model_init, False)

    def test_property(self):
        mapping = Mapping('name')
        bound_mapping = BoundMapping.bind_mapping(mapping, Person)

        self.assertEqual(bound_mapping.model, Person)
        self.assertEqual(bound_mapping.column_name, 'name')
        self.assertEqual(bound_mapping.field_name, 'name')
        self.assertEqual(bound_mapping.readonly, True)
        self.assertEqual(bound_mapping.model_init, False)

    def test_foreign_key(self):
        mapping = Mapping('partner')
        bound_mapping = BoundMapping.bind_mapping(mapping, Person)

        self.assertEqual(bound_mapping.model, Person)
        self.assertEqual(bound_mapping.column_name, 'partner')
        self.assertEqual(bound_mapping.field_name, 'partner')
        self.assertEqual(bound_mapping.readonly, False)
        self.assertEqual(bound_mapping.model_init, True)
        self.assertEqual(bound_mapping.is_relationship, True)
        self.assertEqual(bound_mapping.is_foreign_key, True)

    def test_many_to_many(self):
        mapping = Mapping('children')
        bound_mapping = BoundMapping.bind_mapping(mapping, Person)

        self.assertEqual(bound_mapping.model, Person)
        self.assertEqual(bound_mapping.column_name, 'children')
        self.assertEqual(bound_mapping.field_name, 'children')
        self.assertEqual(bound_mapping.readonly, False)
        self.assertEqual(bound_mapping.model_init, False)
        self.assertEqual(bound_mapping.is_relationship, True)
        self.assertEqual(bound_mapping.is_one_to_many, True)

{'fraction_non_alphanumeric': 0.09649122807017543, 'fraction_numerical': 0.0008771929824561404, 'mean_word_length': 3.925125989920806, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3896764', 'n_tokens_mistral': 1957, 'n_tokens_neox': 1888, 'n_words': 296}