<commit_before># coding: utf-8

from django.core.urlresolvers import reverse

from django_webtest import WebTest

from message.models import Message
from message.factories import MessageFactory
from test.factories import UserFactory


class TestSendRequestMessage(WebTest):
    """ Functional test for request creation. """

    def setUp(self):
        self.user = UserFactory()
        self.page = self.app.get(
            reverse('create-request'),
            user=self.user.username)
        self.data = MessageFactory.attributes(create=False)

    def tearDown(self):
        Message.objects.all().delete()

    def test_get_form(self):
        form = self.page.forms['mainForm']
        self.assertIsNotNone(form)

    def test_message_saved(self):
        before = Message.objects.count()
        form = self.page.forms['mainForm']
        form['title'] = self.data['title']
        form['message'] = self.data['message']
        form['is_anonymous'] = self.data['is_anonymous']
        form['allow_feedback'] = self.data['allow_feedback']
        form.submit()
        self.assertEquals(before + 1, Message.objects.count())


class TestRequestMessageParameters(WebTest):
    """ Test for new request parameters """
    def setUp(self):
        self.user = UserFactory()
        self.data = MessageFactory.attributes(create=False)
        self.form = self.app.get(
            reverse('create-request'), user=self.user.username
        ).forms['mainForm']

    def send_form(self):
        self.form['title'] = self.data['title']
        self.form['message'] = self.data['message']
        self.form['is_anonymous'] = self.data['is_anonymous']
        self.form['allow_feedback'] = self.data['allow_feedback']
        self.form.submit()

    def test_message_user(self):
        """ Test message author """
        self.send_form()
        msg = Message.objects.get()
        self.assertEquals(msg.user, self.user)

    def test_message_flags(self):
        """ Test default message flags """
        self.send_form()
        msg = Message.objects.get()
        self.assertEquals(Message.NEW, msg.status)
        self.assertFalse(msg.is_removed)
        self.assertTrue(msg.is_anonymous)
        self.assertTrue(msg.allow_feedback)
        self.assertFalse(msg.is_virtual)
        self.assertFalse(msg.is_important)
        self.assertFalse(msg.is_active)<commit_msg>Tests for custom form flags<commit_after># coding: utf-8

from django.core.urlresolvers import reverse

from django_webtest import WebTest

from message.models import Message
from message.factories import MessageFactory
from test.factories import UserFactory


class TestSendRequestMessage(WebTest):
    """ Functional test for request creation. """

    def setUp(self):
        self.user = UserFactory()
        self.page = self.app.get(
            reverse('create-request'),
            user=self.user.username)
        self.data = MessageFactory.attributes(create=False)

    def tearDown(self):
        Message.objects.all().delete()

    def test_get_form(self):
        form = self.page.forms['mainForm']
        self.assertIsNotNone(form)

    def test_message_saved(self):
        before = Message.objects.count()
        form = self.page.forms['mainForm']
        form['title'] = self.data['title']
        form['message'] = self.data['message']
        form['is_anonymous'] = self.data['is_anonymous']
        form['allow_feedback'] = self.data['allow_feedback']
        form.submit()
        self.assertEquals(before + 1, Message.objects.count())


class TestRequestMessageParameters(WebTest):
    """ Test for new request parameters """
    def setUp(self):
        self.user = UserFactory()
        self.data = MessageFactory.attributes(create=False)
        self.form = self.app.get(
            reverse('create-request'), user=self.user.username
        ).forms['mainForm']

    def send_form(self):
        self.form['title'] = self.data['title']
        self.form['message'] = self.data['message']
        self.form['is_anonymous'] = self.data['is_anonymous']
        self.form['allow_feedback'] = self.data['allow_feedback']
        self.form.submit()

    def test_message_user(self):
        """ Test message author """
        self.send_form()
        msg = Message.objects.get()
        self.assertEquals(msg.user, self.user)

    def test_message_flags(self):
        """ Test default message flags """
        self.send_form()
        msg = Message.objects.get()
        self.assertEquals(Message.NEW, msg.status)
        self.assertFalse(msg.is_removed)
        self.assertTrue(msg.is_anonymous)
        self.assertTrue(msg.allow_feedback)
        self.assertFalse(msg.is_virtual)
        self.assertFalse(msg.is_important)
        self.assertFalse(msg.is_active)

    def test_nonanonymous_message(self):
        """ Send non-anonymous message """
        self.data['is_anonymous'] = False
        self.send_form()
        msg = Message.objects.get()
        self.assertFalse(msg.is_anonymous)

    def test_no_feedback(self):
        """ Send message and do not want feedback """
        self.data['allow_feedback'] = False
        self.send_form()
        msg = Message.objects.get()
        self.assertFalse(msg.allow_feedback)
{'fraction_non_alphanumeric': 0.12590752770347727, 'fraction_numerical': 0.0007642338555598013, 'mean_word_length': 2.8267543859649122, 'pattern_counts': {'":': 0, '<': 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': '6951276', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1480, 'n_words': 273}