Coverage for tests/test_tutorial/test_query_params_str_validations/test_tutorial014_py310.py: 100%

23 statements  

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

1import pytest 1deabc

2from fastapi.testclient import TestClient 1deabc

3 

4from ...utils import needs_py310 1deabc

5 

6 

7@pytest.fixture(name="client") 1deabc

8def get_client(): 1deabc

9 from docs_src.query_params_str_validations.tutorial014_py310 import app 1abc

10 

11 client = TestClient(app) 1abc

12 return client 1abc

13 

14 

15@needs_py310 1deabc

16def test_hidden_query(client: TestClient): 1deabc

17 response = client.get("/items?hidden_query=somevalue") 1abc

18 assert response.status_code == 200, response.text 1abc

19 assert response.json() == {"hidden_query": "somevalue"} 1abc

20 

21 

22@needs_py310 1deabc

23def test_no_hidden_query(client: TestClient): 1deabc

24 response = client.get("/items") 1abc

25 assert response.status_code == 200, response.text 1abc

26 assert response.json() == {"hidden_query": "Not found"} 1abc

27 

28 

29@needs_py310 1deabc

30def test_openapi_schema(client: TestClient): 1deabc

31 response = client.get("/openapi.json") 1abc

32 assert response.status_code == 200, response.text 1abc

33 assert response.json() == { 1abc

34 "openapi": "3.1.0", 

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

36 "paths": { 

37 "/items/": { 

38 "get": { 

39 "summary": "Read Items", 

40 "operationId": "read_items_items__get", 

41 "responses": { 

42 "200": { 

43 "description": "Successful Response", 

44 "content": {"application/json": {"schema": {}}}, 

45 }, 

46 "422": { 

47 "description": "Validation Error", 

48 "content": { 

49 "application/json": { 

50 "schema": { 

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

52 } 

53 } 

54 }, 

55 }, 

56 }, 

57 } 

58 } 

59 }, 

60 "components": { 

61 "schemas": { 

62 "HTTPValidationError": { 

63 "title": "HTTPValidationError", 

64 "type": "object", 

65 "properties": { 

66 "detail": { 

67 "title": "Detail", 

68 "type": "array", 

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

70 } 

71 }, 

72 }, 

73 "ValidationError": { 

74 "title": "ValidationError", 

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

76 "type": "object", 

77 "properties": { 

78 "loc": { 

79 "title": "Location", 

80 "type": "array", 

81 "items": { 

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

83 }, 

84 }, 

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

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

87 }, 

88 }, 

89 } 

90 }, 

91 }