def test_get_article_by_id(self): # 添加一个用户 data = {'username': '******', 'password': '******'} data = encrypt_data(data) response = self.client.post("/user/signup", data=data) response = json.loads(response.data) self.assertDictContainsSubset({"state": "success"}, response) userid = response['UserId'] # 添加一个RSS data = { 'rsslink': 'http://39.98.93.128:5001/cctv/tech', 'rsstitle': 'cctvtech' } response = self.client.post("/rssdb/addKnownRSS", data=data) response = json.loads(response.data) self.assertDictContainsSubset({"state": "success"}, response) rssid = str(response['moreMsg'][0]['rssId']) # 给用户添加一个RSS data = {'userId': userid, 'RSSId': rssid} response = self.client.post("/userfavor/addFavorRSS", data=data) response = json.loads(response.data) self.assertDictContainsSubset({"state": "success"}, response) # 生成文章列表 data = {'userid': userid} response = self.client.post("/content/getArticles", data=data) response = json.loads(response.data) articleid = response['article_list']['0']['id'] self.assertDictContainsSubset({"state": "success"}, response) data = {'articleid': articleid} response = self.client.post("/content/getArticleById", data=data) response = json.loads(response.data) self.assertDictContainsSubset({"state": "success"}, response)
def test_signup(self): data = {"username": "******", "password": "******"} data = encrypt_data(data) response = self.client.post("/user/signup", data=data) response = json.loads(response.data) print(response) self.assertDictContainsSubset({"state": "success"}, response) response = self.client.post("/user/signup", data=data) response = json.loads(response.data) self.assertDictContainsSubset({"state": "failed"}, response)
def test_token_test(self): data = {"username": "******", "password": "******"} data=encrypt_data(data) response = self.client.post("/user/signup", data=data) response = json.loads(response.data) self.assertDictContainsSubset({"state": "success"}, response) data = {"username": "******", "password": "******"} data=encrypt_data(data) response = self.client.post("/user/login", data=data) response = json.loads(response.data) token = response['token'] headers = {"Authorization": "basic " + base64.b64encode((token + ":").encode("utf-8")).decode("utf-8")} response = self.client.post("/user/token_test", headers=headers) self.assertEqual(response.status_code, 200) response = json.loads(response.data) self.assertDictContainsSubset({"state": "success"}, response) headers = {"Authorization": "basic " + base64.b64encode((token).encode("utf-8")).decode("utf-8")} response = self.client.post("/user/token_test", headers=headers) self.assertEqual(response.status_code, 401)
def test_login(self): data = {"username": "******", "password": "******"} data=encrypt_data(data) response = self.client.post("/user/signup", data=data) response = json.loads(response.data) self.assertDictContainsSubset({"state": "success"}, response) data = {"username": "******", "password": "******"} data=encrypt_data(data) response = self.client.post("/user/login", data=data) response = json.loads(response.data) self.assertDictContainsSubset({"state": "success"}, response) data = {"username": "******", "password": "******"} data=encrypt_data(data) response = self.client.post("/user/login", data=data) response = json.loads(response.data) self.assertDictContainsSubset( {"state": "failed", "description": "No such user."}, response) data = {"username": "******", "password": "******"} data=encrypt_data(data) response = self.client.post("/user/login", data=data) response = json.loads(response.data) self.assertDictContainsSubset( {"state": "failed", "description": "Wrong password."}, response)