def test_unfollow_req(self): follower = User(username='******', password='******') followed = User(username='******', password='******') db.session.add(follower) db.session.add(followed) db.session.commit() self.login('follower', 'cat') follower.follow(followed) db.session.commit() url = url_for('main.unfollow') data = { 'followed_id': followed.id, } response = self.client.post(url, data=data) assert response.status_code == 200 self.assertFalse(follower.is_following(followed))
def test_follow_logic(self): u1 = User(email='*****@*****.**', password='******') u2 = User(email='*****@*****.**', password='******') db.session.add(u1) db.session.add(u2) db.session.commit() self.assertFalse(u1.is_following(u2)) self.assertFalse(u1.is_followed_by(u2)) timestamp_before = datetime.utcnow() u1.follow(u2) db.session.commit() 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.followeds.count() == 1) self.assertTrue(u2.followers.count() == 1) f = u1.followeds.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.unfollow(u2) db.session.commit() self.assertFalse(u1.is_following(u2)) self.assertFalse(u1.is_followed_by(u2)) self.assertFalse(u2.is_following(u1)) self.assertFalse(u2.is_followed_by(u1)) self.assertTrue(u1.followeds.count() == 0) self.assertTrue(u2.followers.count() == 0) self.assertTrue(Follow.query.count() == 0) u2.follow(u1) db.session.commit() db.session.delete(u2) db.session.commit() self.assertTrue(Follow.query.count() == 0)