Coverage for tests / test_reponse_set_reponse_code_empty.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1from typing import Any 1abcd

2 

3from fastapi import FastAPI, Response 1abcd

4from fastapi.testclient import TestClient 1abcd

5from inline_snapshot import snapshot 1abcd

6 

7app = FastAPI() 1abcd

8 

9 

10@app.delete( 1abcd

11 "/{id}", 

12 status_code=204, 

13 response_model=None, 

14) 

15async def delete_deployment( 1abcd

16 id: int, 

17 response: Response, 

18) -> Any: 

19 response.status_code = 400 1efg

20 return {"msg": "Status overwritten", "id": id} 1efg

21 

22 

23client = TestClient(app) 1abcd

24 

25 

26def test_dependency_set_status_code(): 1abcd

27 response = client.delete("/1") 1efg

28 assert response.status_code == 400 and response.content 1efg

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

30 

31 

32def test_openapi_schema(): 1abcd

33 response = client.get("/openapi.json") 1hij

34 assert response.status_code == 200, response.text 1hij

35 assert response.json() == snapshot( 1hij

36 { 

37 "openapi": "3.1.0", 

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

39 "paths": { 

40 "/{id}": { 

41 "delete": { 

42 "summary": "Delete Deployment", 

43 "operationId": "delete_deployment__id__delete", 

44 "parameters": [ 

45 { 

46 "required": True, 

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

48 "name": "id", 

49 "in": "path", 

50 } 

51 ], 

52 "responses": { 

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

54 "422": { 

55 "description": "Validation Error", 

56 "content": { 

57 "application/json": { 

58 "schema": { 

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

60 } 

61 } 

62 }, 

63 }, 

64 }, 

65 } 

66 } 

67 }, 

68 "components": { 

69 "schemas": { 

70 "HTTPValidationError": { 

71 "title": "HTTPValidationError", 

72 "type": "object", 

73 "properties": { 

74 "detail": { 

75 "title": "Detail", 

76 "type": "array", 

77 "items": { 

78 "$ref": "#/components/schemas/ValidationError" 

79 }, 

80 } 

81 }, 

82 }, 

83 "ValidationError": { 

84 "title": "ValidationError", 

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

86 "type": "object", 

87 "properties": { 

88 "loc": { 

89 "title": "Location", 

90 "type": "array", 

91 "items": { 

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

93 }, 

94 }, 

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

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

97 "input": {"title": "Input"}, 

98 "ctx": {"title": "Context", "type": "object"}, 

99 }, 

100 }, 

101 } 

102 }, 

103 } 

104 )