Skip to content

Commit

Permalink
test_no_status_unsupported_if_no_decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuerke Erik committed Mar 25, 2020
1 parent ba52f2c commit 1a53168
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions test/restit/response_status_parameter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,33 @@ class MySchema(Schema):

@path("/")
class MyResource(Resource):

@response(200, {"application/json": MySchema()}, "Everything is ok")
@response(404, {"application/json": RFC7807Schema()}, "Something was not found")
def get(self, request: Request, **path_params) -> Response:
request_body = request.typed_body[dict]
request_body = request.deserialized_body
return Response({"field1": "Hans", "field2": "10"}, status_code=request_body["status"])

def post(self, request: Request) -> Response:
return Response({}, 204)


class ResponseStatusParameterTestCase(unittest.TestCase):
def setUp(self) -> None:
self.restit_test_app = RestItTestApp(RestItApp(resources=[MyResource()]))

def test_status_supported(self):
response = self.restit_test_app.get("/", json={"status": 200})
self.assertEqual(200, response.status_code)
self.assertEqual({'field1': 'Hans', 'field2': 10}, response.json())
r = self.restit_test_app.get("/", json={"status": 200})
self.assertEqual(200, r.status_code)
self.assertEqual({'field1': 'Hans', 'field2': 10}, r.json())

def test_status_unsupported(self):
with self.assertLogs(level=logging.WARNING) as logs:
response = self.restit_test_app.get("/", json={"status": 201})
self.assertEqual(201, response.status_code)
r = self.restit_test_app.get("/", json={"status": 201})
self.assertEqual(201, r.status_code)

self.assertIn("WARNING:restit.resource:Response status code 201 is not expected for ", logs.output[0])

def test_no_status_unsupported_if_no_decorator(self):
with self.assertRaises(AssertionError):
with self.assertLogs(level=logging.WARNING):
self.restit_test_app.post("/")

0 comments on commit 1a53168

Please sign in to comment.