<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.test import TestCase
from django.db import models
from django.contrib.auth import get_user_model
from django.contrib.sites.models import Site

from ..models import Container, ContainerSource, ContainerImage, ContainerBox
from opps.channels.models import Channel


class ContainerFields(TestCase):

    def test_title(self):
        field = Container._meta.get_field_by_name('title')[0]
        self.assertEqual(field.__class__, models.CharField)
        self.assertEqual(field.max_length, 140)
        self.assertTrue(field.db_index)

    def test_hat(self):
        field = Container._meta.get_field_by_name('hat')[0]
        self.assertEqual(field.__class__, models.CharField)
        self.assertEqual(field.max_length, 140)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)

    def test_short_url(self):
        field = Container._meta.get_field_by_name('short_url')[0]
        self.assertEqual(field.__class__, models.URLField)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)

    def test_child_class(self):
        field = Container._meta.get_field_by_name('child_class')[0]
        self.assertEqual(field.__class__, models.CharField)
        self.assertEqual(field.max_length, 30)
        self.assertTrue(field.db_index)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)

    def test_child_module(self):
        field = Container._meta.get_field_by_name('child_module')[0]
        self.assertEqual(field.__class__, models.CharField)
        self.assertEqual(field.max_length, 120)
        self.assertTrue(field.db_index)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)

    def test_child_app_label(self):
        field = Container._meta.get_field_by_name('child_app_label')[0]
        self.assertEqual(field.__class__, models.CharField)
        self.assertEqual(field.max_length, 30)
        self.assertTrue(field.db_index)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)

    def test_show_on_root_channel(self):
        field = Container._meta.get_field_by_name('show_on_root_channel')[0]
        self.assertEqual(field.__class__, models.BooleanField)
        self.assertTrue(field.default)

    def test_sourcesl(self):
        field = Container._meta.get_field_by_name('sources')[0]
        self.assertEqual(field.__class__, models.ManyToManyField)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)
        self.assertFalse(field.unique)
        self.assertFalse(field.primary_key)


class ContainerModelTest(TestCase):

    def setUp(self):
        User = get_user_model()
        self.user = User.objects.create(username=u'test', password='<PASSWORD>')
        self.site = Site.objects.filter(name=u'example.com').get()
        self.channel = Channel.objects.create(name=u'Home', slug=u'home',
                                              description=u'home page',
                                              site=self.site, user=self.user)

        self.container = Container.objects.create(title=u'test',
                                                  user=self.user,
                                                  published=True,
                                                  site=self.site,
                                                  channel=self.channel)

    def test_with_containers_exists(self):
        self.assertTrue(self.container)
        self.assertEqual(self.container.title, u'test')
        container = Container.objects.get(title=u'test')
        self.assertEqual(container, self.container)

    def test_save_with_test_desnomalization(self):
        self.assertEqual(self.container.channel_name, self.channel.name)
        self.assertEqual(self.container.channel_long_slug,
                         self.channel.long_slug)
        self.assertEqual(self.container.child_class, u"Container")
        self.assertEqual(self.container.child_module,
                         u"opps.containers.models")
        self.assertEqual(self.container.child_app_label, u"containers")

    def test_absolute_url(self):
        self.assertEqual(self.container.get_absolute_url(),
                         u"/home/test")

    def test_get_thumb(self):
        self.assertFalse(self.container.get_thumb())

    def test_search_category(self):
        self.assertEqual(self.container.search_category, u"Container")

    def test_get_http_absolute_url(self):
        self.assertEqual(self.container.get_http_absolute_url(),
                         u'http://example.com/home/test')


class ContainerSourceFields(TestCase):

    def test_container(self):
        field = ContainerSource._meta.get_field_by_name(u"container")[0]
        self.assertEqual(field.__class__, models.ForeignKey)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)
        self.assertEqual(field.verbose_name, u"Container")

    def test_order(self):
        field = ContainerSource._meta.get_field_by_name(u"order")[0]
        self.assertEqual(field.__class__, models.PositiveIntegerField)
        self.assertEqual(field.default, 0)

    def test_source(self):
        field = ContainerSource._meta.get_field_by_name(u"source")[0]
        self.assertEqual(field.__class__, models.ForeignKey)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)


