<commit_before>from __future__ import unicode_literals

import json
import tempfile

from django.utils import six
from django.test import TestCase
from django.urls import reverse

from froide.foirequest.tests import factories
from froide.helper.csv_utils import export_csv_bytes

from .models import PublicBody, FoiLaw, Jurisdiction
from .csv_import import CSVImporter


class PublicBodyTest(TestCase):
    def setUp(self):
        self.site = factories.make_world()

    def test_web_page(self):
        response = self.client.get(reverse('publicbody-list'))
        self.assertEqual(response.status_code, 200)
        pb = PublicBody.objects.all()[0]
        tag = pb.tags.all()[0]
        response = self.client.get(reverse('publicbody-list', kwargs={
            'topic': tag.slug
        }))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, pb.name)
        response = self.client.get(reverse('publicbody-list', kwargs={
            'jurisdiction': pb.jurisdiction.slug
        }))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, pb.name)
        response = self.client.get(reverse('publicbody-list', kwargs={
            'jurisdiction': pb.jurisdiction.slug,
            'topic': tag.slug
        }))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, pb.name)
        response = self.client.get(reverse('publicbody-show',
                kwargs={"slug": pb.slug}))
        self.assertEqual(response.status_code, 200)

    def test_csv(self):
        csv = export_csv_bytes(PublicBody.export_csv(PublicBody.objects.all()))
        self.assertEqual(PublicBody.objects.all().count() + 1,
            len(csv.splitlines()))
<commit_msg>Add tag explicitly on public body in test<commit_after>from __future__ import unicode_literals

import json
import tempfile

from django.utils import six
from django.test import TestCase
from django.urls import reverse

from froide.foirequest.tests import factories
from froide.helper.csv_utils import export_csv_bytes

from .models import PublicBody, FoiLaw, Jurisdiction
from .csv_import import CSVImporter


class PublicBodyTest(TestCase):
    def setUp(self):
        self.site = factories.make_world()

    def test_web_page(self):
        response = self.client.get(reverse('publicbody-list'))
        self.assertEqual(response.status_code, 200)
        pb = PublicBody.objects.all()[0]
        tag = factories.PublicBodyTagFactory.create(is_topic=True)
        pb.tags.add(tag)
        response = self.client.get(reverse('publicbody-list', kwargs={
            'topic': tag.slug
        }))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, pb.name)
        response = self.client.get(reverse('publicbody-list', kwargs={
            'jurisdiction': pb.jurisdiction.slug
        }))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, pb.name)
        response = self.client.get(reverse('publicbody-list', kwargs={
            'jurisdiction': pb.jurisdiction.slug,
            'topic': tag.slug
        }))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, pb.name)
        response = self.client.get(reverse('publicbody-show',
                kwargs={"slug": pb.slug}))
        self.assertEqual(response.status_code, 200)

    def test_csv(self):
        csv = export_csv_bytes(PublicBody.export_csv(PublicBody.objects.all()))
        self.assertEqual(PublicBody.objects.all().count() + 1,
            len(csv.splitlines()))

{'fraction_non_alphanumeric': 0.11215729714760454, 'fraction_numerical': 0.009692605926336195, 'mean_word_length': 3.072153325817362, 'pattern_counts': {'":': 2, '<': 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': '1973852', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1035, 'n_words': 200}