<commit_before>import pytest
from mc2.controllers.base.tests.base import ControllerBaseTestCase
from django.contrib.auth.models import User
from django.test import TestCase
from django.test.client import Client
from django.core.urlresolvers import reverse

from freebasics.models import FreeBasicsTemplateData, FreeBasicsController
from urllib import urlencode


@pytest.mark.django_db
class FreeBasicsControllerFormTestCase(TestCase, ControllerBaseTestCase):
    fixtures = ['test_users.json', 'test_social_auth.json']

    def setUp(self):
        self.user = User.objects.get(username='testuser')
        self.maxDiff = None
        self.client = Client()

    def test_template_create_and_delete_view(self):
        self.client.login(username='testuser', password='<PASSWORD>')
        post_data = {
            'site_name': 'example', 'site_name_url': 'https://example.com',
            'body_background_color': 'purple', 'body_color': 'purple',
            'body_font_family': 'helvetica', 'accent1': '', 'accent2': ''}
        response = self.client.post(reverse('template_list'), post_data)
        self.assertEqual(response.status_code, 201)
        self.assertEqual(FreeBasicsTemplateData.objects.all().count(), 1)
        self.assertEqual(FreeBasicsController.objects.all().count(), 1)
        pk = FreeBasicsTemplateData.objects.get(site_name='example').pk
        response = self.client.get(reverse(
            'template_detail', kwargs={'pk': pk}))
        self.assertEquals(response.data['site_name'], 'example')
        post_data = {
            'site_name': 'example2', 'site_name_url': 'https://example2.com',
            'body_background_color': 'purple', 'body_color': 'purple',
            'body_font_family': 'helvetica', 'accent1': '', 'accent2': ''}
        response = self.client.put(reverse(
            'template_detail', kwargs={'pk': pk}), data=urlencode(post_data),
            content_type='application/x-www-form-urlencoded')
        self.assertEquals(
            FreeBasicsTemplateData.objects.get(pk=pk).site_name, 'example2')
        response = self.client.delete(reverse(
            'template_detail', kwargs={'pk': pk}))
        self.assertEqual(response.status_code, 204)
        self.assertEqual(FreeBasicsTemplateData.objects.all().count(), 0)<commit_msg>using json string<commit_after>import json
import pytest
from mc2.controllers.base.tests.base import ControllerBaseTestCase
from django.contrib.auth.models import User
from django.test import TestCase
from django.test.client import Client
from django.core.urlresolvers import reverse

from freebasics.models import FreeBasicsTemplateData, FreeBasicsController


@pytest.mark.django_db
class FreeBasicsControllerFormTestCase(TestCase, ControllerBaseTestCase):
    fixtures = ['test_users.json', 'test_social_auth.json']

    def setUp(self):
        self.user = User.objects.get(username='testuser')
        self.maxDiff = None
        self.client = Client()

    def test_template_create_and_delete_view(self):
        self.client.login(username='testuser', password='<PASSWORD>')
        post_data = {
            'site_name': 'example', 'site_name_url': 'https://example.com',
            'body_background_color': 'purple', 'body_color': 'purple',
            'body_font_family': 'helvetica', 'accent1': '', 'accent2': ''}
        response = self.client.post(reverse('template_list'), post_data)
        self.assertEqual(response.status_code, 201)
        self.assertEqual(FreeBasicsTemplateData.objects.all().count(), 1)
        self.assertEqual(FreeBasicsController.objects.all().count(), 1)
        pk = FreeBasicsTemplateData.objects.get(site_name='example').pk
        response = self.client.get(reverse(
            'template_detail', kwargs={'pk': pk}))
        self.assertEquals(response.data['site_name'], 'example')
        post_data = {
            'site_name': 'example2', 'site_name_url': 'https://example2.com',
            'body_background_color': 'purple', 'body_color': 'purple',
            'body_font_family': 'helvetica', 'accent1': '', 'accent2': ''}
        response = self.client.put(reverse(
            'template_detail', kwargs={'pk': pk}), data=json.dumps(post_data),
            content_type='application/json')
        self.assertEquals(
            FreeBasicsTemplateData.objects.get(pk=pk).site_name, 'example2')
        response = self.client.delete(reverse(
            'template_detail', kwargs={'pk': pk}))
        self.assertEqual(response.status_code, 204)
        self.assertEqual(FreeBasicsTemplateData.objects.all().count(), 0)
{'fraction_non_alphanumeric': 0.13488066564484344, 'fraction_numerical': 0.007444712064812787, 'mean_word_length': 3.6755373592630503, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 1, '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': '2205204', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1337, 'n_words': 225}