def test_follow_unfollow(self): user1 = User(name='tester1', email='*****@*****.**', password='******') db.session.add(user1) user2 = User(name='tester2', email='*****@*****.**', password='******') db.session.add(user2) db.session.commit() user1.follow(user2) assert user1.num_following == 1 assert user1.get_following_query().first().id == user2.id assert user2.num_followers == 1 assert user2.get_followers_query().first().id == user1.id user1.unfollow(user2) assert user1.num_following == 0 assert user2.num_followers == 0
def initdb(): """ 初始化数据,插入管理员admin,用户guest """ # 管理员admin user_detail = UserDetail( age =10, phone =u'13702001234', url =u'http://www.narota.com', deposit =100.00, location =u'GuangZhou', bio = u'this is a admin', ) user_detail.save() user = User( name = u'admin', email = u'*****@*****.**', _password = generate_password_hash(u'123456'), role_id = ADMIN, status_id = ACTIVE, user_detail = user_detail.id ) user.save() # 用户guest user_detail = UserDetail( age =10, phone =u'13702001234', url =u'http://www.narota.com', deposit =100.00, location =u'GuangZhou', bio = u'this is a guest' ) user_detail.save() user = User( name = u'guest', email = u'*****@*****.**', _password = generate_password_hash(u'123456'), role_id = USER, status_id = ACTIVE, user_detail = user_detail.id, ) user.save()