def test_13_follows(self): u1 = User(username='******', email='*****@*****.**', password='******') u2 = User(username='******', email='*****@*****.**', password='******') u1.save() u2.save() self.assertFalse(u1.is_following(u2)) self.assertFalse(u1.is_followed_by(u2)) timestamp_before = datetime.utcnow() u1.follow(u2) timestamp_after = datetime.utcnow() self.assertTrue(u1.is_following(u2)) self.assertFalse(u1.is_followed_by(u2)) self.assertTrue(u2.is_followed_by(u1)) self.assertTrue(u1.followed.count() == 2) self.assertTrue(u2.followers.count() == 2) f = u1.followed.all()[-1] self.assertTrue(f.followed == u2) self.assertTrue(timestamp_before <= f.timestamp <= timestamp_after) f = u2.followers.all()[-1] self.assertTrue(f.follower == u1) u1.not_follow(u2) self.assertTrue(u1.followed.count() == 1) self.assertTrue(u2.followers.count() == 1) self.assertTrue(Follow.query.count() == 4) u2.follow(u1) u2.delete() self.assertTrue(Follow.query.count() == 3)
def test_01_save_and_delete(self): kwargs = {"username": self.person.name(), "email": self.person.email()} self.assertEqual(User.query.count(), 0) user = User(**kwargs) user.save() self.assertEqual(user.__repr__(), "<User {} ID {}>".format(kwargs["username"], 1)) self.assertEqual(User.query.count(), 1) user.delete() self.assertEqual(User.query.count(), 0)