| 1 |
from fastapi.testclient import TestClient |
| 2 |
|
| 3 |
from .main import app |
| 4 |
|
| 5 |
client = TestClient(app) |
| 6 |
|
| 7 |
|
| 8 |
def test_text_get(): |
| 9 |
response = client.get("/text") |
| 10 |
assert response.status_code == 200, response.text |
| 11 |
assert response.json() == "Hello World" |
| 12 |
|
| 13 |
|
| 14 |
def test_nonexistent(): |
| 15 |
response = client.get("/nonexistent") |
| 16 |
assert response.status_code == 404, response.text |
| 17 |
assert response.json() == {"detail": "Not Found"} |
| 18 |
|
| 19 |
|
| 20 |
def test_path_foobar(): |
| 21 |
response = client.get("/path/foobar") |
| 22 |
assert response.status_code == 200 |
| 23 |
assert response.json() == "foobar" |
| 24 |
|
| 25 |
|
| 26 |
def test_path_str_foobar(): |
| 27 |
response = client.get("/path/str/foobar") |
| 28 |
assert response.status_code == 200 |
| 29 |
assert response.json() == "foobar" |
| 30 |
|
| 31 |
|
| 32 |
def test_path_str_42(): |
| 33 |
response = client.get("/path/str/42") |
| 34 |
assert response.status_code == 200 |
| 35 |
assert response.json() == "42" |
| 36 |
|
| 37 |
|
| 38 |
def test_path_str_True(): |
| 39 |
response = client.get("/path/str/True") |
| 40 |
assert response.status_code == 200 |
| 41 |
assert response.json() == "True" |
| 42 |
|
| 43 |
|
| 44 |
def test_path_int_foobar(): |
| 45 |
response = client.get("/path/int/foobar") |
| 46 |
assert response.status_code == 422 |
| 47 |
assert response.json() == { |
| 48 |
"detail": [ |
| 49 |
{ |
| 50 |
"type": "int_parsing", |
| 51 |
"loc": ["path", "item_id"], |
| 52 |
"msg": "Input should be a valid integer, unable to parse string as an integer", |
| 53 |
"input": "foobar", |
| 54 |
} |
| 55 |
] |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
def test_path_int_True(): |
| 60 |
response = client.get("/path/int/True") |
| 61 |
assert response.status_code == 422 |
| 62 |
assert response.json() == { |
| 63 |
"detail": [ |
| 64 |
{ |
| 65 |
"type": "int_parsing", |
| 66 |
"loc": ["path", "item_id"], |
| 67 |
"msg": "Input should be a valid integer, unable to parse string as an integer", |
| 68 |
"input": "True", |
| 69 |
} |
| 70 |
] |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
def test_path_int_42(): |
| 75 |
response = client.get("/path/int/42") |
| 76 |
assert response.status_code == 200 |
| 77 |
assert response.json() == 42 |
| 78 |
|
| 79 |
|
| 80 |
def test_path_int_42_5(): |
| 81 |
response = client.get("/path/int/42.5") |
| 82 |
assert response.status_code == 422 |
| 83 |
assert response.json() == { |
| 84 |
"detail": [ |
| 85 |
{ |
| 86 |
"type": "int_parsing", |
| 87 |
"loc": ["path", "item_id"], |
| 88 |
"msg": "Input should be a valid integer, unable to parse string as an integer", |
| 89 |
"input": "42.5", |
| 90 |
} |
| 91 |
] |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
def test_path_float_foobar(): |
| 96 |
response = client.get("/path/float/foobar") |
| 97 |
assert response.status_code == 422 |
| 98 |
assert response.json() == { |
| 99 |
"detail": [ |
| 100 |
{ |
| 101 |
"type": "float_parsing", |
| 102 |
"loc": ["path", "item_id"], |
| 103 |
"msg": "Input should be a valid number, unable to parse string as a number", |
| 104 |
"input": "foobar", |
| 105 |
} |
| 106 |
] |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
def test_path_float_True(): |
| 111 |
response = client.get("/path/float/True") |
| 112 |
assert response.status_code == 422 |
| 113 |
assert response.json() == { |
| 114 |
"detail": [ |
| 115 |
{ |
| 116 |
"type": "float_parsing", |
| 117 |
"loc": ["path", "item_id"], |
| 118 |
"msg": "Input should be a valid number, unable to parse string as a number", |
| 119 |
"input": "True", |
| 120 |
} |
| 121 |
] |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
def test_path_float_42(): |
| 126 |
response = client.get("/path/float/42") |
| 127 |
assert response.status_code == 200 |
| 128 |
assert response.json() == 42 |
| 129 |
|
| 130 |
|
| 131 |
def test_path_float_42_5(): |
| 132 |
response = client.get("/path/float/42.5") |
| 133 |
assert response.status_code == 200 |
| 134 |
assert response.json() == 42.5 |
| 135 |
|
| 136 |
|
| 137 |
def test_path_bool_foobar(): |
| 138 |
response = client.get("/path/bool/foobar") |
| 139 |
assert response.status_code == 422 |
| 140 |
assert response.json() == { |
| 141 |
"detail": [ |
| 142 |
{ |
| 143 |
"type": "bool_parsing", |
| 144 |
"loc": ["path", "item_id"], |
| 145 |
"msg": "Input should be a valid boolean, unable to interpret input", |
| 146 |
"input": "foobar", |
| 147 |
} |
| 148 |
] |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
def test_path_bool_True(): |
| 153 |
response = client.get("/path/bool/True") |
| 154 |
assert response.status_code == 200 |
| 155 |
assert response.json() is True |
| 156 |
|
| 157 |
|
| 158 |
def test_path_bool_42(): |
| 159 |
response = client.get("/path/bool/42") |
| 160 |
assert response.status_code == 422 |
| 161 |
assert response.json() == { |
| 162 |
"detail": [ |
| 163 |
{ |
| 164 |
"type": "bool_parsing", |
| 165 |
"loc": ["path", "item_id"], |
| 166 |
"msg": "Input should be a valid boolean, unable to interpret input", |
| 167 |
"input": "42", |
| 168 |
} |
| 169 |
] |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
def test_path_bool_42_5(): |
| 174 |
response = client.get("/path/bool/42.5") |
| 175 |
assert response.status_code == 422 |
| 176 |
assert response.json() == { |
| 177 |
"detail": [ |
| 178 |
{ |
| 179 |
"type": "bool_parsing", |
| 180 |
"loc": ["path", "item_id"], |
| 181 |
"msg": "Input should be a valid boolean, unable to interpret input", |
| 182 |
"input": "42.5", |
| 183 |
} |
| 184 |
] |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
def test_path_bool_1(): |
| 189 |
response = client.get("/path/bool/1") |
| 190 |
assert response.status_code == 200 |
| 191 |
assert response.json() is True |
| 192 |
|
| 193 |
|
| 194 |
def test_path_bool_0(): |
| 195 |
response = client.get("/path/bool/0") |
| 196 |
assert response.status_code == 200 |
| 197 |
assert response.json() is False |
| 198 |
|
| 199 |
|
| 200 |
def test_path_bool_true(): |
| 201 |
response = client.get("/path/bool/true") |
| 202 |
assert response.status_code == 200 |
| 203 |
assert response.json() is True |
| 204 |
|
| 205 |
|
| 206 |
def test_path_bool_False(): |
| 207 |
response = client.get("/path/bool/False") |
| 208 |
assert response.status_code == 200 |
| 209 |
assert response.json() is False |
| 210 |
|
| 211 |
|
| 212 |
def test_path_bool_false(): |
| 213 |
response = client.get("/path/bool/false") |
| 214 |
assert response.status_code == 200 |
| 215 |
assert response.json() is False |
| 216 |
|
| 217 |
|
| 218 |
def test_path_param_foo(): |
| 219 |
response = client.get("/path/param/foo") |
| 220 |
assert response.status_code == 200 |
| 221 |
assert response.json() == "foo" |
| 222 |
|
| 223 |
|
| 224 |
def test_path_param_minlength_foo(): |
| 225 |
response = client.get("/path/param-minlength/foo") |
| 226 |
assert response.status_code == 200 |
| 227 |
assert response.json() == "foo" |
| 228 |
|
| 229 |
|
| 230 |
def test_path_param_minlength_fo(): |
| 231 |
response = client.get("/path/param-minlength/fo") |
| 232 |
assert response.status_code == 422 |
| 233 |
assert response.json() == { |
| 234 |
"detail": [ |
| 235 |
{ |
| 236 |
"type": "string_too_short", |
| 237 |
"loc": ["path", "item_id"], |
| 238 |
"msg": "String should have at least 3 characters", |
| 239 |
"input": "fo", |
| 240 |
"ctx": {"min_length": 3}, |
| 241 |
} |
| 242 |
] |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
def test_path_param_maxlength_foo(): |
| 247 |
response = client.get("/path/param-maxlength/foo") |
| 248 |
assert response.status_code == 200 |
| 249 |
assert response.json() == "foo" |
| 250 |
|
| 251 |
|
| 252 |
def test_path_param_maxlength_foobar(): |
| 253 |
response = client.get("/path/param-maxlength/foobar") |
| 254 |
assert response.status_code == 422 |
| 255 |
assert response.json() == { |
| 256 |
"detail": [ |
| 257 |
{ |
| 258 |
"type": "string_too_long", |
| 259 |
"loc": ["path", "item_id"], |
| 260 |
"msg": "String should have at most 3 characters", |
| 261 |
"input": "foobar", |
| 262 |
"ctx": {"max_length": 3}, |
| 263 |
} |
| 264 |
] |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
def test_path_param_min_maxlength_foo(): |
| 269 |
response = client.get("/path/param-min_maxlength/foo") |
| 270 |
assert response.status_code == 200 |
| 271 |
assert response.json() == "foo" |
| 272 |
|
| 273 |
|
| 274 |
def test_path_param_min_maxlength_foobar(): |
| 275 |
response = client.get("/path/param-min_maxlength/foobar") |
| 276 |
assert response.status_code == 422 |
| 277 |
assert response.json() == { |
| 278 |
"detail": [ |
| 279 |
{ |
| 280 |
"type": "string_too_long", |
| 281 |
"loc": ["path", "item_id"], |
| 282 |
"msg": "String should have at most 3 characters", |
| 283 |
"input": "foobar", |
| 284 |
"ctx": {"max_length": 3}, |
| 285 |
} |
| 286 |
] |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
def test_path_param_min_maxlength_f(): |
| 291 |
response = client.get("/path/param-min_maxlength/f") |
| 292 |
assert response.status_code == 422 |
| 293 |
assert response.json() == { |
| 294 |
"detail": [ |
| 295 |
{ |
| 296 |
"type": "string_too_short", |
| 297 |
"loc": ["path", "item_id"], |
| 298 |
"msg": "String should have at least 2 characters", |
| 299 |
"input": "f", |
| 300 |
"ctx": {"min_length": 2}, |
| 301 |
} |
| 302 |
] |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
def test_path_param_gt_42(): |
| 307 |
response = client.get("/path/param-gt/42") |
| 308 |
assert response.status_code == 200 |
| 309 |
assert response.json() == 42 |
| 310 |
|
| 311 |
|
| 312 |
def test_path_param_gt_2(): |
| 313 |
response = client.get("/path/param-gt/2") |
| 314 |
assert response.status_code == 422 |
| 315 |
assert response.json() == { |
| 316 |
"detail": [ |
| 317 |
{ |
| 318 |
"type": "greater_than", |
| 319 |
"loc": ["path", "item_id"], |
| 320 |
"msg": "Input should be greater than 3", |
| 321 |
"input": "2", |
| 322 |
"ctx": {"gt": 3.0}, |
| 323 |
} |
| 324 |
] |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
def test_path_param_gt0_0_05(): |
| 329 |
response = client.get("/path/param-gt0/0.05") |
| 330 |
assert response.status_code == 200 |
| 331 |
assert response.json() == 0.05 |
| 332 |
|
| 333 |
|
| 334 |
def test_path_param_gt0_0(): |
| 335 |
response = client.get("/path/param-gt0/0") |
| 336 |
assert response.status_code == 422 |
| 337 |
assert response.json() == { |
| 338 |
"detail": [ |
| 339 |
{ |
| 340 |
"type": "greater_than", |
| 341 |
"loc": ["path", "item_id"], |
| 342 |
"msg": "Input should be greater than 0", |
| 343 |
"input": "0", |
| 344 |
"ctx": {"gt": 0.0}, |
| 345 |
} |
| 346 |
] |
| 347 |
} |
| 348 |
|
| 349 |
|
| 350 |
def test_path_param_ge_42(): |
| 351 |
response = client.get("/path/param-ge/42") |
| 352 |
assert response.status_code == 200 |
| 353 |
assert response.json() == 42 |
| 354 |
|
| 355 |
|
| 356 |
def test_path_param_ge_3(): |
| 357 |
response = client.get("/path/param-ge/3") |
| 358 |
assert response.status_code == 200 |
| 359 |
assert response.json() == 3 |
| 360 |
|
| 361 |
|
| 362 |
def test_path_param_ge_2(): |
| 363 |
response = client.get("/path/param-ge/2") |
| 364 |
assert response.status_code == 422 |
| 365 |
assert response.json() == { |
| 366 |
"detail": [ |
| 367 |
{ |
| 368 |
"type": "greater_than_equal", |
| 369 |
"loc": ["path", "item_id"], |
| 370 |
"msg": "Input should be greater than or equal to 3", |
| 371 |
"input": "2", |
| 372 |
"ctx": {"ge": 3.0}, |
| 373 |
} |
| 374 |
] |
| 375 |
} |
| 376 |
|
| 377 |
|
| 378 |
def test_path_param_lt_42(): |
| 379 |
response = client.get("/path/param-lt/42") |
| 380 |
assert response.status_code == 422 |
| 381 |
assert response.json() == { |
| 382 |
"detail": [ |
| 383 |
{ |
| 384 |
"type": "less_than", |
| 385 |
"loc": ["path", "item_id"], |
| 386 |
"msg": "Input should be less than 3", |
| 387 |
"input": "42", |
| 388 |
"ctx": {"lt": 3.0}, |
| 389 |
} |
| 390 |
] |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
def test_path_param_lt_2(): |
| 395 |
response = client.get("/path/param-lt/2") |
| 396 |
assert response.status_code == 200 |
| 397 |
assert response.json() == 2 |
| 398 |
|
| 399 |
|
| 400 |
def test_path_param_lt0__1(): |
| 401 |
response = client.get("/path/param-lt0/-1") |
| 402 |
assert response.status_code == 200 |
| 403 |
assert response.json() == -1 |
| 404 |
|
| 405 |
|
| 406 |
def test_path_param_lt0_0(): |
| 407 |
response = client.get("/path/param-lt0/0") |
| 408 |
assert response.status_code == 422 |
| 409 |
assert response.json() == { |
| 410 |
"detail": [ |
| 411 |
{ |
| 412 |
"type": "less_than", |
| 413 |
"loc": ["path", "item_id"], |
| 414 |
"msg": "Input should be less than 0", |
| 415 |
"input": "0", |
| 416 |
"ctx": {"lt": 0.0}, |
| 417 |
} |
| 418 |
] |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
def test_path_param_le_42(): |
| 423 |
response = client.get("/path/param-le/42") |
| 424 |
assert response.status_code == 422 |
| 425 |
assert response.json() == { |
| 426 |
"detail": [ |
| 427 |
{ |
| 428 |
"type": "less_than_equal", |
| 429 |
"loc": ["path", "item_id"], |
| 430 |
"msg": "Input should be less than or equal to 3", |
| 431 |
"input": "42", |
| 432 |
"ctx": {"le": 3.0}, |
| 433 |
} |
| 434 |
] |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
def test_path_param_le_3(): |
| 439 |
response = client.get("/path/param-le/3") |
| 440 |
assert response.status_code == 200 |
| 441 |
assert response.json() == 3 |
| 442 |
|
| 443 |
|
| 444 |
def test_path_param_le_2(): |
| 445 |
response = client.get("/path/param-le/2") |
| 446 |
assert response.status_code == 200 |
| 447 |
assert response.json() == 2 |
| 448 |
|
| 449 |
|
| 450 |
def test_path_param_lt_gt_2(): |
| 451 |
response = client.get("/path/param-lt-gt/2") |
| 452 |
assert response.status_code == 200 |
| 453 |
assert response.json() == 2 |
| 454 |
|
| 455 |
|
| 456 |
def test_path_param_lt_gt_4(): |
| 457 |
response = client.get("/path/param-lt-gt/4") |
| 458 |
assert response.status_code == 422 |
| 459 |
assert response.json() == { |
| 460 |
"detail": [ |
| 461 |
{ |
| 462 |
"type": "less_than", |
| 463 |
"loc": ["path", "item_id"], |
| 464 |
"msg": "Input should be less than 3", |
| 465 |
"input": "4", |
| 466 |
"ctx": {"lt": 3.0}, |
| 467 |
} |
| 468 |
] |
| 469 |
} |
| 470 |
|
| 471 |
|
| 472 |
def test_path_param_lt_gt_0(): |
| 473 |
response = client.get("/path/param-lt-gt/0") |
| 474 |
assert response.status_code == 422 |
| 475 |
assert response.json() == { |
| 476 |
"detail": [ |
| 477 |
{ |
| 478 |
"type": "greater_than", |
| 479 |
"loc": ["path", "item_id"], |
| 480 |
"msg": "Input should be greater than 1", |
| 481 |
"input": "0", |
| 482 |
"ctx": {"gt": 1.0}, |
| 483 |
} |
| 484 |
] |
| 485 |
} |
| 486 |
|
| 487 |
|
| 488 |
def test_path_param_le_ge_2(): |
| 489 |
response = client.get("/path/param-le-ge/2") |
| 490 |
assert response.status_code == 200 |
| 491 |
assert response.json() == 2 |
| 492 |
|
| 493 |
|
| 494 |
def test_path_param_le_ge_1(): |
| 495 |
response = client.get("/path/param-le-ge/1") |
| 496 |
assert response.status_code == 200 |
| 497 |
|
| 498 |
|
| 499 |
def test_path_param_le_ge_3(): |
| 500 |
response = client.get("/path/param-le-ge/3") |
| 501 |
assert response.status_code == 200 |
| 502 |
assert response.json() == 3 |
| 503 |
|
| 504 |
|
| 505 |
def test_path_param_le_ge_4(): |
| 506 |
response = client.get("/path/param-le-ge/4") |
| 507 |
assert response.status_code == 422 |
| 508 |
assert response.json() == { |
| 509 |
"detail": [ |
| 510 |
{ |
| 511 |
"type": "less_than_equal", |
| 512 |
"loc": ["path", "item_id"], |
| 513 |
"msg": "Input should be less than or equal to 3", |
| 514 |
"input": "4", |
| 515 |
"ctx": {"le": 3.0}, |
| 516 |
} |
| 517 |
] |
| 518 |
} |
| 519 |
|
| 520 |
|
| 521 |
def test_path_param_lt_int_2(): |
| 522 |
response = client.get("/path/param-lt-int/2") |
| 523 |
assert response.status_code == 200 |
| 524 |
assert response.json() == 2 |
| 525 |
|
| 526 |
|
| 527 |
def test_path_param_lt_int_42(): |
| 528 |
response = client.get("/path/param-lt-int/42") |
| 529 |
assert response.status_code == 422 |
| 530 |
assert response.json() == { |
| 531 |
"detail": [ |
| 532 |
{ |
| 533 |
"type": "less_than", |
| 534 |
"loc": ["path", "item_id"], |
| 535 |
"msg": "Input should be less than 3", |
| 536 |
"input": "42", |
| 537 |
"ctx": {"lt": 3}, |
| 538 |
} |
| 539 |
] |
| 540 |
} |
| 541 |
|
| 542 |
|
| 543 |
def test_path_param_lt_int_2_7(): |
| 544 |
response = client.get("/path/param-lt-int/2.7") |
| 545 |
assert response.status_code == 422 |
| 546 |
assert response.json() == { |
| 547 |
"detail": [ |
| 548 |
{ |
| 549 |
"type": "int_parsing", |
| 550 |
"loc": ["path", "item_id"], |
| 551 |
"msg": "Input should be a valid integer, unable to parse string as an integer", |
| 552 |
"input": "2.7", |
| 553 |
} |
| 554 |
] |
| 555 |
} |
| 556 |
|
| 557 |
|
| 558 |
def test_path_param_gt_int_42(): |
| 559 |
response = client.get("/path/param-gt-int/42") |
| 560 |
assert response.status_code == 200 |
| 561 |
assert response.json() == 42 |
| 562 |
|
| 563 |
|
| 564 |
def test_path_param_gt_int_2(): |
| 565 |
response = client.get("/path/param-gt-int/2") |
| 566 |
assert response.status_code == 422 |
| 567 |
assert response.json() == { |
| 568 |
"detail": [ |
| 569 |
{ |
| 570 |
"type": "greater_than", |
| 571 |
"loc": ["path", "item_id"], |
| 572 |
"msg": "Input should be greater than 3", |
| 573 |
"input": "2", |
| 574 |
"ctx": {"gt": 3}, |
| 575 |
} |
| 576 |
] |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
def test_path_param_gt_int_2_7(): |
| 581 |
response = client.get("/path/param-gt-int/2.7") |
| 582 |
assert response.status_code == 422 |
| 583 |
assert response.json() == { |
| 584 |
"detail": [ |
| 585 |
{ |
| 586 |
"type": "int_parsing", |
| 587 |
"loc": ["path", "item_id"], |
| 588 |
"msg": "Input should be a valid integer, unable to parse string as an integer", |
| 589 |
"input": "2.7", |
| 590 |
} |
| 591 |
] |
| 592 |
} |
| 593 |
|
| 594 |
|
| 595 |
def test_path_param_le_int_42(): |
| 596 |
response = client.get("/path/param-le-int/42") |
| 597 |
assert response.status_code == 422 |
| 598 |
assert response.json() == { |
| 599 |
"detail": [ |
| 600 |
{ |
| 601 |
"type": "less_than_equal", |
| 602 |
"loc": ["path", "item_id"], |
| 603 |
"msg": "Input should be less than or equal to 3", |
| 604 |
"input": "42", |
| 605 |
"ctx": {"le": 3}, |
| 606 |
} |
| 607 |
] |
| 608 |
} |
| 609 |
|
| 610 |
|
| 611 |
def test_path_param_le_int_3(): |
| 612 |
response = client.get("/path/param-le-int/3") |
| 613 |
assert response.status_code == 200 |
| 614 |
assert response.json() == 3 |
| 615 |
|
| 616 |
|
| 617 |
def test_path_param_le_int_2(): |
| 618 |
response = client.get("/path/param-le-int/2") |
| 619 |
assert response.status_code == 200 |
| 620 |
assert response.json() == 2 |
| 621 |
|
| 622 |
|
| 623 |
def test_path_param_le_int_2_7(): |
| 624 |
response = client.get("/path/param-le-int/2.7") |
| 625 |
assert response.status_code == 422 |
| 626 |
assert response.json() == { |
| 627 |
"detail": [ |
| 628 |
{ |
| 629 |
"type": "int_parsing", |
| 630 |
"loc": ["path", "item_id"], |
| 631 |
"msg": "Input should be a valid integer, unable to parse string as an integer", |
| 632 |
"input": "2.7", |
| 633 |
} |
| 634 |
] |
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
def test_path_param_ge_int_42(): |
| 639 |
response = client.get("/path/param-ge-int/42") |
| 640 |
assert response.status_code == 200 |
| 641 |
assert response.json() == 42 |
| 642 |
|
| 643 |
|
| 644 |
def test_path_param_ge_int_3(): |
| 645 |
response = client.get("/path/param-ge-int/3") |
| 646 |
assert response.status_code == 200 |
| 647 |
assert response.json() == 3 |
| 648 |
|
| 649 |
|
| 650 |
def test_path_param_ge_int_2(): |
| 651 |
response = client.get("/path/param-ge-int/2") |
| 652 |
assert response.status_code == 422 |
| 653 |
assert response.json() == { |
| 654 |
"detail": [ |
| 655 |
{ |
| 656 |
"type": "greater_than_equal", |
| 657 |
"loc": ["path", "item_id"], |
| 658 |
"msg": "Input should be greater than or equal to 3", |
| 659 |
"input": "2", |
| 660 |
"ctx": {"ge": 3}, |
| 661 |
} |
| 662 |
] |
| 663 |
} |
| 664 |
|
| 665 |
|
| 666 |
def test_path_param_ge_int_2_7(): |
| 667 |
response = client.get("/path/param-ge-int/2.7") |
| 668 |
assert response.status_code == 422 |
| 669 |
assert response.json() == { |
| 670 |
"detail": [ |
| 671 |
{ |
| 672 |
"type": "int_parsing", |
| 673 |
"loc": ["path", "item_id"], |
| 674 |
"msg": "Input should be a valid integer, unable to parse string as an integer", |
| 675 |
"input": "2.7", |
| 676 |
} |
| 677 |
] |
| 678 |
} |
| 679 |
|
| 680 |
|
| 681 |
def test_path_param_lt_gt_int_2(): |
| 682 |
response = client.get("/path/param-lt-gt-int/2") |
| 683 |
assert response.status_code == 200 |
| 684 |
assert response.json() == 2 |
| 685 |
|
| 686 |
|
| 687 |
def test_path_param_lt_gt_int_4(): |
| 688 |
response = client.get("/path/param-lt-gt-int/4") |
| 689 |
assert response.status_code == 422 |
| 690 |
assert response.json() == { |
| 691 |
"detail": [ |
| 692 |
{ |
| 693 |
"type": "less_than", |
| 694 |
"loc": ["path", "item_id"], |
| 695 |
"msg": "Input should be less than 3", |
| 696 |
"input": "4", |
| 697 |
"ctx": {"lt": 3}, |
| 698 |
} |
| 699 |
] |
| 700 |
} |
| 701 |
|
| 702 |
|
| 703 |
def test_path_param_lt_gt_int_0(): |
| 704 |
response = client.get("/path/param-lt-gt-int/0") |
| 705 |
assert response.status_code == 422 |
| 706 |
assert response.json() == { |
| 707 |
"detail": [ |
| 708 |
{ |
| 709 |
"type": "greater_than", |
| 710 |
"loc": ["path", "item_id"], |
| 711 |
"msg": "Input should be greater than 1", |
| 712 |
"input": "0", |
| 713 |
"ctx": {"gt": 1}, |
| 714 |
} |
| 715 |
] |
| 716 |
} |
| 717 |
|
| 718 |
|
| 719 |
def test_path_param_lt_gt_int_2_7(): |
| 720 |
response = client.get("/path/param-lt-gt-int/2.7") |
| 721 |
assert response.status_code == 422 |
| 722 |
assert response.json() == { |
| 723 |
"detail": [ |
| 724 |
{ |
| 725 |
"type": "int_parsing", |
| 726 |
"loc": ["path", "item_id"], |
| 727 |
"msg": "Input should be a valid integer, unable to parse string as an integer", |
| 728 |
"input": "2.7", |
| 729 |
} |
| 730 |
] |
| 731 |
} |
| 732 |
|
| 733 |
|
| 734 |
def test_path_param_le_ge_int_2(): |
| 735 |
response = client.get("/path/param-le-ge-int/2") |
| 736 |
assert response.status_code == 200 |
| 737 |
assert response.json() == 2 |
| 738 |
|
| 739 |
|
| 740 |
def test_path_param_le_ge_int_1(): |
| 741 |
response = client.get("/path/param-le-ge-int/1") |
| 742 |
assert response.status_code == 200 |
| 743 |
assert response.json() == 1 |
| 744 |
|
| 745 |
|
| 746 |
def test_path_param_le_ge_int_3(): |
| 747 |
response = client.get("/path/param-le-ge-int/3") |
| 748 |
assert response.status_code == 200 |
| 749 |
assert response.json() == 3 |
| 750 |
|
| 751 |
|
| 752 |
def test_path_param_le_ge_int_4(): |
| 753 |
response = client.get("/path/param-le-ge-int/4") |
| 754 |
assert response.status_code == 422 |
| 755 |
assert response.json() == { |
| 756 |
"detail": [ |
| 757 |
{ |
| 758 |
"type": "less_than_equal", |
| 759 |
"loc": ["path", "item_id"], |
| 760 |
"msg": "Input should be less than or equal to 3", |
| 761 |
"input": "4", |
| 762 |
"ctx": {"le": 3}, |
| 763 |
} |
| 764 |
] |
| 765 |
} |
| 766 |
|
| 767 |
|
| 768 |
def test_path_param_le_ge_int_2_7(): |
| 769 |
response = client.get("/path/param-le-ge-int/2.7") |
| 770 |
assert response.status_code == 422 |
| 771 |
assert response.json() == { |
| 772 |
"detail": [ |
| 773 |
{ |
| 774 |
"type": "int_parsing", |
| 775 |
"loc": ["path", "item_id"], |
| 776 |
"msg": "Input should be a valid integer, unable to parse string as an integer", |
| 777 |
"input": "2.7", |
| 778 |
} |
| 779 |
] |
| 780 |
} |