<commit_before># coding: utf-8

import unittest

from core.factories import CategoryFactory

from geozones.factories import RegionFactory

from message.forms import MessageForm
from message.models import Message, Category

from test.utils import lorem_ipsum
from test.factories import UserFactory


class TestBaseMessageForm(unittest.TestCase):

    def setUp(self):
        self.user = UserFactory()
        self.region = RegionFactory()
        self.data = {
            'title': lorem_ipsum(words_count=3),
            'message': lorem_ipsum(),
            'georegion': self.region.pk,
            'messageType': Message.REQUEST,
        }

    def tearDown(self):
        self.region.delete()
        self.region = None
        self.user.delete()

#    def test_form_type(self):
#        self.assertEqual(
#            self.type_request.pk,
#            self.form.fields['messageType'].initial)

    def test_send_data(self):
        form = MessageForm(self.data)
        self.assertTrue(form.is_bound)
        self.assertTrue(form.is_valid(), form.errors)
        msg = form.save(commit=False)
        msg.user = self.user
        msg.save()
        self.assertIsNotNone(msg)
        self.assertIsNotNone(msg.pk)
        self.assertEqual(Message.NEW, msg.status)
        self.assertEqual(Message.REQUEST, msg.messageType)
        msg.delete()

    def test_lost_message(self):
        self.data["message"] = ""
        form = MessageForm(self.data)
        self.assertFalse(form.is_valid())


class TestRequestCategory(unittest.TestCase):
    def setUp(self):
        self.cats = list()
        for x in xrange(5):
            self.cats.append(CategoryFactory())
        self.user = UserFactory()
        self.region = RegionFactory()
#        self.type_request = MessageTypeFactory()
        self.data = {
            'message': lorem_ipsum(),
#            'messageType': self.type_request.pk,
            'user_id': self.user,
            'georegion': self.region.pk,
            'location_0': 25.0,
            'location_1': 50.0,
            'category': [x.pk for x in self.cats],
            'address': lorem_ipsum(words_count=4)
        }

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

#    def test_message_with_cats(self):
#        form = UserMessageForm(self.data, message_type=self.type_request.pk)
#        self.assertTrue(form.is_valid())
#        msg = form.save(commit=False)
#        msg.user = self.user
#        msg.save()
#        form.save_m2m()
#        self.assertEqual(5, msg.category.all().count())


class TestRequiredFields(unittest.TestCase):
    def setUp(self):
        self.user = UserFactory()
        self.region = RegionFactory()
        self.type_request = MessageTypeFactory()
        self.data = {
            'message': lorem_ipsum(),
            'messageType': self.type_request.pk,
            'user': self.user,
            'address': lorem_ipsum(words_count=4),
            'georegion': self.region.pk,
            'location_0': 25.0,
            'location_1': 50.0,
        }

    def tearDown(self):
        self.region.delete()
        self.user = None
        self.data = None

    #def test_lost_address(self):
    #    self.data['address'] = ''
    #    form = SimpleRequestForm(self.data)
    #    self.assertFalse(form.is_valid())

#    def test_lost_message(self):
#        self.data['message'] = ''
#        form = UserMessageForm(self.data, message_type=self.type_request.pk)
#        self.assertFalse(form.is_valid())

#    def test_lost_first_name(self):
#        self.data['contact_first_name'] = ''
#        form = SimpleRequestForm(self.data)
#        self.assertFalse(form.is_valid())

#    def test_lost_last_name(self):
#        self.data['contact_last_name'] = ''
#        form = SimpleRequestForm(self.data)
#        self.assertFalse(form.is_valid())

#    def test_lost_contacts(self):
#        self.data['contact_mail'] = ''
#        self.data['contact_phone'] = ''
#        form = SimpleRequestForm(self.data)
#        self.assertFalse(form.is_valid())

#    def test_lost_email(self):
#        self.data['contact_mail'] = ''
#        form = SimpleRequestForm(self.data)
#        self.assertTrue(form.is_valid(), form.errors)

#    def test_lost_phone(self):
#        self.data['contact_phone'] = ''
#        form = SimpleRequestForm(self.data)
#        self.assertTrue(form.is_valid())
<commit_msg>Added UserMessageForm test<commit_after># coding: utf-8

import unittest

from django import forms

from core.factories import CategoryFactory
from geozones.factories import RegionFactory
from message.forms import MessageForm, UserMessageForm
from message.models import Message, Category

from test.utils import lorem_ipsum
from test.factories import UserFactory


