示例#1
0
 def testSaveSameContactTwice(self):
     NAME = "newuser"
     PHONE = "+233123"
     contact = Contact(name=NAME)
     form = CommoditiesContactForm({
         'name': NAME,
         'phone': PHONE
     },
                                   instance=contact)
     self.assertTrue(form.is_valid())
     # this time around, the form should NOT throw an error on re-registration
     contact.save()
     contact.set_default_connection_identity(PHONE,
                                             settings.DEFAULT_BACKEND)
     form = CommoditiesContactForm({
         'name': NAME,
         'phone': PHONE
     },
                                   instance=contact)
     self.assertTrue(form.is_valid())
     # this time around, the form should throw an error on duplicate registration
     NEWNAME = "newname"
     new_contact = Contact(name=NEWNAME)
     form = CommoditiesContactForm({
         'name': NEWNAME,
         'phone': PHONE
     },
                                   instance=new_contact)
     self.assertFalse(form.is_valid())
示例#2
0
 def testFormWithNoPhoneNumber(self):
     NAME = "newuser"
     PHONE = "+233123"
     contact = Contact(name=NAME)
     form = CommoditiesContactForm({'name': NAME}, instance=contact)
     self.assertFalse(form.is_valid())
     form = CommoditiesContactForm({
         'name': NAME,
         'phone': PHONE
     },
                                   instance=contact)
     self.assertTrue(form.is_valid())
示例#3
0
 def testEmptyInstance(self):
     NAME = "newuser"
     PHONE = "+233123"
     contact = Contact(name=NAME)
     form = CommoditiesContactForm({'name': NAME}, instance=None)
     self.assertFalse(form.is_valid())