- Currently I'm writing a unite testing for my flask project. I wrote a function to test the login feature. When I run the unit test, it showed some error message.
FAILED unit_test.py::TestClass::test_login - AttributeError: 'WrapperTestResponse' object has no attribute 'text'
2.Here is my code for the unit testing implementation, I can get the status code successfully but not the text. Did I make some mistakes?
import unittest
from app import app
import requests
from flask import request
import json
class TestClass(unittest.TestCase):
def setup_class(self):
app.config['TESTING'] = True
self.app = app.test_client()
def teardown_class(self):
"""Do the testing """
pass
def test_login(self):
response = self.app.get('/login')
print(response)
data = {'username': '123456@qq.com', 'password': '12345678'}
response = app.test_client().post('/login', data=json.dumps(data))
self.assertEqual(response.status_code, 200)
print('--------------')
self.assertEqual(response.text, "Invalid login credentials")