def test_UserPhone(self): """ Test for verifying creationg of UserPhone instance """ phone = u"+987645321" result = models.UserPhone(phone=phone) self.assertIsInstance(result, models.UserPhone)
def test_UserPhone_unicode(self): """ Test for verifying whether UserPhone's unicode method returns phone number in unicode """ phone = u'+8080808080' result = unicode(models.UserPhone(phone)) self.assertIsInstance(result, unicode) self.assertEqual(result, phone)
def test_user_phone(self): """ Test to retrieve UserPhone property phone """ # scenario 1: when there is a phone set as primary crusoe = self.fixtures.crusoe crusoe_phone = self.fixtures.crusoe_phone self.assertIsInstance(crusoe.phone, models.UserPhone) self.assertEqual(crusoe_phone, crusoe.phone) self.assertTrue(crusoe.phone.primary) # scenario 2: when there is a phone but not as primary snowball = models.User(username='******') snowball_phone = models.UserPhone(phone='+918574808032', user=snowball) db.session.add_all([snowball, snowball_phone]) db.session.commit() self.assertIsInstance(snowball.phone, models.UserPhone) self.assertEqual(snowball_phone, snowball.phone) self.assertTrue(snowball.phone.primary) # scenario 3: when there is no phone on db piglet = self.fixtures.piglet assert piglet.phone == ''