Exemple #1
0
def send(request):
    form = MessageForm(request.POST)
    if form.is_valid():
        recipients = form.send()
        text = form.cleaned_data['text']
        names = ", ".join(str(r) for r in recipients)
        return HttpResponse("'%s' sent to %s" % (text, names))
    return HttpResponseBadRequest(unicode(form.errors))
Exemple #2
0
 def test_valid_send_data(self):
     """
     MessageForm.send should return successfully with valid data
     """
     data = {'text': 'hello!', 'recipients': [self.contact.id]}
     form = MessageForm(data)
     self.assertTrue(form.is_valid())
     recipients = form.send()
     self.assertTrue(self.contact in recipients)
     self.assertEqual(self.outbox[0].text, data['text'])
Exemple #3
0
 def test_valid_send_data(self):
     """
     MessageForm.send should return successfully with valid data
     """
     data = {'text': 'hello!',
             'recipients': [self.contact.id]}
     form = MessageForm(data)
     self.assertTrue(form.is_valid())
     recipients = form.send()
     self.assertTrue(self.contact in recipients)
     self.assertEqual(self.outbound[0].text, data['text'])
Exemple #4
0
 def test_contacts_with_connection(self):
     """
     Only contacts with connections are valid options
     """
     connectionless_contact = self.create_contact()
     data = {
         'text': 'hello!',
         'recipients': [self.contact.id, connectionless_contact.pk]
     }
     form = MessageForm(data)
     self.assertTrue('recipients' in form.errors)
     self.assertEqual(len(self.outbox), 0)