<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.test import TestCase
from django.test import Client as HttpClient
from django.contrib.auth.models import User, Permission
from django.core.management import call_command
from django.apps import apps

from faker import Factory


fake = Factory.create()


class AppTestCase(TestCase):
    def setUp(self):
        pass

    def test_api_config(self):
        self.assertEqual(apps.get_app_config('api').name, 'api')


class BrowseableApiTestCase(TestCase):
    def setUp(self):
        call_command('fake', verbosity=0, iterations=1)

        self.c = HttpClient()

        fake_user = fake.simple_profile()
        fake_password = <PASSWORD>()
        User.objects.create_user(fake_user['username'],
                                 fake_user['mail'],
                                 fake_password)

        self.user = User.objects.get(username=fake_user['username'])
        self.c.login(username=fake_user['username'],
                     password=<PASSWORD>)

    def test_users_get(self):
        page = self.c.get('/api/users/')
        self.assertEqual(page.status_code, 200)

    def test_permission_get(self):
        page = self.c.get('/api/permissions/')
        self.assertEqual(page.status_code, 200)

    def test_clients_get(self):
        page = self.c.get('/api/clients/')
        self.assertEqual(page.status_code, 403)

        self.user.user_permissions.add(
            Permission.objects.get(codename='view_client'))<commit_msg>Add SitePermission to API tests user.<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.test import TestCase
from django.test import Client as HttpClient
from django.contrib.auth.models import User, Permission
from django.core.management import call_command
from django.apps import apps

from faker import Factory

from conf.models import Site, SitePermission


fake = Factory.create()


class AppTestCase(TestCase):
    def setUp(self):
        pass

    def test_api_config(self):
        self.assertEqual(apps.get_app_config('api').name, 'api')


class BrowseableApiTestCase(TestCase):
    def setUp(self):
        call_command('fake', verbosity=0, iterations=1)

        self.c = HttpClient()

        fake_user = fake.simple_profile()
        fake_password = <PASSWORD>()
        user = User.objects.create_user(fake_user['username'],
                                        fake_user['mail'],
                                        fake_password)
        site_permission = SitePermission.objects.create(user=user)
        site_permission.sites = Site.objects.filter(id=1)
        site_permission.save()

        self.user = User.objects.get(username=fake_user['username'])
        self.c.login(username=fake_user['username'],
                     password=<PASSWORD>)

    def test_users_get(self):
        page = self.c.get('/api/users/')
        self.assertEqual(page.status_code, 200)

    def test_permission_get(self):
        page = self.c.get('/api/permissions/')
        self.assertEqual(page.status_code, 200)

    def test_clients_get(self):
        page = self.c.get('/api/clients/')
        self.assertEqual(page.status_code, 403)

        self.user.user_permissions.add(
            Permission.objects.get(codename='view_client'))
{'fraction_non_alphanumeric': 0.11221122112211221, 'fraction_numerical': 0.007500750075007501, 'mean_word_length': 2.7334826427771555, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6905229', 'n_tokens_mistral': 982, 'n_tokens_neox': 930, 'n_words': 185}