Exemplo n.º 1
0
    def test_invalid_data(self):
        """
        Test the save method of :class:`ComposeForm`

        We don't need to make the ``to`` field sweat because we have done that
        in the ``fields`` test.

        """
        invalid_data_dicts = [
            # No body
            {'data': {'to': 'john',
                      'body': ''},
             'error': ('body', [u'This field is required.'])},
        ]

        for invalid_dict in invalid_data_dicts:
            form = ComposeForm(data=invalid_dict['data'])
            self.failIf(form.is_valid())
            self.assertEqual(form.errors[invalid_dict['error'][0]],
                             invalid_dict['error'][1])
Exemplo n.º 2
0
    def test_save_msg(self):
        """ Test valid data """
        valid_data = {'to': 'john, jane',
                      'body': 'Body'}

        form = ComposeForm(data=valid_data)

        self.failUnless(form.is_valid())

        # Save the form.
        sender = User.objects.get(username='******')
        msg = form.save(sender)

        # Check if the values are set correctly
        self.failUnlessEqual(msg.body, valid_data['body'])
        self.failUnlessEqual(msg.sender, sender)
        self.failUnless(msg.sent_at)

        # Check recipients
        self.failUnlessEqual(msg.recipients.all()[0].username, 'jane')
        self.failUnlessEqual(msg.recipients.all()[1].username, 'john')