<commit_before>from datetime import datetime
import time

from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group, Permission
from django.utils.text import slugify

from html5lib.filters._base import Filter as html5lib_Filter
from nose.tools import nottest
from waffle.models import Flag

from kuma.core.tests import get_user, KumaTestCase
from kuma.wiki.models import Document, Revision
import kuma.wiki.content


class WikiTestCase(KumaTestCase):
    """Base TestCase for the wiki app test cases."""

    def setUp(self):
        super(WikiTestCase, self).setUp()
        self.kumaediting_flag, created = Flag.objects.get_or_create(
            name='kumaediting', everyone=True)


# Model makers. These make it clearer and more concise to create objects in
# test cases. They allow the significant attribute values to stand out rather
# than being hidden amongst the values needed merely to get the model to
# validate.

def document(save=False, **kwargs):
    """Return an empty document with enough stuff filled out that it can be
    saved."""
    defaults = {'category': Document.CATEGORIES[0][0],
                'title': str(datetime.now()),
                'is_redirect': 0}
    defaults.update(kwargs)
    if 'slug' not in kwargs:
        defaults['slug'] = slugify(defaults['title'])
    d = Document(**defaults)
    if save:
        d.save()
    return d


def revision(save=False, **kwargs):
    """Return an empty revision with enough stuff filled out that it can be
    saved.

    Revision's is_approved=False unless you specify otherwise.

    Requires a users fixture if no creator is provided.

    """
    d = None
    if 'document' not in kwargs:
        d = document()
        d.save()
    else:
        d = kwargs['document']

    defaults = {'summary': 'Some summary', 'content': 'Some content',
                'comment': 'Some comment',
                'creator': kwargs.get('creator', get_user()), 'document': d,<commit_msg>Bug 1116335 - Fixed encoding error when slugifying the title later.<commit_after>from datetime import datetime
import time

from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group, Permission
from django.utils.text import slugify

from html5lib.filters._base import Filter as html5lib_Filter
from nose.tools import nottest
from waffle.models import Flag

from kuma.core.tests import get_user, KumaTestCase
from kuma.wiki.models import Document, Revision
import kuma.wiki.content


class WikiTestCase(KumaTestCase):
    """Base TestCase for the wiki app test cases."""

    def setUp(self):
        super(WikiTestCase, self).setUp()
        self.kumaediting_flag, created = Flag.objects.get_or_create(
            name='kumaediting', everyone=True)


# Model makers. These make it clearer and more concise to create objects in
# test cases. They allow the significant attribute values to stand out rather
# than being hidden amongst the values needed merely to get the model to
# validate.

def document(save=False, **kwargs):
    """Return an empty document with enough stuff filled out that it can be
    saved."""
    defaults = {'category': Document.CATEGORIES[0][0],
                'title': unicode(datetime.now()),
                'is_redirect': 0}
    defaults.update(kwargs)
    if 'slug' not in kwargs:
        defaults['slug'] = slugify(defaults['title'])
    d = Document(**defaults)
    if save:
        d.save()
    return d


def revision(save=False, **kwargs):
    """Return an empty revision with enough stuff filled out that it can be
    saved.

    Revision's is_approved=False unless you specify otherwise.

    Requires a users fixture if no creator is provided.

    """
    d = None
    if 'document' not in kwargs:
        d = document()
        d.save()
    else:
        d = kwargs['document']

    defaults = {'summary': 'Some summary', 'content': 'Some content',
                'comment': 'Some comment',
                'creator': kwargs.get('creator', get_user()), 'document': d,
{'fraction_non_alphanumeric': 0.09717402082300446, 'fraction_numerical': 0.00421417947446703, 'mean_word_length': 3.2163009404388716, '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': '5972994', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1089, 'n_words': 412}