Coverage for tests/test_path.py: 100%
303 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1from dirty_equals import IsDict 1abcde
2from fastapi.testclient import TestClient 1abcde
4from .main import app 1abcde
6client = TestClient(app) 1abcde
9def test_text_get(): 1abcde
10 response = client.get("/text") 1abcde
11 assert response.status_code == 200, response.text 1abcde
12 assert response.json() == "Hello World" 1abcde
15def test_nonexistent(): 1abcde
16 response = client.get("/nonexistent") 1abcde
17 assert response.status_code == 404, response.text 1abcde
18 assert response.json() == {"detail": "Not Found"} 1abcde
21def test_path_foobar(): 1abcde
22 response = client.get("/path/foobar") 1abcde
23 assert response.status_code == 200 1abcde
24 assert response.json() == "foobar" 1abcde
27def test_path_str_foobar(): 1abcde
28 response = client.get("/path/str/foobar") 1abcde
29 assert response.status_code == 200 1abcde
30 assert response.json() == "foobar" 1abcde
33def test_path_str_42(): 1abcde
34 response = client.get("/path/str/42") 1abcde
35 assert response.status_code == 200 1abcde
36 assert response.json() == "42" 1abcde
39def test_path_str_True(): 1abcde
40 response = client.get("/path/str/True") 1abcde
41 assert response.status_code == 200 1abcde
42 assert response.json() == "True" 1abcde
45def test_path_int_foobar(): 1abcde
46 response = client.get("/path/int/foobar") 1abcde
47 assert response.status_code == 422 1abcde
48 assert response.json() == IsDict( 1abcde
49 {
50 "detail": [
51 {
52 "type": "int_parsing",
53 "loc": ["path", "item_id"],
54 "msg": "Input should be a valid integer, unable to parse string as an integer",
55 "input": "foobar",
56 }
57 ]
58 }
59 ) | IsDict(
60 # TODO: remove when deprecating Pydantic v1
61 {
62 "detail": [
63 {
64 "loc": ["path", "item_id"],
65 "msg": "value is not a valid integer",
66 "type": "type_error.integer",
67 }
68 ]
69 }
70 )
73def test_path_int_True(): 1abcde
74 response = client.get("/path/int/True") 1abcde
75 assert response.status_code == 422 1abcde
76 assert response.json() == IsDict( 1abcde
77 {
78 "detail": [
79 {
80 "type": "int_parsing",
81 "loc": ["path", "item_id"],
82 "msg": "Input should be a valid integer, unable to parse string as an integer",
83 "input": "True",
84 }
85 ]
86 }
87 ) | IsDict(
88 # TODO: remove when deprecating Pydantic v1
89 {
90 "detail": [
91 {
92 "loc": ["path", "item_id"],
93 "msg": "value is not a valid integer",
94 "type": "type_error.integer",
95 }
96 ]
97 }
98 )
101def test_path_int_42(): 1abcde
102 response = client.get("/path/int/42") 1abcde
103 assert response.status_code == 200 1abcde
104 assert response.json() == 42 1abcde
107def test_path_int_42_5(): 1abcde
108 response = client.get("/path/int/42.5") 1abcde
109 assert response.status_code == 422 1abcde
110 assert response.json() == IsDict( 1abcde
111 {
112 "detail": [
113 {
114 "type": "int_parsing",
115 "loc": ["path", "item_id"],
116 "msg": "Input should be a valid integer, unable to parse string as an integer",
117 "input": "42.5",
118 }
119 ]
120 }
121 ) | IsDict(
122 # TODO: remove when deprecating Pydantic v1
123 {
124 "detail": [
125 {
126 "loc": ["path", "item_id"],
127 "msg": "value is not a valid integer",
128 "type": "type_error.integer",
129 }
130 ]
131 }
132 )
135def test_path_float_foobar(): 1abcde
136 response = client.get("/path/float/foobar") 1abcde
137 assert response.status_code == 422 1abcde
138 assert response.json() == IsDict( 1abcde
139 {
140 "detail": [
141 {
142 "type": "float_parsing",
143 "loc": ["path", "item_id"],
144 "msg": "Input should be a valid number, unable to parse string as a number",
145 "input": "foobar",
146 }
147 ]
148 }
149 ) | IsDict(
150 # TODO: remove when deprecating Pydantic v1
151 {
152 "detail": [
153 {
154 "loc": ["path", "item_id"],
155 "msg": "value is not a valid float",
156 "type": "type_error.float",
157 }
158 ]
159 }
160 )
163def test_path_float_True(): 1abcde
164 response = client.get("/path/float/True") 1abcde
165 assert response.status_code == 422 1abcde
166 assert response.json() == IsDict( 1abcde
167 {
168 "detail": [
169 {
170 "type": "float_parsing",
171 "loc": ["path", "item_id"],
172 "msg": "Input should be a valid number, unable to parse string as a number",
173 "input": "True",
174 }
175 ]
176 }
177 ) | IsDict(
178 # TODO: remove when deprecating Pydantic v1
179 {
180 "detail": [
181 {
182 "loc": ["path", "item_id"],
183 "msg": "value is not a valid float",
184 "type": "type_error.float",
185 }
186 ]
187 }
188 )
191def test_path_float_42(): 1abcde
192 response = client.get("/path/float/42") 1abcde
193 assert response.status_code == 200 1abcde
194 assert response.json() == 42 1abcde
197def test_path_float_42_5(): 1abcde
198 response = client.get("/path/float/42.5") 1abcde
199 assert response.status_code == 200 1abcde
200 assert response.json() == 42.5 1abcde
203def test_path_bool_foobar(): 1abcde
204 response = client.get("/path/bool/foobar") 1abcde
205 assert response.status_code == 422 1abcde
206 assert response.json() == IsDict( 1abcde
207 {
208 "detail": [
209 {
210 "type": "bool_parsing",
211 "loc": ["path", "item_id"],
212 "msg": "Input should be a valid boolean, unable to interpret input",
213 "input": "foobar",
214 }
215 ]
216 }
217 ) | IsDict(
218 # TODO: remove when deprecating Pydantic v1
219 {
220 "detail": [
221 {
222 "loc": ["path", "item_id"],
223 "msg": "value could not be parsed to a boolean",
224 "type": "type_error.bool",
225 }
226 ]
227 }
228 )
231def test_path_bool_True(): 1abcde
232 response = client.get("/path/bool/True") 1abcde
233 assert response.status_code == 200 1abcde
234 assert response.json() is True 1abcde
237def test_path_bool_42(): 1abcde
238 response = client.get("/path/bool/42") 1abcde
239 assert response.status_code == 422 1abcde
240 assert response.json() == IsDict( 1abcde
241 {
242 "detail": [
243 {
244 "type": "bool_parsing",
245 "loc": ["path", "item_id"],
246 "msg": "Input should be a valid boolean, unable to interpret input",
247 "input": "42",
248 }
249 ]
250 }
251 ) | IsDict(
252 # TODO: remove when deprecating Pydantic v1
253 {
254 "detail": [
255 {
256 "loc": ["path", "item_id"],
257 "msg": "value could not be parsed to a boolean",
258 "type": "type_error.bool",
259 }
260 ]
261 }
262 )
265def test_path_bool_42_5(): 1abcde
266 response = client.get("/path/bool/42.5") 1abcde
267 assert response.status_code == 422 1abcde
268 assert response.json() == IsDict( 1abcde
269 {
270 "detail": [
271 {
272 "type": "bool_parsing",
273 "loc": ["path", "item_id"],
274 "msg": "Input should be a valid boolean, unable to interpret input",
275 "input": "42.5",
276 }
277 ]
278 }
279 ) | IsDict(
280 # TODO: remove when deprecating Pydantic v1
281 {
282 "detail": [
283 {
284 "loc": ["path", "item_id"],
285 "msg": "value could not be parsed to a boolean",
286 "type": "type_error.bool",
287 }
288 ]
289 }
290 )
293def test_path_bool_1(): 1abcde
294 response = client.get("/path/bool/1") 1abcde
295 assert response.status_code == 200 1abcde
296 assert response.json() is True 1abcde
299def test_path_bool_0(): 1abcde
300 response = client.get("/path/bool/0") 1abcde
301 assert response.status_code == 200 1abcde
302 assert response.json() is False 1abcde
305def test_path_bool_true(): 1abcde
306 response = client.get("/path/bool/true") 1abcde
307 assert response.status_code == 200 1abcde
308 assert response.json() is True 1abcde
311def test_path_bool_False(): 1abcde
312 response = client.get("/path/bool/False") 1abcde
313 assert response.status_code == 200 1abcde
314 assert response.json() is False 1abcde
317def test_path_bool_false(): 1abcde
318 response = client.get("/path/bool/false") 1abcde
319 assert response.status_code == 200 1abcde
320 assert response.json() is False 1abcde
323def test_path_param_foo(): 1abcde
324 response = client.get("/path/param/foo") 1abcde
325 assert response.status_code == 200 1abcde
326 assert response.json() == "foo" 1abcde
329def test_path_param_minlength_foo(): 1abcde
330 response = client.get("/path/param-minlength/foo") 1abcde
331 assert response.status_code == 200 1abcde
332 assert response.json() == "foo" 1abcde
335def test_path_param_minlength_fo(): 1abcde
336 response = client.get("/path/param-minlength/fo") 1abcde
337 assert response.status_code == 422 1abcde
338 assert response.json() == IsDict( 1abcde
339 {
340 "detail": [
341 {
342 "type": "string_too_short",
343 "loc": ["path", "item_id"],
344 "msg": "String should have at least 3 characters",
345 "input": "fo",
346 "ctx": {"min_length": 3},
347 }
348 ]
349 }
350 ) | IsDict(
351 # TODO: remove when deprecating Pydantic v1
352 {
353 "detail": [
354 {
355 "loc": ["path", "item_id"],
356 "msg": "ensure this value has at least 3 characters",
357 "type": "value_error.any_str.min_length",
358 "ctx": {"limit_value": 3},
359 }
360 ]
361 }
362 )
365def test_path_param_maxlength_foo(): 1abcde
366 response = client.get("/path/param-maxlength/foo") 1abcde
367 assert response.status_code == 200 1abcde
368 assert response.json() == "foo" 1abcde
371def test_path_param_maxlength_foobar(): 1abcde
372 response = client.get("/path/param-maxlength/foobar") 1abcde
373 assert response.status_code == 422 1abcde
374 assert response.json() == IsDict( 1abcde
375 {
376 "detail": [
377 {
378 "type": "string_too_long",
379 "loc": ["path", "item_id"],
380 "msg": "String should have at most 3 characters",
381 "input": "foobar",
382 "ctx": {"max_length": 3},
383 }
384 ]
385 }
386 ) | IsDict(
387 # TODO: remove when deprecating Pydantic v1
388 {
389 "detail": [
390 {
391 "loc": ["path", "item_id"],
392 "msg": "ensure this value has at most 3 characters",
393 "type": "value_error.any_str.max_length",
394 "ctx": {"limit_value": 3},
395 }
396 ]
397 }
398 )
401def test_path_param_min_maxlength_foo(): 1abcde
402 response = client.get("/path/param-min_maxlength/foo") 1abcde
403 assert response.status_code == 200 1abcde
404 assert response.json() == "foo" 1abcde
407def test_path_param_min_maxlength_foobar(): 1abcde
408 response = client.get("/path/param-min_maxlength/foobar") 1abcde
409 assert response.status_code == 422 1abcde
410 assert response.json() == IsDict( 1abcde
411 {
412 "detail": [
413 {
414 "type": "string_too_long",
415 "loc": ["path", "item_id"],
416 "msg": "String should have at most 3 characters",
417 "input": "foobar",
418 "ctx": {"max_length": 3},
419 }
420 ]
421 }
422 ) | IsDict(
423 # TODO: remove when deprecating Pydantic v1
424 {
425 "detail": [
426 {
427 "loc": ["path", "item_id"],
428 "msg": "ensure this value has at most 3 characters",
429 "type": "value_error.any_str.max_length",
430 "ctx": {"limit_value": 3},
431 }
432 ]
433 }
434 )
437def test_path_param_min_maxlength_f(): 1abcde
438 response = client.get("/path/param-min_maxlength/f") 1abcde
439 assert response.status_code == 422 1abcde
440 assert response.json() == IsDict( 1abcde
441 {
442 "detail": [
443 {
444 "type": "string_too_short",
445 "loc": ["path", "item_id"],
446 "msg": "String should have at least 2 characters",
447 "input": "f",
448 "ctx": {"min_length": 2},
449 }
450 ]
451 }
452 ) | IsDict(
453 {
454 "detail": [
455 {
456 "loc": ["path", "item_id"],
457 "msg": "ensure this value has at least 2 characters",
458 "type": "value_error.any_str.min_length",
459 "ctx": {"limit_value": 2},
460 }
461 ]
462 }
463 )
466def test_path_param_gt_42(): 1abcde
467 response = client.get("/path/param-gt/42") 1abcde
468 assert response.status_code == 200 1abcde
469 assert response.json() == 42 1abcde
472def test_path_param_gt_2(): 1abcde
473 response = client.get("/path/param-gt/2") 1abcde
474 assert response.status_code == 422 1abcde
475 assert response.json() == IsDict( 1abcde
476 {
477 "detail": [
478 {
479 "type": "greater_than",
480 "loc": ["path", "item_id"],
481 "msg": "Input should be greater than 3",
482 "input": "2",
483 "ctx": {"gt": 3.0},
484 }
485 ]
486 }
487 ) | IsDict(
488 # TODO: remove when deprecating Pydantic v1
489 {
490 "detail": [
491 {
492 "loc": ["path", "item_id"],
493 "msg": "ensure this value is greater than 3",
494 "type": "value_error.number.not_gt",
495 "ctx": {"limit_value": 3},
496 }
497 ]
498 }
499 )
502def test_path_param_gt0_0_05(): 1abcde
503 response = client.get("/path/param-gt0/0.05") 1abcde
504 assert response.status_code == 200 1abcde
505 assert response.json() == 0.05 1abcde
508def test_path_param_gt0_0(): 1abcde
509 response = client.get("/path/param-gt0/0") 1abcde
510 assert response.status_code == 422 1abcde
511 assert response.json() == IsDict( 1abcde
512 {
513 "detail": [
514 {
515 "type": "greater_than",
516 "loc": ["path", "item_id"],
517 "msg": "Input should be greater than 0",
518 "input": "0",
519 "ctx": {"gt": 0.0},
520 }
521 ]
522 }
523 ) | IsDict(
524 # TODO: remove when deprecating Pydantic v1
525 {
526 "detail": [
527 {
528 "loc": ["path", "item_id"],
529 "msg": "ensure this value is greater than 0",
530 "type": "value_error.number.not_gt",
531 "ctx": {"limit_value": 0},
532 }
533 ]
534 }
535 )
538def test_path_param_ge_42(): 1abcde
539 response = client.get("/path/param-ge/42") 1abcde
540 assert response.status_code == 200 1abcde
541 assert response.json() == 42 1abcde
544def test_path_param_ge_3(): 1abcde
545 response = client.get("/path/param-ge/3") 1abcde
546 assert response.status_code == 200 1abcde
547 assert response.json() == 3 1abcde
550def test_path_param_ge_2(): 1abcde
551 response = client.get("/path/param-ge/2") 1abcde
552 assert response.status_code == 422 1abcde
553 assert response.json() == IsDict( 1abcde
554 {
555 "detail": [
556 {
557 "type": "greater_than_equal",
558 "loc": ["path", "item_id"],
559 "msg": "Input should be greater than or equal to 3",
560 "input": "2",
561 "ctx": {"ge": 3.0},
562 }
563 ]
564 }
565 ) | IsDict(
566 # TODO: remove when deprecating Pydantic v1
567 {
568 "detail": [
569 {
570 "loc": ["path", "item_id"],
571 "msg": "ensure this value is greater than or equal to 3",
572 "type": "value_error.number.not_ge",
573 "ctx": {"limit_value": 3},
574 }
575 ]
576 }
577 )
580def test_path_param_lt_42(): 1abcde
581 response = client.get("/path/param-lt/42") 1abcde
582 assert response.status_code == 422 1abcde
583 assert response.json() == IsDict( 1abcde
584 {
585 "detail": [
586 {
587 "type": "less_than",
588 "loc": ["path", "item_id"],
589 "msg": "Input should be less than 3",
590 "input": "42",
591 "ctx": {"lt": 3.0},
592 }
593 ]
594 }
595 ) | IsDict(
596 # TODO: remove when deprecating Pydantic v1
597 {
598 "detail": [
599 {
600 "loc": ["path", "item_id"],
601 "msg": "ensure this value is less than 3",
602 "type": "value_error.number.not_lt",
603 "ctx": {"limit_value": 3},
604 }
605 ]
606 }
607 )
610def test_path_param_lt_2(): 1abcde
611 response = client.get("/path/param-lt/2") 1abcde
612 assert response.status_code == 200 1abcde
613 assert response.json() == 2 1abcde
616def test_path_param_lt0__1(): 1abcde
617 response = client.get("/path/param-lt0/-1") 1abcde
618 assert response.status_code == 200 1abcde
619 assert response.json() == -1 1abcde
622def test_path_param_lt0_0(): 1abcde
623 response = client.get("/path/param-lt0/0") 1abcde
624 assert response.status_code == 422 1abcde
625 assert response.json() == IsDict( 1abcde
626 {
627 "detail": [
628 {
629 "type": "less_than",
630 "loc": ["path", "item_id"],
631 "msg": "Input should be less than 0",
632 "input": "0",
633 "ctx": {"lt": 0.0},
634 }
635 ]
636 }
637 ) | IsDict(
638 # TODO: remove when deprecating Pydantic v1
639 {
640 "detail": [
641 {
642 "loc": ["path", "item_id"],
643 "msg": "ensure this value is less than 0",
644 "type": "value_error.number.not_lt",
645 "ctx": {"limit_value": 0},
646 }
647 ]
648 }
649 )
652def test_path_param_le_42(): 1abcde
653 response = client.get("/path/param-le/42") 1abcde
654 assert response.status_code == 422 1abcde
655 assert response.json() == IsDict( 1abcde
656 {
657 "detail": [
658 {
659 "type": "less_than_equal",
660 "loc": ["path", "item_id"],
661 "msg": "Input should be less than or equal to 3",
662 "input": "42",
663 "ctx": {"le": 3.0},
664 }
665 ]
666 }
667 ) | IsDict(
668 # TODO: remove when deprecating Pydantic v1
669 {
670 "detail": [
671 {
672 "loc": ["path", "item_id"],
673 "msg": "ensure this value is less than or equal to 3",
674 "type": "value_error.number.not_le",
675 "ctx": {"limit_value": 3},
676 }
677 ]
678 }
679 )
682def test_path_param_le_3(): 1abcde
683 response = client.get("/path/param-le/3") 1abcde
684 assert response.status_code == 200 1abcde
685 assert response.json() == 3 1abcde
688def test_path_param_le_2(): 1abcde
689 response = client.get("/path/param-le/2") 1abcde
690 assert response.status_code == 200 1abcde
691 assert response.json() == 2 1abcde
694def test_path_param_lt_gt_2(): 1abcde
695 response = client.get("/path/param-lt-gt/2") 1abcde
696 assert response.status_code == 200 1abcde
697 assert response.json() == 2 1abcde
700def test_path_param_lt_gt_4(): 1abcde
701 response = client.get("/path/param-lt-gt/4") 1abcde
702 assert response.status_code == 422 1abcde
703 assert response.json() == IsDict( 1abcde
704 {
705 "detail": [
706 {
707 "type": "less_than",
708 "loc": ["path", "item_id"],
709 "msg": "Input should be less than 3",
710 "input": "4",
711 "ctx": {"lt": 3.0},
712 }
713 ]
714 }
715 ) | IsDict(
716 # TODO: remove when deprecating Pydantic v1
717 {
718 "detail": [
719 {
720 "loc": ["path", "item_id"],
721 "msg": "ensure this value is less than 3",
722 "type": "value_error.number.not_lt",
723 "ctx": {"limit_value": 3},
724 }
725 ]
726 }
727 )
730def test_path_param_lt_gt_0(): 1abcde
731 response = client.get("/path/param-lt-gt/0") 1abcde
732 assert response.status_code == 422 1abcde
733 assert response.json() == IsDict( 1abcde
734 {
735 "detail": [
736 {
737 "type": "greater_than",
738 "loc": ["path", "item_id"],
739 "msg": "Input should be greater than 1",
740 "input": "0",
741 "ctx": {"gt": 1.0},
742 }
743 ]
744 }
745 ) | IsDict(
746 # TODO: remove when deprecating Pydantic v1
747 {
748 "detail": [
749 {
750 "loc": ["path", "item_id"],
751 "msg": "ensure this value is greater than 1",
752 "type": "value_error.number.not_gt",
753 "ctx": {"limit_value": 1},
754 }
755 ]
756 }
757 )
760def test_path_param_le_ge_2(): 1abcde
761 response = client.get("/path/param-le-ge/2") 1abcde
762 assert response.status_code == 200 1abcde
763 assert response.json() == 2 1abcde
766def test_path_param_le_ge_1(): 1abcde
767 response = client.get("/path/param-le-ge/1") 1abcde
768 assert response.status_code == 200 1abcde
771def test_path_param_le_ge_3(): 1abcde
772 response = client.get("/path/param-le-ge/3") 1abcde
773 assert response.status_code == 200 1abcde
774 assert response.json() == 3 1abcde
777def test_path_param_le_ge_4(): 1abcde
778 response = client.get("/path/param-le-ge/4") 1abcde
779 assert response.status_code == 422 1abcde
780 assert response.json() == IsDict( 1abcde
781 {
782 "detail": [
783 {
784 "type": "less_than_equal",
785 "loc": ["path", "item_id"],
786 "msg": "Input should be less than or equal to 3",
787 "input": "4",
788 "ctx": {"le": 3.0},
789 }
790 ]
791 }
792 ) | IsDict(
793 # TODO: remove when deprecating Pydantic v1
794 {
795 "detail": [
796 {
797 "loc": ["path", "item_id"],
798 "msg": "ensure this value is less than or equal to 3",
799 "type": "value_error.number.not_le",
800 "ctx": {"limit_value": 3},
801 }
802 ]
803 }
804 )
807def test_path_param_lt_int_2(): 1abcde
808 response = client.get("/path/param-lt-int/2") 1abcde
809 assert response.status_code == 200 1abcde
810 assert response.json() == 2 1abcde
813def test_path_param_lt_int_42(): 1abcde
814 response = client.get("/path/param-lt-int/42") 1abcde
815 assert response.status_code == 422 1abcde
816 assert response.json() == IsDict( 1abcde
817 {
818 "detail": [
819 {
820 "type": "less_than",
821 "loc": ["path", "item_id"],
822 "msg": "Input should be less than 3",
823 "input": "42",
824 "ctx": {"lt": 3},
825 }
826 ]
827 }
828 ) | IsDict(
829 # TODO: remove when deprecating Pydantic v1
830 {
831 "detail": [
832 {
833 "loc": ["path", "item_id"],
834 "msg": "ensure this value is less than 3",
835 "type": "value_error.number.not_lt",
836 "ctx": {"limit_value": 3},
837 }
838 ]
839 }
840 )
843def test_path_param_lt_int_2_7(): 1abcde
844 response = client.get("/path/param-lt-int/2.7") 1abcde
845 assert response.status_code == 422 1abcde
846 assert response.json() == IsDict( 1abcde
847 {
848 "detail": [
849 {
850 "type": "int_parsing",
851 "loc": ["path", "item_id"],
852 "msg": "Input should be a valid integer, unable to parse string as an integer",
853 "input": "2.7",
854 }
855 ]
856 }
857 ) | IsDict(
858 # TODO: remove when deprecating Pydantic v1
859 {
860 "detail": [
861 {
862 "loc": ["path", "item_id"],
863 "msg": "value is not a valid integer",
864 "type": "type_error.integer",
865 }
866 ]
867 }
868 )
871def test_path_param_gt_int_42(): 1abcde
872 response = client.get("/path/param-gt-int/42") 1abcde
873 assert response.status_code == 200 1abcde
874 assert response.json() == 42 1abcde
877def test_path_param_gt_int_2(): 1abcde
878 response = client.get("/path/param-gt-int/2") 1abcde
879 assert response.status_code == 422 1abcde
880 assert response.json() == IsDict( 1abcde
881 {
882 "detail": [
883 {
884 "type": "greater_than",
885 "loc": ["path", "item_id"],
886 "msg": "Input should be greater than 3",
887 "input": "2",
888 "ctx": {"gt": 3},
889 }
890 ]
891 }
892 ) | IsDict(
893 # TODO: remove when deprecating Pydantic v1
894 {
895 "detail": [
896 {
897 "loc": ["path", "item_id"],
898 "msg": "ensure this value is greater than 3",
899 "type": "value_error.number.not_gt",
900 "ctx": {"limit_value": 3},
901 }
902 ]
903 }
904 )
907def test_path_param_gt_int_2_7(): 1abcde
908 response = client.get("/path/param-gt-int/2.7") 1abcde
909 assert response.status_code == 422 1abcde
910 assert response.json() == IsDict( 1abcde
911 {
912 "detail": [
913 {
914 "type": "int_parsing",
915 "loc": ["path", "item_id"],
916 "msg": "Input should be a valid integer, unable to parse string as an integer",
917 "input": "2.7",
918 }
919 ]
920 }
921 ) | IsDict(
922 # TODO: remove when deprecating Pydantic v1
923 {
924 "detail": [
925 {
926 "loc": ["path", "item_id"],
927 "msg": "value is not a valid integer",
928 "type": "type_error.integer",
929 }
930 ]
931 }
932 )
935def test_path_param_le_int_42(): 1abcde
936 response = client.get("/path/param-le-int/42") 1abcde
937 assert response.status_code == 422 1abcde
938 assert response.json() == IsDict( 1abcde
939 {
940 "detail": [
941 {
942 "type": "less_than_equal",
943 "loc": ["path", "item_id"],
944 "msg": "Input should be less than or equal to 3",
945 "input": "42",
946 "ctx": {"le": 3},
947 }
948 ]
949 }
950 ) | IsDict(
951 # TODO: remove when deprecating Pydantic v1
952 {
953 "detail": [
954 {
955 "loc": ["path", "item_id"],
956 "msg": "ensure this value is less than or equal to 3",
957 "type": "value_error.number.not_le",
958 "ctx": {"limit_value": 3},
959 }
960 ]
961 }
962 )
965def test_path_param_le_int_3(): 1abcde
966 response = client.get("/path/param-le-int/3") 1abcde
967 assert response.status_code == 200 1abcde
968 assert response.json() == 3 1abcde
971def test_path_param_le_int_2(): 1abcde
972 response = client.get("/path/param-le-int/2") 1abcde
973 assert response.status_code == 200 1abcde
974 assert response.json() == 2 1abcde
977def test_path_param_le_int_2_7(): 1abcde
978 response = client.get("/path/param-le-int/2.7") 1abcde
979 assert response.status_code == 422 1abcde
980 assert response.json() == IsDict( 1abcde
981 {
982 "detail": [
983 {
984 "type": "int_parsing",
985 "loc": ["path", "item_id"],
986 "msg": "Input should be a valid integer, unable to parse string as an integer",
987 "input": "2.7",
988 }
989 ]
990 }
991 ) | IsDict(
992 # TODO: remove when deprecating Pydantic v1
993 {
994 "detail": [
995 {
996 "loc": ["path", "item_id"],
997 "msg": "value is not a valid integer",
998 "type": "type_error.integer",
999 }
1000 ]
1001 }
1002 )
1005def test_path_param_ge_int_42(): 1abcde
1006 response = client.get("/path/param-ge-int/42") 1abcde
1007 assert response.status_code == 200 1abcde
1008 assert response.json() == 42 1abcde
1011def test_path_param_ge_int_3(): 1abcde
1012 response = client.get("/path/param-ge-int/3") 1abcde
1013 assert response.status_code == 200 1abcde
1014 assert response.json() == 3 1abcde
1017def test_path_param_ge_int_2(): 1abcde
1018 response = client.get("/path/param-ge-int/2") 1abcde
1019 assert response.status_code == 422 1abcde
1020 assert response.json() == IsDict( 1abcde
1021 {
1022 "detail": [
1023 {
1024 "type": "greater_than_equal",
1025 "loc": ["path", "item_id"],
1026 "msg": "Input should be greater than or equal to 3",
1027 "input": "2",
1028 "ctx": {"ge": 3},
1029 }
1030 ]
1031 }
1032 ) | IsDict(
1033 # TODO: remove when deprecating Pydantic v1
1034 {
1035 "detail": [
1036 {
1037 "loc": ["path", "item_id"],
1038 "msg": "ensure this value is greater than or equal to 3",
1039 "type": "value_error.number.not_ge",
1040 "ctx": {"limit_value": 3},
1041 }
1042 ]
1043 }
1044 )
1047def test_path_param_ge_int_2_7(): 1abcde
1048 response = client.get("/path/param-ge-int/2.7") 1abcde
1049 assert response.status_code == 422 1abcde
1050 assert response.json() == IsDict( 1abcde
1051 {
1052 "detail": [
1053 {
1054 "type": "int_parsing",
1055 "loc": ["path", "item_id"],
1056 "msg": "Input should be a valid integer, unable to parse string as an integer",
1057 "input": "2.7",
1058 }
1059 ]
1060 }
1061 ) | IsDict(
1062 # TODO: remove when deprecating Pydantic v1
1063 {
1064 "detail": [
1065 {
1066 "loc": ["path", "item_id"],
1067 "msg": "value is not a valid integer",
1068 "type": "type_error.integer",
1069 }
1070 ]
1071 }
1072 )
1075def test_path_param_lt_gt_int_2(): 1abcde
1076 response = client.get("/path/param-lt-gt-int/2") 1abcde
1077 assert response.status_code == 200 1abcde
1078 assert response.json() == 2 1abcde
1081def test_path_param_lt_gt_int_4(): 1abcde
1082 response = client.get("/path/param-lt-gt-int/4") 1abcde
1083 assert response.status_code == 422 1abcde
1084 assert response.json() == IsDict( 1abcde
1085 {
1086 "detail": [
1087 {
1088 "type": "less_than",
1089 "loc": ["path", "item_id"],
1090 "msg": "Input should be less than 3",
1091 "input": "4",
1092 "ctx": {"lt": 3},
1093 }
1094 ]
1095 }
1096 ) | IsDict(
1097 # TODO: remove when deprecating Pydantic v1
1098 {
1099 "detail": [
1100 {
1101 "loc": ["path", "item_id"],
1102 "msg": "ensure this value is less than 3",
1103 "type": "value_error.number.not_lt",
1104 "ctx": {"limit_value": 3},
1105 }
1106 ]
1107 }
1108 )
1111def test_path_param_lt_gt_int_0(): 1abcde
1112 response = client.get("/path/param-lt-gt-int/0") 1abcde
1113 assert response.status_code == 422 1abcde
1114 assert response.json() == IsDict( 1abcde
1115 {
1116 "detail": [
1117 {
1118 "type": "greater_than",
1119 "loc": ["path", "item_id"],
1120 "msg": "Input should be greater than 1",
1121 "input": "0",
1122 "ctx": {"gt": 1},
1123 }
1124 ]
1125 }
1126 ) | IsDict(
1127 # TODO: remove when deprecating Pydantic v1
1128 {
1129 "detail": [
1130 {
1131 "loc": ["path", "item_id"],
1132 "msg": "ensure this value is greater than 1",
1133 "type": "value_error.number.not_gt",
1134 "ctx": {"limit_value": 1},
1135 }
1136 ]
1137 }
1138 )
1141def test_path_param_lt_gt_int_2_7(): 1abcde
1142 response = client.get("/path/param-lt-gt-int/2.7") 1abcde
1143 assert response.status_code == 422 1abcde
1144 assert response.json() == IsDict( 1abcde
1145 {
1146 "detail": [
1147 {
1148 "type": "int_parsing",
1149 "loc": ["path", "item_id"],
1150 "msg": "Input should be a valid integer, unable to parse string as an integer",
1151 "input": "2.7",
1152 }
1153 ]
1154 }
1155 ) | IsDict(
1156 # TODO: remove when deprecating Pydantic v1
1157 {
1158 "detail": [
1159 {
1160 "loc": ["path", "item_id"],
1161 "msg": "value is not a valid integer",
1162 "type": "type_error.integer",
1163 }
1164 ]
1165 }
1166 )
1169def test_path_param_le_ge_int_2(): 1abcde
1170 response = client.get("/path/param-le-ge-int/2") 1abcde
1171 assert response.status_code == 200 1abcde
1172 assert response.json() == 2 1abcde
1175def test_path_param_le_ge_int_1(): 1abcde
1176 response = client.get("/path/param-le-ge-int/1") 1abcde
1177 assert response.status_code == 200 1abcde
1178 assert response.json() == 1 1abcde
1181def test_path_param_le_ge_int_3(): 1abcde
1182 response = client.get("/path/param-le-ge-int/3") 1abcde
1183 assert response.status_code == 200 1abcde
1184 assert response.json() == 3 1abcde
1187def test_path_param_le_ge_int_4(): 1abcde
1188 response = client.get("/path/param-le-ge-int/4") 1abcde
1189 assert response.status_code == 422 1abcde
1190 assert response.json() == IsDict( 1abcde
1191 {
1192 "detail": [
1193 {
1194 "type": "less_than_equal",
1195 "loc": ["path", "item_id"],
1196 "msg": "Input should be less than or equal to 3",
1197 "input": "4",
1198 "ctx": {"le": 3},
1199 }
1200 ]
1201 }
1202 ) | IsDict(
1203 # TODO: remove when deprecating Pydantic v1
1204 {
1205 "detail": [
1206 {
1207 "loc": ["path", "item_id"],
1208 "msg": "ensure this value is less than or equal to 3",
1209 "type": "value_error.number.not_le",
1210 "ctx": {"limit_value": 3},
1211 }
1212 ]
1213 }
1214 )
1217def test_path_param_le_ge_int_2_7(): 1abcde
1218 response = client.get("/path/param-le-ge-int/2.7") 1abcde
1219 assert response.status_code == 422 1abcde
1220 assert response.json() == IsDict( 1abcde
1221 {
1222 "detail": [
1223 {
1224 "type": "int_parsing",
1225 "loc": ["path", "item_id"],
1226 "msg": "Input should be a valid integer, unable to parse string as an integer",
1227 "input": "2.7",
1228 }
1229 ]
1230 }
1231 ) | IsDict(
1232 # TODO: remove when deprecating Pydantic v1
1233 {
1234 "detail": [
1235 {
1236 "loc": ["path", "item_id"],
1237 "msg": "value is not a valid integer",
1238 "type": "type_error.integer",
1239 }
1240 ]
1241 }
1242 )