def test_unfollow_user(self): global _app if _app is None: tested_app = create_app(debug=True) _app = tested_app else: tested_app = _app restart_db_tables(db, tested_app) with tested_app.test_client() as client: with client.session_transaction() as session: user_a_id, user_b_id, user_c_id, aemail = create_test_users( session) with client.session_transaction() as session: create_test_follow(session, user_a_id, user_b_id, user_c_id) # login as user_1 login(client, aemail, 'test') # call /follow/a/a # return {"followed": -2, "message": "You can't self-unfollow"} reply = client.delete('/follow/' + str(user_a_id) + '/' + str(user_a_id)) data = '{"followed":-2,"message":"You can' self.assertIn(data, str(reply.data)) # call /follow/a/b # return {"followed": 1, "message": "OK"} reply = client.delete('/follow/' + str(user_a_id) + '/' + str(user_b_id)) data = '{"followed":1,"message":"OK"}' self.assertIn(data, str(reply.data)) # call /follow/a/b another time # return {"followed": -1, "message": "You do not already follow this user"} reply = client.delete('/follow/' + str(user_a_id) + '/' + str(user_b_id)) data = '{"followed":-1,"message":"You do not already follow this user"}' self.assertIn(data, str(reply.data)) # call /follow/a/not_exist_id # return {"followed": -3, "message": "The user does not exist"} user_not_exist_id = 999999999999 reply = client.delete('/follow/' + str(user_a_id) + '/' + str(user_not_exist_id)) data = '{"followed":-3,"message":"The user does not exist"}' self.assertIn(data, str(reply.data))
def test_followers_list(self): global _app if _app is None: tested_app = create_app(debug=True) _app = tested_app else: tested_app = _app restart_db_tables(db, tested_app) with tested_app.test_client() as client: with client.session_transaction() as session: user_a_id, user_b_id, user_c_id, aemail = create_test_users( session) # login as user_1 login(client, aemail, 'test') # call /followed/list/a # return {"followed": []} reply = client.get('/followed/list/' + str(user_a_id)) data = 0 res = json.loads(str(reply.data, 'UTF8')) self.assertEqual(data, len(res["followed"])) # Create followers with client.session_transaction() as session: create_test_follow(session, user_a_id, user_b_id, user_c_id) # call /followed/list/a # return {"followed": [<b>, <c>]} reply = client.get('/followed/list/' + str(user_a_id)) data = 2 res = json.loads(str(reply.data, 'UTF8')) self.assertEqual(data, len(res["followed"])) client.delete('/follow/' + str(user_a_id) + '/' + str(user_b_id)) # call /followed/list/a # return {"followed": [<c>]} reply = client.get('/followed/list/' + str(user_a_id)) data = 1 res = json.loads(str(reply.data, 'UTF8')) self.assertEqual(data, len(res["followed"]))
def getTester(self): application = app.create_app() tester = application.test_client(self) return tester