class TestBaseMessageForm(unittest.TestCase):

    def setUp(self):
        self.user = UserFactory()
        self.region = RegionFactory()
        self.data = {
            'title': lorem_ipsum(words_count=3),
            'message': lorem_ipsum(),
            'georegion': self.region.pk,
            'messageType': Message.REQUEST,
        }

    def tearDown(self):
        self.region.delete()
        self.region = None
        self.user.delete()

#    def test_form_type(self):
#        self.assertEqual(
#            self.type_request.pk,
#            self.form.fields['messageType'].initial)

    def test_send_data(self):
        form = MessageForm(self.data)
        self.assertTrue(form.is_bound)
        self.assertTrue(form.is_valid(), form.errors)
        msg = form.save(commit=False)
        msg.user = self.user
        msg.save()
        self.assertIsNotNone(msg)
        self.assertIsNotNone(msg.pk)
        self.assertEqual(Message.NEW, msg.status)
        self.assertEqual(Message.REQUEST, msg.messageType)
        msg.delete()

    def test_lost_message(self):
        self.data["message"] = ""
        form = MessageForm(self.data)
        self.assertFalse(form.is_valid())


class TestUserMessageForm(unittest.TestCase):
    def setUp(self):
        self.form = UserMessageForm()

    def test_messagetype_widget(self):
        self.assertIsInstance(
            self.form.fields['messageType'].widget,
            forms.HiddenInput)


class TestRequestCategory(unittest.TestCase):
    def setUp(self):
        self.cats = list()
        for x in xrange(5):
            self.cats.append(CategoryFactory())
        self.user = UserFactory()
        self.region = RegionFactory()
#        self.type_request = MessageTypeFactory()
        self.data = {
            'message': lorem_ipsum(),
#            'messageType': self.type_request.pk,
            'user_id': self.user,
            'georegion': self.region.pk,
            'location_0': 25.0,
            'location_1': 50.0,
            'category': [x.pk for x in self.cats],
            'address': lorem_ipsum(words_count=4)
        }

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

#    def test_message_with_cats(self):
#        form = UserMessageForm(self.data, message_type=self.type_request.pk)
#        self.assertTrue(form.is_valid())
#        msg = form.save(commit=False)
#        msg.user = self.user
#        msg.save()
#        form.save_m2m()
#        self.assertEqual(5, msg.category.all().count())


class TestRequiredFields(unittest.TestCase):
    def setUp(self):
        self.user = UserFactory()
        self.region = RegionFactory()
        self.type_request = MessageTypeFactory()
        self.data = {
            'message': lorem_ipsum(),
            'messageType': self.type_request.pk,
            'user': self.user,
            'address': lorem_ipsum(words_count=4),
            'georegion': self.region.pk,
            'location_0': 25.0,
            'location_1': 50.0,
        }

    def tearDown(self):
        self.region.delete()
        self.user = None
        self.data = None

    #def test_lost_address(self):
    #    self.data['address'] = ''
    #    form = SimpleRequestForm(self.data)
    #    self.assertFalse(form.is_valid())

#    def test_lost_message(self):
#        self.data['message'] = ''
#        form = UserMessageForm(self.data, message_type=self.type_request.pk)
#        self.assertFalse(form.is_valid())

#    def test_lost_first_name(self):
#        self.data['contact_first_name'] = ''
#        form = SimpleRequestForm(self.data)
#        self.assertFalse(form.is_valid())

#    def test_lost_last_name(self):
#        self.data['contact_last_name'] = ''
#        form = SimpleRequestForm(self.data)
#        self.assertFalse(form.is_valid())

#    def test_lost_contacts(self):
#        self.data['contact_mail'] = ''
#        self.data['contact_phone'] = ''
#        form = SimpleRequestForm(self.data)
#        self.assertFalse(form.is_valid())

#    def test_lost_email(self):
#        self.data['contact_mail'] = ''
#        form = SimpleRequestForm(self.data)
#        self.assertTrue(form.is_valid(), form.errors)

#    def test_lost_phone(self):
#        self.data['contact_phone'] = ''
#        form = SimpleRequestForm(self.data)
#        self.assertTrue(form.is_valid())

{'fraction_non_alphanumeric': 0.1286170095720101, 'fraction_numerical': 0.0050610628231928705, 'mean_word_length': 2.4134434847915887, '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': '4492042', 'n_tokens_mistral': 2841, 'n_tokens_neox': 2786, 'n_words': 448}