Esempio n. 1
0
class TestMessage(unittest.TestCase):
    """
    Test messages
    """

    def setUp(self):
        self.user = UserFactory()
        self.region = RegionFactory()
        self.message = MessageFactory.build(georegion=self.region)

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

    def test_message_unicode(self):
        self.assertEqual(self.message.title, "%s" % self.message)

    def test_message_save(self):
        self.message.save()
        self.assertIsNotNone(self.message.pk)
        self.message.delete()

    def test_message_remove(self):
        self.message.is_removed = True
        self.assertTrue(self.message.is_removed)

    def test_message_restore(self):
        self.message.is_removed = True
        self.assertTrue(self.message.is_removed)
        self.message.is_removed = False
        self.assertFalse(self.message.is_removed)
Esempio n. 2
0
class TestRequiredFields(unittest.TestCase):
    def setUp(self):
        self.user = UserFactory.build()
        self.region = RegionFactory()
        self.data = {
            "message": lorem_ipsum(),
            "messageType": MessageType.TYPE_REQUEST,
            "contact_first_name": self.user.first_name,
            "contact_last_name": self.user.last_name,
            "contact_mail": self.user.email,
            "contact_phone": "12345678",
            "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 = SimpleRequestForm(self.data)
        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())
Esempio n. 3
0
class TestSendMessage(WebTest):
    def setUp(self):
        self.region = RegionFactory()
        self.form = self.app.get('/message/pomogite/dobavit').forms['mainForm']

    def tearDown(self):
        Message.objects.all().delete()
        self.region.delete()
        self.form = None

    def test_anonymous_message(self):
        before = Message.objects.count()
        self.form['title'] = 'Test message'
        self.form['message'] = "This is simple test message"
        self.form['contact_first_name'] = 'Dummy'
        self.form['contact_last_name'] = 'User'
        self.form['contact_mail'] = '*****@*****.**'
        self.form['contact_phone'] = '123456789'
        self.form['georegion'] = self.region.pk
        self.form['address'] = 'Some address string'
        self.form.submit()
        self.assertEqual(before + 1, Message.objects.count())

    def test_knownuser_form(self):
        ''' Form for authenticated user contain initial data for some fields'''
        user = UserFactory(is_active=True)
        form = self.app.get(
            '/message/pomogite/dobavit',
            user=user.username).forms['mainForm']
        self.assertEqual(user.first_name, form['contact_first_name'].value)
        self.assertEqual(user.last_name, form['contact_last_name'].value)
        self.assertEqual(user.email, form['contact_mail'].value)
        self.assertEqual(user.profile.phones, form['contact_phone'].value)
        user.delete()

    def test_knownuser_message(self):
        ''' Authenticated user send message and this message must be
            linked to user profile'''
        before = Message.objects.count()
        user = UserFactory(is_active=True)
        form = self.app.get(
            '/message/pomogite/dobavit',
            user=user.username).forms['mainForm']
        form['title'] = 'Test message'
        form['message'] = "This is simple test message"
        form['georegion'] = self.region.pk
        form['address'] = 'Some address'
        form.submit()
        self.assertEqual(before + 1, Message.objects.count())
        msg = Message.objects.all().select_related().reverse()[0]
        self.assertEqual(msg.user, user)
        user.delete()
Esempio n. 4
0
class TestMessageCleanData(unittest.TestCase):
    """
    Test message cleaf functionality.
    """

    def setUp(self):
        self.user = UserFactory()
        self.region = RegionFactory()
        self.message = MessageFactory.build(georegion=self.region)

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

    def catch_wrong_data(self):
        """ Common test missed data"""
        with self.assertRaises(ValidationError):
            self.message.save()
            self.message.delete()

    def test_no_message_contacts(self):
        self.message.contact_phone = None
        self.message.contact_mail = None
        self.catch_wrong_data()

    def test_invalid_email(self):
        self.message.contact_mail = "notamail"
        self.catch_wrong_data()

    def test_phone_contact(self):
        self.message.contact_mail = ""
        self.message.save()
        self.assertIsNotNone(self.message.pk)
        self.message.delete()

    def test_email_contact(self):
        self.message.contact_phone = ""
        self.message.save()
        self.assertIsNotNone(self.message.pk)
        self.message.delete()
Esempio n. 5
0
class TestSimpleRequestForm(unittest.TestCase):
    def setUp(self):
        self.form = SimpleRequestForm()
        self.user = UserFactory()
        self.region = RegionFactory()
        self.data = {
            "title": lorem_ipsum(words_count=3),
            "message": lorem_ipsum(),
            "messageType": MessageType.TYPE_REQUEST,
            "contact_first_name": self.user.first_name,
            "contact_last_name": self.user.last_name,
            "contact_mail": self.user.email,
            "georegion": self.region.pk,
            "location_0": 0.0,
            "location_1": 0.0,
            "address": lorem_ipsum(words_count=4),
        }

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

    def test_form_type(self):
        self.assertEqual(1, self.form.fields["messageType"].initial)

    def test_send_data(self):
        form = SimpleRequestForm(self.data)
        self.assertTrue(form.is_bound)
        self.assertTrue(form.is_valid(), form.errors)
        msg = form.save(commit=True)
        self.assertIsNotNone(msg)
        self.assertIsNotNone(msg.pk)
        self.assertEqual(1, msg.status)
        self.assertEqual(1, msg.messageType)
        msg.delete()
Esempio n. 6
0
 def setUp(self):
     self.user = UserFactory.build()
     self.region = RegionFactory()
     self.data = {
         "message": lorem_ipsum(),
         "messageType": MessageType.TYPE_REQUEST,
         "contact_first_name": self.user.first_name,
         "contact_last_name": self.user.last_name,
         "contact_mail": self.user.email,
         "contact_phone": "12345678",
         "address": lorem_ipsum(words_count=4),
         "georegion": self.region.pk,
         "location_0": 25.0,
         "location_1": 50.0,
     }
Esempio n. 7
0
 def setUp(self):
     self.form = SimpleRequestForm()
     self.user = UserFactory()
     self.region = RegionFactory()
     self.data = {
         "title": lorem_ipsum(words_count=3),
         "message": lorem_ipsum(),
         "messageType": MessageType.TYPE_REQUEST,
         "contact_first_name": self.user.first_name,
         "contact_last_name": self.user.last_name,
         "contact_mail": self.user.email,
         "georegion": self.region.pk,
         "location_0": 0.0,
         "location_1": 0.0,
         "address": lorem_ipsum(words_count=4),
     }
Esempio n. 8
0
 def setUp(self):
     self.region = RegionFactory()
     self.form = self.app.get('/message/pomogite/dobavit').forms['mainForm']
Esempio n. 9
0
 def setUp(self):
     self.region = RegionFactory.build()
Esempio n. 10
0
 def setUp(self):
     self.user = UserFactory()
     self.region = RegionFactory()
     self.message = MessageFactory.build(georegion=self.region)