class ContainerImageFields(TestCase):

    def test_container(self):
        field = ContainerImage._meta.get_field_by_name(u"container")[0]
        self.assertEqual(field.__class__, models.ForeignKey)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)
        self.assertEqual(field.verbose_name, u"Container")

    def test_order(self):
        field = ContainerImage._meta.get_field_by_name(u"order")[0]
        self.assertEqual(field.__class__, models.PositiveIntegerField)
        self.assertEqual(field.default, 0)

    def test_image(self):
        field = ContainerImage._meta.get_field_by_name(u"image")[0]
        self.assertEqual(field.__class__, models.ForeignKey)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)
        self.assertEqual(field.verbose_name, u"Image")

    def test_caption(self):
        field = ContainerImage._meta.get_field_by_name(u"caption")[0]
        self.assertEqual(field.__class__, models.CharField)
        self.assertEqual(field.max_length, 255)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)


class ContainerBoxFields(TestCase):

    def test_title(self):
        field = ContainerBox._meta.get_field_by_name(u"title")[0]
        self.assertEqual(field.__class__, models.CharField)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)
        self.assertEqual(field.max_length, 140)

    def test_containers(self):
        field = ContainerBox._meta.get_field_by_name(u"containers")[0]
        self.assertEqual(field.__class__, models.ManyToManyField)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)
        self.assertEqual(field.verbose_name, u"Container")

    def test_queryset(self):
        field = ContainerBox._meta.get_field_by_name(u"queryset")[0]
        self.assertEqual(field.__class__, models.ForeignKey)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)
        self.assertEqual(field.verbose_name, u"Query Set")<commit_msg>test for container box containers fields<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.test import TestCase
from django.db import models
from django.contrib.auth import get_user_model
from django.contrib.sites.models import Site

from ..models import Container, ContainerSource
from ..models import ContainerImage, ContainerBox, ContainerBoxContainers
from opps.channels.models import Channel


class ContainerFields(TestCase):

    def test_title(self):
        field = Container._meta.get_field_by_name('title')[0]
        self.assertEqual(field.__class__, models.CharField)
        self.assertEqual(field.max_length, 140)
        self.assertTrue(field.db_index)

    def test_hat(self):
        field = Container._meta.get_field_by_name('hat')[0]
        self.assertEqual(field.__class__, models.CharField)
        self.assertEqual(field.max_length, 140)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)

    def test_short_url(self):
        field = Container._meta.get_field_by_name('short_url')[0]
        self.assertEqual(field.__class__, models.URLField)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)

    def test_child_class(self):
        field = Container._meta.get_field_by_name('child_class')[0]
        self.assertEqual(field.__class__, models.CharField)
        self.assertEqual(field.max_length, 30)
        self.assertTrue(field.db_index)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)

    def test_child_module(self):
        field = Container._meta.get_field_by_name('child_module')[0]
        self.assertEqual(field.__class__, models.CharField)
        self.assertEqual(field.max_length, 120)
        self.assertTrue(field.db_index)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)

    def test_child_app_label(self):
        field = Container._meta.get_field_by_name('child_app_label')[0]
        self.assertEqual(field.__class__, models.CharField)
        self.assertEqual(field.max_length, 30)
        self.assertTrue(field.db_index)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)

    def test_show_on_root_channel(self):
        field = Container._meta.get_field_by_name('show_on_root_channel')[0]
        self.assertEqual(field.__class__, models.BooleanField)
        self.assertTrue(field.default)

    def test_sourcesl(self):
        field = Container._meta.get_field_by_name('sources')[0]
        self.assertEqual(field.__class__, models.ManyToManyField)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)
        self.assertFalse(field.unique)
        self.assertFalse(field.primary_key)


