@@ -392,15 +392,29 @@ def test_post_birds(self, spec, spec_dict):
392392 }
393393 }
394394 data = json .dumps (data_json )
395+ headers = {
396+ 'api_key' : '12345' ,
397+ }
398+ cookies = {
399+ 'user' : '123' ,
400+ }
395401
396402 request = MockRequest (
397403 host_url , 'POST' , '/pets' ,
398404 path_pattern = path_pattern , data = data ,
405+ headers = headers , cookies = cookies ,
399406 )
400407
401408 parameters = request .get_parameters (spec )
402409
403- assert parameters == {}
410+ assert parameters == {
411+ 'header' : {
412+ 'api_key' : 12345 ,
413+ },
414+ 'cookie' : {
415+ 'user' : 123 ,
416+ },
417+ }
404418
405419 body = request .get_body (spec )
406420
@@ -438,15 +452,29 @@ def test_post_cats(self, spec, spec_dict):
438452 }
439453 }
440454 data = json .dumps (data_json )
455+ headers = {
456+ 'api_key' : '12345' ,
457+ }
458+ cookies = {
459+ 'user' : '123' ,
460+ }
441461
442462 request = MockRequest (
443463 host_url , 'POST' , '/pets' ,
444464 path_pattern = path_pattern , data = data ,
465+ headers = headers , cookies = cookies ,
445466 )
446467
447468 parameters = request .get_parameters (spec )
448469
449- assert parameters == {}
470+ assert parameters == {
471+ 'header' : {
472+ 'api_key' : 12345 ,
473+ },
474+ 'cookie' : {
475+ 'user' : 123 ,
476+ },
477+ }
450478
451479 body = request .get_body (spec )
452480
@@ -484,15 +512,29 @@ def test_post_cats_boolean_string(self, spec, spec_dict):
484512 }
485513 }
486514 data = json .dumps (data_json )
515+ headers = {
516+ 'api_key' : '12345' ,
517+ }
518+ cookies = {
519+ 'user' : '123' ,
520+ }
487521
488522 request = MockRequest (
489523 host_url , 'POST' , '/pets' ,
490524 path_pattern = path_pattern , data = data ,
525+ headers = headers , cookies = cookies ,
491526 )
492527
493528 parameters = request .get_parameters (spec )
494529
495- assert parameters == {}
530+ assert parameters == {
531+ 'header' : {
532+ 'api_key' : 12345 ,
533+ },
534+ 'cookie' : {
535+ 'user' : 123 ,
536+ },
537+ }
496538
497539 body = request .get_body (spec )
498540
@@ -518,15 +560,29 @@ def test_post_no_one_of_schema(self, spec, spec_dict):
518560 'alias' : alias ,
519561 }
520562 data = json .dumps (data_json )
563+ headers = {
564+ 'api_key' : '12345' ,
565+ }
566+ cookies = {
567+ 'user' : '123' ,
568+ }
521569
522570 request = MockRequest (
523571 host_url , 'POST' , '/pets' ,
524572 path_pattern = path_pattern , data = data ,
573+ headers = headers , cookies = cookies ,
525574 )
526575
527576 parameters = request .get_parameters (spec )
528577
529- assert parameters == {}
578+ assert parameters == {
579+ 'header' : {
580+ 'api_key' : 12345 ,
581+ },
582+ 'cookie' : {
583+ 'user' : 123 ,
584+ },
585+ }
530586
531587 with pytest .raises (NoOneOfSchema ):
532588 request .get_body (spec )
@@ -543,15 +599,29 @@ def test_post_cats_only_required_body(self, spec, spec_dict):
543599 }
544600 }
545601 data = json .dumps (data_json )
602+ headers = {
603+ 'api_key' : '12345' ,
604+ }
605+ cookies = {
606+ 'user' : '123' ,
607+ }
546608
547609 request = MockRequest (
548610 host_url , 'POST' , '/pets' ,
549611 path_pattern = path_pattern , data = data ,
612+ headers = headers , cookies = cookies ,
550613 )
551614
552615 parameters = request .get_parameters (spec )
553616
554- assert parameters == {}
617+ assert parameters == {
618+ 'header' : {
619+ 'api_key' : 12345 ,
620+ },
621+ 'cookie' : {
622+ 'user' : 123 ,
623+ },
624+ }
555625
556626 body = request .get_body (spec )
557627
@@ -570,19 +640,101 @@ def test_post_pets_raises_invalid_mimetype(self, spec):
570640 'tag' : 'cats' ,
571641 }
572642 data = json .dumps (data_json )
643+ headers = {
644+ 'api_key' : '12345' ,
645+ }
646+ cookies = {
647+ 'user' : '123' ,
648+ }
573649
574650 request = MockRequest (
575651 host_url , 'POST' , '/pets' ,
576652 path_pattern = path_pattern , data = data , mimetype = 'text/html' ,
653+ headers = headers , cookies = cookies ,
577654 )
578655
579656 parameters = request .get_parameters (spec )
580657
581- assert parameters == {}
658+ assert parameters == {
659+ 'header' : {
660+ 'api_key' : 12345 ,
661+ },
662+ 'cookie' : {
663+ 'user' : 123 ,
664+ },
665+ }
582666
583667 with pytest .raises (InvalidContentType ):
584668 request .get_body (spec )
585669
670+ def test_post_pets_missing_cookie (self , spec , spec_dict ):
671+ host_url = 'http://petstore.swagger.io/v1'
672+ path_pattern = '/v1/pets'
673+ pet_name = 'Cat'
674+ pet_healthy = True
675+ data_json = {
676+ 'name' : pet_name ,
677+ 'ears' : {
678+ 'healthy' : pet_healthy ,
679+ }
680+ }
681+ data = json .dumps (data_json )
682+ headers = {
683+ 'api_key' : '12345' ,
684+ }
685+
686+ request = MockRequest (
687+ host_url , 'POST' , '/pets' ,
688+ path_pattern = path_pattern , data = data ,
689+ headers = headers ,
690+ )
691+
692+ with pytest .raises (MissingRequiredParameter ):
693+ request .get_parameters (spec )
694+
695+ body = request .get_body (spec )
696+
697+ schemas = spec_dict ['components' ]['schemas' ]
698+ pet_model = schemas ['PetCreate' ]['x-model' ]
699+ assert body .__class__ .__name__ == pet_model
700+ assert body .name == pet_name
701+ assert not hasattr (body , 'tag' )
702+ assert not hasattr (body , 'address' )
703+
704+ def test_post_pets_missing_header (self , spec , spec_dict ):
705+ host_url = 'http://petstore.swagger.io/v1'
706+ path_pattern = '/v1/pets'
707+ pet_name = 'Cat'
708+ pet_healthy = True
709+ data_json = {
710+ 'name' : pet_name ,
711+ 'ears' : {
712+ 'healthy' : pet_healthy ,
713+ }
714+ }
715+ data = json .dumps (data_json )
716+ cookies = {
717+ 'user' : '123' ,
718+ }
719+
720+ request = MockRequest (
721+ host_url , 'POST' , '/pets' ,
722+ path_pattern = path_pattern , data = data ,
723+ cookies = cookies ,
724+ )
725+
726+ with pytest .raises (MissingRequiredParameter ):
727+ request .get_parameters (spec )
728+
729+ body = request .get_body (spec )
730+
731+ schemas = spec_dict ['components' ]['schemas' ]
732+ pet_model = schemas ['PetCreate' ]['x-model' ]
733+ assert body .__class__ .__name__ == pet_model
734+ assert body .name == pet_name
735+ assert not hasattr (body , 'tag' )
736+ assert not hasattr (body , 'address' )
737+
586738 def test_post_pets_raises_invalid_server_error (self , spec ):
587739 host_url = 'http://flowerstore.swagger.io/v1'
588740 path_pattern = '/v1/pets'
@@ -591,10 +743,17 @@ def test_post_pets_raises_invalid_server_error(self, spec):
591743 'tag' : 'cats' ,
592744 }
593745 data = json .dumps (data_json )
746+ headers = {
747+ 'api_key' : '12345' ,
748+ }
749+ cookies = {
750+ 'user' : '123' ,
751+ }
594752
595753 request = MockRequest (
596754 host_url , 'POST' , '/pets' ,
597755 path_pattern = path_pattern , data = data , mimetype = 'text/html' ,
756+ headers = headers , cookies = cookies ,
598757 )
599758
600759 with pytest .raises (InvalidServer ):
0 commit comments