<commit_before>from __future__ import unicode_literals
import json
import pickle

import django
from django import forms
from django.core import serializers
from django.core.exceptions import ValidationError
from django.core.serializers.base import DeserializationError
from django.db import models
from django.template import Template, Context
from django.test import TestCase

import any_urlfield.forms
from any_urlfield.models import AnyUrlField, AnyUrlValue
from any_urlfield.registry import UrlTypeRegistry
from any_urlfield.validators import ExtendedURLValidator

try:
    from unittest import skipIf
except ImportError:
    from django.utils.unittest import skipIf  # Python 2.6

try:
    from django.utils import six
    unicode = six.text_type
except ImportError:
    pass  # Python 2, Django 1.3

try:
    from StringIO import StringIO       # Python 2
except ImportError:
    from io import BytesIO as StringIO  # Python 3


class UrlModel(models.Model):
    """
    Example model for testing AnyUrlField
    """
    url = AnyUrlField()

    def get_absolute_url(self):
        return str(self.url)


class PageModel(models.Model):
    """
    Example model to be linking to.
    """
    slug = models.SlugField()

    def get_absolute_url(self):
        return '/{0}/'.format(self.slug)


class RegPageModel(models.Model):
    slug = models.SlugField()

    def get_absolute_url(self):
        return '/{0}/'.format(self.slug)

AnyUrlField.register_model(RegPageModel)


class AnyUrlTests(TestCase):
    maxDiff = None

    def test_registry(self):
        """
        Test the basic registry setup.
        """
        reg = UrlTypeRegistry()
        self.assertIsNotNone(reg['http'])
        self.assertIsNotNone(reg['https'])

    def test_from_model(self):
        """
        Basic test of ``from_model``.
        """
        page2 = RegPageModel.objects.create(pk=1, slug='foo2')
        v = AnyUrlValue.from_model(page2)

        self.assertEqual(v.url_type.prefix, 'any_urlfield.regpagemodel')   # app_label.modelname
        self.assertEqual(v.type_value, page2.id)
        self.assertEqual(v.to_db_value(), 'any_urlfield.regpagemodel://1')<commit_msg>Include SimpleRawIdWidget in tests<commit_after>from __future__ import unicode_literals
import json
import pickle

import django
from any_urlfield.forms import SimpleRawIdWidget
from django import forms
from django.core import serializers
from django.core.exceptions import ValidationError
from django.core.serializers.base import DeserializationError
from django.db import models
from django.template import Template, Context
from django.test import TestCase

import any_urlfield.forms
from any_urlfield.models import AnyUrlField, AnyUrlValue
from any_urlfield.registry import UrlTypeRegistry
from any_urlfield.validators import ExtendedURLValidator

try:
    from unittest import skipIf
except ImportError:
    from django.utils.unittest import skipIf  # Python 2.6

try:
    from django.utils import six
    unicode = six.text_type
except ImportError:
    pass  # Python 2, Django 1.3

try:
    from StringIO import StringIO       # Python 2
except ImportError:
    from io import BytesIO as StringIO  # Python 3


class UrlModel(models.Model):
    """
    Example model for testing AnyUrlField
    """
    url = AnyUrlField()

    def get_absolute_url(self):
        return str(self.url)


class PageModel(models.Model):
    """
    Example model to be linking to.
    """
    slug = models.SlugField()

    def get_absolute_url(self):
        return '/{0}/'.format(self.slug)


class RegPageModel(models.Model):
    slug = models.SlugField()

    def get_absolute_url(self):
        return '/{0}/'.format(self.slug)

AnyUrlField.register_model(RegPageModel, widget=SimpleRawIdWidget(RegPageModel))


class AnyUrlTests(TestCase):
    maxDiff = None

    def test_registry(self):
        """
        Test the basic registry setup.
        """
        reg = UrlTypeRegistry()
        self.assertIsNotNone(reg['http'])
        self.assertIsNotNone(reg['https'])

    def test_from_model(self):
        """
        Basic test of ``from_model``.
        """
        page2 = RegPageModel.objects.create(pk=1, slug='foo2')
        v = AnyUrlValue.from_model(page2)

        self.assertEqual(v.url_type.prefix, 'any_urlfield.regpagemodel')   # app_label.modelname
        self.assertEqual(v.type_value, page2.id)
        self.assertEqual(v.to_db_value(), 'any_urlfield.regpagemodel://1')
{'fraction_non_alphanumeric': 0.08909335727109516, 'fraction_numerical': 0.006732495511669659, 'mean_word_length': 3.439243027888446, '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': '7209048', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1318, 'n_words': 341}