Coverage for tests/test_reponse_set_reponse_code_empty.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1from typing import Any 1abcde

2 

3from fastapi import FastAPI, Response 1abcde

4from fastapi.testclient import TestClient 1abcde

5 

6app = FastAPI() 1abcde

7 

8 

9@app.delete( 1abcde

10 "/{id}", 

11 status_code=204, 

12 response_model=None, 

13) 

14async def delete_deployment( 1abcde

15 id: int, 

16 response: Response, 

17) -> Any: 

18 response.status_code = 400 1abcde

19 return {"msg": "Status overwritten", "id": id} 1abcde

20 

21 

22client = TestClient(app) 1abcde

23 

24 

25def test_dependency_set_status_code(): 1abcde

26 response = client.delete("/1") 1abcde

27 assert response.status_code == 400 and response.content 1abcde

28 assert response.json() == {"msg": "Status overwritten", "id": 1} 1abcde

29 

30 

31def test_openapi_schema(): 1abcde

32 response = client.get("/openapi.json") 1abcde

33 assert response.status_code == 200, response.text 1abcde

34 assert response.json() == { 1abcde

35 "openapi": "3.1.0", 

36 "info": {"title": "FastAPI", "version": "0.1.0"}, 

37 "paths": { 

38 "/{id}": { 

39 "delete": { 

40 "summary": "Delete Deployment", 

41 "operationId": "delete_deployment__id__delete", 

42 "parameters": [ 

43 { 

44 "required": True, 

45 "schema": {"title": "Id", "type": "integer"}, 

46 "name": "id", 

47 "in": "path", 

48 } 

49 ], 

50 "responses": { 

51 "204": {"description": "Successful Response"}, 

52 "422": { 

53 "description": "Validation Error", 

54 "content": { 

55 "application/json": { 

56 "schema": { 

57 "$ref": "#/components/schemas/HTTPValidationError" 

58 } 

59 } 

60 }, 

61 }, 

62 }, 

63 } 

64 } 

65 }, 

66 "components": { 

67 "schemas": { 

68 "HTTPValidationError": { 

69 "title": "HTTPValidationError", 

70 "type": "object", 

71 "properties": { 

72 "detail": { 

73 "title": "Detail", 

74 "type": "array", 

75 "items": {"$ref": "#/components/schemas/ValidationError"}, 

76 } 

77 }, 

78 }, 

79 "ValidationError": { 

80 "title": "ValidationError", 

81 "required": ["loc", "msg", "type"], 

82 "type": "object", 

83 "properties": { 

84 "loc": { 

85 "title": "Location", 

86 "type": "array", 

87 "items": { 

88 "anyOf": [{"type": "string"}, {"type": "integer"}] 

89 }, 

90 }, 

91 "msg": {"title": "Message", "type": "string"}, 

92 "type": {"title": "Error Type", "type": "string"}, 

93 }, 

94 }, 

95 } 

96 }, 

97 }