22from flask import json
33from flask .testing import FlaskClient
44from pytest_mock import MockFixture
5-
5+ from flask_restplus . _http import HTTPStatus
66
77fake = Faker ()
88
@@ -24,7 +24,7 @@ def test_create_activity_should_succeed_with_valid_request(client: FlaskClient,
2424
2525 response = client .post ("/activities" , json = valid_activity_data , follow_redirects = True )
2626
27- assert 201 == response .status_code
27+ assert HTTPStatus . CREATED == response .status_code
2828 repository_create_mock .assert_called_once_with (valid_activity_data )
2929
3030
@@ -39,7 +39,7 @@ def test_create_activity_should_reject_bad_request(client: FlaskClient, mocker:
3939
4040 response = client .post ("/activities" , json = invalid_activity_data , follow_redirects = True )
4141
42- assert 400 == response .status_code
42+ assert HTTPStatus . BAD_REQUEST == response .status_code
4343 repository_create_mock .assert_not_called ()
4444
4545
@@ -51,7 +51,7 @@ def test_list_all_activities(client: FlaskClient, mocker: MockFixture):
5151
5252 response = client .get ("/activities" , follow_redirects = True )
5353
54- assert 200 == response .status_code
54+ assert HTTPStatus . OK == response .status_code
5555 json_data = json .loads (response .data )
5656 assert [] == json_data
5757 repository_find_all_mock .assert_called_once ()
@@ -68,7 +68,7 @@ def test_get_activity_should_succeed_with_valid_id(client: FlaskClient, mocker:
6868
6969 response = client .get ("/activities/%s" % valid_id , follow_redirects = True )
7070
71- assert 200 == response .status_code
71+ assert HTTPStatus . OK == response .status_code
7272 fake_activity == json .loads (response .data )
7373 repository_find_mock .assert_called_once_with (str (valid_id ))
7474
@@ -85,7 +85,7 @@ def test_get_activity_should_return_not_found_with_invalid_id(client: FlaskClien
8585
8686 response = client .get ("/activities/%s" % invalid_id , follow_redirects = True )
8787
88- assert 404 == response .status_code
88+ assert HTTPStatus . NOT_FOUND == response .status_code
8989 repository_find_mock .assert_called_once_with (str (invalid_id ))
9090
9191
@@ -101,7 +101,7 @@ def test_get_activity_should_return_422_for_invalid_id_format(client: FlaskClien
101101
102102 response = client .get ("/activities/%s" % invalid_id , follow_redirects = True )
103103
104- assert 422 == response .status_code
104+ assert HTTPStatus . UNPROCESSABLE_ENTITY == response .status_code
105105 repository_find_mock .assert_called_once_with (str (invalid_id ))
106106
107107
@@ -115,7 +115,7 @@ def test_update_activity_should_succeed_with_valid_data(client: FlaskClient, moc
115115 valid_id = fake .random_int (1 , 9999 )
116116 response = client .put ("/activities/%s" % valid_id , json = valid_activity_data , follow_redirects = True )
117117
118- assert 200 == response .status_code
118+ assert HTTPStatus . OK == response .status_code
119119 fake_activity == json .loads (response .data )
120120 repository_update_mock .assert_called_once_with (str (valid_id ), valid_activity_data )
121121
@@ -132,7 +132,7 @@ def test_update_activity_should_reject_bad_request(client: FlaskClient, mocker:
132132 valid_id = fake .random_int (1 , 9999 )
133133 response = client .put ("/activities/%s" % valid_id , json = invalid_activity_data , follow_redirects = True )
134134
135- assert 400 == response .status_code
135+ assert HTTPStatus . BAD_REQUEST == response .status_code
136136 repository_update_mock .assert_not_called ()
137137
138138
@@ -150,7 +150,7 @@ def test_update_activity_should_return_not_found_with_invalid_id(client: FlaskCl
150150 json = valid_activity_data ,
151151 follow_redirects = True )
152152
153- assert 404 == response .status_code
153+ assert HTTPStatus . NOT_FOUND == response .status_code
154154 repository_update_mock .assert_called_once_with (str (invalid_id ), valid_activity_data )
155155
156156
@@ -165,7 +165,7 @@ def test_delete_activity_should_succeed_with_valid_id(client: FlaskClient, mocke
165165
166166 response = client .delete ("/activities/%s" % valid_id , follow_redirects = True )
167167
168- assert 204 == response .status_code
168+ assert HTTPStatus . NO_CONTENT == response .status_code
169169 assert b'' == response .data
170170 repository_remove_mock .assert_called_once_with (str (valid_id ))
171171
@@ -182,7 +182,7 @@ def test_delete_activity_should_return_not_found_with_invalid_id(client: FlaskCl
182182
183183 response = client .delete ("/activities/%s" % invalid_id , follow_redirects = True )
184184
185- assert 404 == response .status_code
185+ assert HTTPStatus . NOT_FOUND == response .status_code
186186 repository_remove_mock .assert_called_once_with (str (invalid_id ))
187187
188188
@@ -198,5 +198,5 @@ def test_delete_activity_should_return_422_for_invalid_id_format(client: FlaskCl
198198
199199 response = client .delete ("/activities/%s" % invalid_id , follow_redirects = True )
200200
201- assert 422 == response .status_code
201+ assert HTTPStatus . UNPROCESSABLE_ENTITY == response .status_code
202202 repository_remove_mock .assert_called_once_with (str (invalid_id ))
0 commit comments