<commit_before>##
#    Copyright (C) 2014 <NAME> & <NAME>
#   
#    This file is part of Inboxen.
#
#    Inboxen is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Inboxen is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with Inboxen.  If not, see <http://www.gnu.org/licenses/>.
##
from django import test
from django.conf import settings as dj_settings
from django.contrib.auth import get_user_model
from django.core import urlresolvers

from inboxen import models
from website import forms
from website.tests import utils

class SettingsTestCase(test.TestCase):
    fixtures = ['inboxen_testdata.json']
    form = None

    def setUp(self):
        super(SettingsTestCase, self).setUp()
        self.user = get_user_model().objects.get(id=1)

        login = self.client.login(username=self.user.username, password="<PASSWORD>")

        if not login:
            raise Exception("Could not log in")

    def get_url(self):
        return urlresolvers.reverse("user-settings")

    def test_get(self):
        response = self.client.get(self.get_url())
        self.assertEqual(response.status_code, 200)
        if self.form is not None:
            form = response.context["form"]
            self.assertIsInstance(form, self.form)

class LiberateTestCase(SettingsTestCase):
    form = forms.LiberationForm

    def get_url(self):
        return urlresolvers.reverse("user-liberate")

    def test_form_bad_data(self):
        params = {"storage_type": 180, "compression_type": 180}
        form = self.form(user=self.user, data=params)

        self.assertFalse(form.is_valid())

    def test_form_good_data(self):
        params = {"storage_type": 1, "compression_type": 1}
        form = self.form(user=self.user, data=params)

        self.assertTrue(form.is_valid())

class DeleteTestCase(SettingsTestCase):
    form = forms.DeleteAccountForm<commit_msg>Test new views<commit_after>##
#    Copyright (C) 2014 <NAME> & <NAME>
#   
#    This file is part of Inboxen.
#
#    Inboxen is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Inboxen is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with Inboxen.  If not, see <http://www.gnu.org/licenses/>.
##
from django import test
from django.conf import settings as dj_settings
from django.contrib.auth import get_user_model
from django.core import urlresolvers

from inboxen import models
from website import forms
from website.tests import utils

class SettingsTestCase(test.TestCase):
    fixtures = ['inboxen_testdata.json']
    form = forms.SettingsForm

    def setUp(self):
        super(SettingsTestCase, self).setUp()
        self.user = get_user_model().objects.get(id=1)

        login = self.client.login(username=self.user.username, password="<PASSWORD>")

        if not login:
            raise Exception("Could not log in")

    def get_url(self):
        return urlresolvers.reverse("user-settings")

    def test_get(self):
        response = self.client.get(self.get_url())
        self.assertEqual(response.status_code, 200)
        form = response.context["form"]
        self.assertIsInstance(form, self.form)

    def test_form_bad_data(self):
        params = {"images": "12213"}
        request = utils.MockRequest(self.user)
        form = self.form(request, data=params)

        self.assertFalse(form.is_valid())

    def test_form_good_data(self):
        params = {"images": "1"}
        request = utils.MockRequest(self.user)
        form = self.form(request, data=params)

        self.assertTrue(form.is_valid())

class UsernameChangeTestCase(SettingsTestCase):
    form = forms.UsernameChangeForm

    def get_url(self):
        return urlresolvers.reverse("user-username")

    def test_form_bad_data(self):
        params = {"new_username1": self.user.username, "new_username2": self.user.username}
        request = utils.MockRequest(self.user)
        form = self.form(request, data=params)

        self.assertFalse(form.is_valid())

    def test_form_good_data(self):
        params = {"new_username1": self.user.username + "1", "new_username2": self.user.username + "1"}
        request = utils.MockRequest(self.user)
        form = self.form(request, data=params)

        self.assertTrue(form.is_valid())

class LiberateTestCase(SettingsTestCase):
    form = forms.LiberationForm

    def get_url(self):
        return urlresolvers.reverse("user-liberate")

    def test_form_bad_data(self):
        params = {"storage_type": 180, "compression_type": 180}
        form = self.form(user=self.user, data=params)

        self.assertFalse(form.is_valid())

    def test_form_good_data(self):
        params = {"storage_type": 1, "compression_type": 1}
        form = self.form(user=self.user, data=params)

        self.assertTrue(form.is_valid())

class DeleteTestCase(SettingsTestCase):
    form = forms.DeleteAccountForm
{'fraction_non_alphanumeric': 0.09987924788683802, 'fraction_numerical': 0.007935138864930136, 'mean_word_length': 3.2884615384615383, 'pattern_counts': {'":': 14, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6054528', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1671, 'n_words': 488}