<commit_before>from django.conf import settings
from django.template import engines as template_engines
from django.template.loader import render_to_string
from django.test.client import RequestFactory
from django.utils import translation

import mock
from nose.tools import eq_
from pyquery import PyQuery as pq

from kitsune.sumo.tests import LocalizingClient, TestCase
from kitsune.sumo.urlresolvers import reverse


def test_breadcrumb():
    """Make sure breadcrumb links start with /."""
    c = LocalizingClient()
    response = c.get(reverse('search'))

    doc = pq(response.content)
    href = doc('.breadcrumbs a')[0]
    eq_('/', href.attrib['href'][0])


class MockRequestTests(TestCase):
    """Base class for tests that need a mock request"""

    def setUp(self):
        super(MockRequestTests, self).setUp()
        request = RequestFactory()
        request.GET = {}
        request.LANGUAGE_CODE = 'en-US'
        self.request = request


class BaseTemplateTests(MockRequestTests):
    """Tests for base.html"""

    def setUp(self):
        super(BaseTemplateTests, self).setUp()
        self.template = 'base.html'

    def test_dir_ltr(self):
        """Make sure dir attr is set to 'ltr' for LTR language."""
        html = render_to_string(self.template, request=self.request)
        eq_('ltr', pq(html)('html').attr['dir'])

    def test_dir_rtl(self):
        """Make sure dir attr is set to 'rtl' for RTL language."""
        translation.activate('he')
        self.request.LANGUAGE_CODE = 'he'
        html = render_to_string(self.template, request=self.request)
        eq_('rtl', pq(html)('html').attr['dir'])
        translation.deactivate()<commit_msg>Add csrf_token to the request for mocked request tests<commit_after>from django.conf import settings
from django.template import engines as template_engines
from django.template.loader import render_to_string
from django.test.client import RequestFactory
from django.utils import translation

import mock
from nose.tools import eq_
from pyquery import PyQuery as pq

from kitsune.sumo.tests import LocalizingClient, TestCase
from kitsune.sumo.urlresolvers import reverse


def test_breadcrumb():
    """Make sure breadcrumb links start with /."""
    c = LocalizingClient()
    response = c.get(reverse('search'))

    doc = pq(response.content)
    href = doc('.breadcrumbs a')[0]
    eq_('/', href.attrib['href'][0])


class MockRequestTests(TestCase):
    """Base class for tests that need a mock request"""

    def setUp(self):
        super(MockRequestTests, self).setUp()
        request = RequestFactory()
        request.GET = {}
        request.LANGUAGE_CODE = 'en-US'
        request.META = {'csrf_token': '<PASSWORD>'}
        self.request = request


class BaseTemplateTests(MockRequestTests):
    """Tests for base.html"""

    def setUp(self):
        super(BaseTemplateTests, self).setUp()
        self.template = 'base.html'

    def test_dir_ltr(self):
        """Make sure dir attr is set to 'ltr' for LTR language."""
        html = render_to_string(self.template, request=self.request)
        eq_('ltr', pq(html)('html').attr['dir'])

    def test_dir_rtl(self):
        """Make sure dir attr is set to 'rtl' for RTL language."""
        translation.activate('he')
        self.request.LANGUAGE_CODE = 'he'
        html = render_to_string(self.template, request=self.request)
        eq_('rtl', pq(html)('html').attr['dir'])
        translation.deactivate()
{'fraction_non_alphanumeric': 0.11976911976911978, 'fraction_numerical': 0.0011544011544011544, 'mean_word_length': 3.466494845360825, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '4211414', 'n_tokens_mistral': 1039, 'n_tokens_neox': 1017, 'n_words': 280}