class ContainerModelTest(TestCase):

    def setUp(self):
        User = get_user_model()
        self.user = User.objects.create(username=u'test', password='<PASSWORD>')
        self.site = Site.objects.filter(name=u'example.com').get()
        self.channel = Channel.objects.create(name=u'Home', slug=u'home',
                                              description=u'home page',
                                              site=self.site, user=self.user)

        self.container = Container.objects.create(title=u'test',
                                                  user=self.user,
                                                  published=True,
                                                  site=self.site,
                                                  channel=self.channel)

    def test_with_containers_exists(self):
        self.assertTrue(self.container)
        self.assertEqual(self.container.title, u'test')
        container = Container.objects.get(title=u'test')
        self.assertEqual(container, self.container)

    def test_save_with_test_desnomalization(self):
        self.assertEqual(self.container.channel_name, self.channel.name)
        self.assertEqual(self.container.channel_long_slug,
                         self.channel.long_slug)
        self.assertEqual(self.container.child_class, u"Container")
        self.assertEqual(self.container.child_module,
                         u"opps.containers.models")
        self.assertEqual(self.container.child_app_label, u"containers")

    def test_absolute_url(self):
        self.assertEqual(self.container.get_absolute_url(),
                         u"/home/test")

    def test_get_thumb(self):
        self.assertFalse(self.container.get_thumb())

    def test_search_category(self):
        self.assertEqual(self.container.search_category, u"Container")

    def test_get_http_absolute_url(self):
        self.assertEqual(self.container.get_http_absolute_url(),
                         u'http://example.com/home/test')


class ContainerSourceFields(TestCase):

    def test_container(self):
        field = ContainerSource._meta.get_field_by_name(u"container")[0]
        self.assertEqual(field.__class__, models.ForeignKey)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)
        self.assertEqual(field.verbose_name, u"Container")

    def test_order(self):
        field = ContainerSource._meta.get_field_by_name(u"order")[0]
        self.assertEqual(field.__class__, models.PositiveIntegerField)
        self.assertEqual(field.default, 0)

    def test_source(self):
        field = ContainerSource._meta.get_field_by_name(u"source")[0]
        self.assertEqual(field.__class__, models.ForeignKey)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)


class ContainerImageFields(TestCase):

    def test_container(self):
        field = ContainerImage._meta.get_field_by_name(u"container")[0]
        self.assertEqual(field.__class__, models.ForeignKey)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)
        self.assertEqual(field.verbose_name, u"Container")

    def test_order(self):
        field = ContainerImage._meta.get_field_by_name(u"order")[0]
        self.assertEqual(field.__class__, models.PositiveIntegerField)
        self.assertEqual(field.default, 0)

    def test_image(self):
        field = ContainerImage._meta.get_field_by_name(u"image")[0]
        self.assertEqual(field.__class__, models.ForeignKey)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)
        self.assertEqual(field.verbose_name, u"Image")

    def test_caption(self):
        field = ContainerImage._meta.get_field_by_name(u"caption")[0]
        self.assertEqual(field.__class__, models.CharField)
        self.assertEqual(field.max_length, 255)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)


class ContainerBoxFields(TestCase):

    def test_title(self):
        field = ContainerBox._meta.get_field_by_name(u"title")[0]
        self.assertEqual(field.__class__, models.CharField)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)
        self.assertEqual(field.max_length, 140)

    def test_containers(self):
        field = ContainerBox._meta.get_field_by_name(u"containers")[0]
        self.assertEqual(field.__class__, models.ManyToManyField)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)
        self.assertEqual(field.verbose_name, u"Container")

    def test_queryset(self):
        field = ContainerBox._meta.get_field_by_name(u"queryset")[0]
        self.assertEqual(field.__class__, models.ForeignKey)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)
        self.assertEqual(field.verbose_name, u"Query Set")


class ContainerBoxContainersFields(TestCase):

    def test_containerbox(self):
        field = ContainerBoxContainers._meta.get_field_by_name(
            u"containerbox"
        )[0]
        self.assertEqual(field.__class__, models.ForeignKey)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)
        self.assertEqual(field.verbose_name, u"Container Box")

    def test_container(self):
        field = ContainerBoxContainers._meta.get_field_by_name(u"container")[0]
        self.assertEqual(field.__class__, models.ForeignKey)
        self.assertTrue(field.null)
        self.assertTrue(field.blank)
        self.assertEqual(field.verbose_name, u"Container")

{'fraction_non_alphanumeric': 0.10624280414481259, 'fraction_numerical': 0.005244978892158117, 'mean_word_length': 2.8854373757455267, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5919935', 'n_tokens_mistral': 4474, 'n_tokens_neox': 4421, 'n_words': 575}