@@ -397,15 +397,29 @@ def test_post_birds(self, spec, spec_dict):
397
397
}
398
398
}
399
399
data = json .dumps (data_json )
400
+ headers = {
401
+ 'api_key' : '12345' ,
402
+ }
403
+ cookies = {
404
+ 'user' : '123' ,
405
+ }
400
406
401
407
request = MockRequest (
402
408
host_url , 'POST' , '/pets' ,
403
409
path_pattern = path_pattern , data = data ,
410
+ headers = headers , cookies = cookies ,
404
411
)
405
412
406
413
parameters = request .get_parameters (spec )
407
414
408
- assert parameters == {}
415
+ assert parameters == {
416
+ 'header' : {
417
+ 'api_key' : 12345 ,
418
+ },
419
+ 'cookie' : {
420
+ 'user' : 123 ,
421
+ },
422
+ }
409
423
410
424
body = request .get_body (spec )
411
425
@@ -443,15 +457,29 @@ def test_post_cats(self, spec, spec_dict):
443
457
}
444
458
}
445
459
data = json .dumps (data_json )
460
+ headers = {
461
+ 'api_key' : '12345' ,
462
+ }
463
+ cookies = {
464
+ 'user' : '123' ,
465
+ }
446
466
447
467
request = MockRequest (
448
468
host_url , 'POST' , '/pets' ,
449
469
path_pattern = path_pattern , data = data ,
470
+ headers = headers , cookies = cookies ,
450
471
)
451
472
452
473
parameters = request .get_parameters (spec )
453
474
454
- assert parameters == {}
475
+ assert parameters == {
476
+ 'header' : {
477
+ 'api_key' : 12345 ,
478
+ },
479
+ 'cookie' : {
480
+ 'user' : 123 ,
481
+ },
482
+ }
455
483
456
484
body = request .get_body (spec )
457
485
@@ -489,15 +517,29 @@ def test_post_cats_boolean_string(self, spec, spec_dict):
489
517
}
490
518
}
491
519
data = json .dumps (data_json )
520
+ headers = {
521
+ 'api_key' : '12345' ,
522
+ }
523
+ cookies = {
524
+ 'user' : '123' ,
525
+ }
492
526
493
527
request = MockRequest (
494
528
host_url , 'POST' , '/pets' ,
495
529
path_pattern = path_pattern , data = data ,
530
+ headers = headers , cookies = cookies ,
496
531
)
497
532
498
533
parameters = request .get_parameters (spec )
499
534
500
- assert parameters == {}
535
+ assert parameters == {
536
+ 'header' : {
537
+ 'api_key' : 12345 ,
538
+ },
539
+ 'cookie' : {
540
+ 'user' : 123 ,
541
+ },
542
+ }
501
543
502
544
body = request .get_body (spec )
503
545
@@ -523,15 +565,29 @@ def test_post_no_one_of_schema(self, spec, spec_dict):
523
565
'alias' : alias ,
524
566
}
525
567
data = json .dumps (data_json )
568
+ headers = {
569
+ 'api_key' : '12345' ,
570
+ }
571
+ cookies = {
572
+ 'user' : '123' ,
573
+ }
526
574
527
575
request = MockRequest (
528
576
host_url , 'POST' , '/pets' ,
529
577
path_pattern = path_pattern , data = data ,
578
+ headers = headers , cookies = cookies ,
530
579
)
531
580
532
581
parameters = request .get_parameters (spec )
533
582
534
- assert parameters == {}
583
+ assert parameters == {
584
+ 'header' : {
585
+ 'api_key' : 12345 ,
586
+ },
587
+ 'cookie' : {
588
+ 'user' : 123 ,
589
+ },
590
+ }
535
591
536
592
with pytest .raises (NoOneOfSchema ):
537
593
request .get_body (spec )
@@ -548,15 +604,29 @@ def test_post_cats_only_required_body(self, spec, spec_dict):
548
604
}
549
605
}
550
606
data = json .dumps (data_json )
607
+ headers = {
608
+ 'api_key' : '12345' ,
609
+ }
610
+ cookies = {
611
+ 'user' : '123' ,
612
+ }
551
613
552
614
request = MockRequest (
553
615
host_url , 'POST' , '/pets' ,
554
616
path_pattern = path_pattern , data = data ,
617
+ headers = headers , cookies = cookies ,
555
618
)
556
619
557
620
parameters = request .get_parameters (spec )
558
621
559
- assert parameters == {}
622
+ assert parameters == {
623
+ 'header' : {
624
+ 'api_key' : 12345 ,
625
+ },
626
+ 'cookie' : {
627
+ 'user' : 123 ,
628
+ },
629
+ }
560
630
561
631
body = request .get_body (spec )
562
632
@@ -575,19 +645,101 @@ def test_post_pets_raises_invalid_mimetype(self, spec):
575
645
'tag' : 'cats' ,
576
646
}
577
647
data = json .dumps (data_json )
648
+ headers = {
649
+ 'api_key' : '12345' ,
650
+ }
651
+ cookies = {
652
+ 'user' : '123' ,
653
+ }
578
654
579
655
request = MockRequest (
580
656
host_url , 'POST' , '/pets' ,
581
657
path_pattern = path_pattern , data = data , mimetype = 'text/html' ,
658
+ headers = headers , cookies = cookies ,
582
659
)
583
660
584
661
parameters = request .get_parameters (spec )
585
662
586
- assert parameters == {}
663
+ assert parameters == {
664
+ 'header' : {
665
+ 'api_key' : 12345 ,
666
+ },
667
+ 'cookie' : {
668
+ 'user' : 123 ,
669
+ },
670
+ }
587
671
588
672
with pytest .raises (InvalidContentType ):
589
673
request .get_body (spec )
590
674
675
+ def test_post_pets_missing_cookie (self , spec , spec_dict ):
676
+ host_url = 'http://petstore.swagger.io/v1'
677
+ path_pattern = '/v1/pets'
678
+ pet_name = 'Cat'
679
+ pet_healthy = True
680
+ data_json = {
681
+ 'name' : pet_name ,
682
+ 'ears' : {
683
+ 'healthy' : pet_healthy ,
684
+ }
685
+ }
686
+ data = json .dumps (data_json )
687
+ headers = {
688
+ 'api_key' : '12345' ,
689
+ }
690
+
691
+ request = MockRequest (
692
+ host_url , 'POST' , '/pets' ,
693
+ path_pattern = path_pattern , data = data ,
694
+ headers = headers ,
695
+ )
696
+
697
+ with pytest .raises (MissingRequiredParameter ):
698
+ request .get_parameters (spec )
699
+
700
+ body = request .get_body (spec )
701
+
702
+ schemas = spec_dict ['components' ]['schemas' ]
703
+ pet_model = schemas ['PetCreate' ]['x-model' ]
704
+ assert body .__class__ .__name__ == pet_model
705
+ assert body .name == pet_name
706
+ assert not hasattr (body , 'tag' )
707
+ assert not hasattr (body , 'address' )
708
+
709
+ def test_post_pets_missing_header (self , spec , spec_dict ):
710
+ host_url = 'http://petstore.swagger.io/v1'
711
+ path_pattern = '/v1/pets'
712
+ pet_name = 'Cat'
713
+ pet_healthy = True
714
+ data_json = {
715
+ 'name' : pet_name ,
716
+ 'ears' : {
717
+ 'healthy' : pet_healthy ,
718
+ }
719
+ }
720
+ data = json .dumps (data_json )
721
+ cookies = {
722
+ 'user' : '123' ,
723
+ }
724
+
725
+ request = MockRequest (
726
+ host_url , 'POST' , '/pets' ,
727
+ path_pattern = path_pattern , data = data ,
728
+ cookies = cookies ,
729
+ )
730
+
731
+ with pytest .raises (MissingRequiredParameter ):
732
+ request .get_parameters (spec )
733
+
734
+ body = request .get_body (spec )
735
+
736
+ schemas = spec_dict ['components' ]['schemas' ]
737
+ pet_model = schemas ['PetCreate' ]['x-model' ]
738
+ assert body .__class__ .__name__ == pet_model
739
+ assert body .name == pet_name
740
+ assert not hasattr (body , 'tag' )
741
+ assert not hasattr (body , 'address' )
742
+
591
743
def test_post_pets_raises_invalid_server_error (self , spec ):
592
744
host_url = 'http://flowerstore.swagger.io/v1'
593
745
path_pattern = '/v1/pets'
@@ -596,10 +748,17 @@ def test_post_pets_raises_invalid_server_error(self, spec):
596
748
'tag' : 'cats' ,
597
749
}
598
750
data = json .dumps (data_json )
751
+ headers = {
752
+ 'api_key' : '12345' ,
753
+ }
754
+ cookies = {
755
+ 'user' : '123' ,
756
+ }
599
757
600
758
request = MockRequest (
601
759
host_url , 'POST' , '/pets' ,
602
760
path_pattern = path_pattern , data = data , mimetype = 'text/html' ,
761
+ headers = headers , cookies = cookies ,
603
762
)
604
763
605
764
with pytest .raises (InvalidServer ):
0 commit comments