Reputation: 13
I'm trying to unittest my app in flask, but I'm getting a little bit stuck witch this one. I want to add a parameter to my app route but I don't know how to do this. Can anybody help me?
I set the vacancy id hardcoded in the test for now, but I will add a connection and a query to the database. But I first wanted to get this to work
This is the route:
@app.route('/add_application/<vacancy_id>')
def add_application(vacancy_id):
return render_template(
'addapplication.html')
This is my test so far:
VACANCY_ID = '5f67bc3643f71774b981ebfc'
def test_addapplicationFromVacancy(self):
tester = app.test_client(self)
tester.post(
'/login',
data=dict(username=USERNAME_USER, password=SPW_TWO),
follow_redirects=True
)
response = tester.get(
'/add_application/',
data={'vacancy_id': VACANCY_ID},
content_type='html/text'
)
print()
self.assertEqual(response.status_code, 200)
Upvotes: 1
Views: 1116
Reputation: 269
I don't know your whole application however I see at least two things which could help you here:
self
during creating the client because this is the object of the unittest.TestCase
class, not the Flask application's one. And it will be passed automatically.
tester = app.test_client()
tester.get(f"/add_application/{VACANCY_ID}", ...)
*I have used here f-string, feel free to change it if you are not using >=3.6 version of PythonUpvotes: 3