@@ -397,15 +397,29 @@ def test_post_birds(self, spec, spec_dict):
397397 }
398398 }
399399 data = json .dumps (data_json )
400+ headers = {
401+ 'api_key' : '12345' ,
402+ }
403+ cookies = {
404+ 'user' : '123' ,
405+ }
400406
401407 request = MockRequest (
402408 host_url , 'POST' , '/pets' ,
403409 path_pattern = path_pattern , data = data ,
410+ headers = headers , cookies = cookies ,
404411 )
405412
406413 parameters = request .get_parameters (spec )
407414
408- assert parameters == {}
415+ assert parameters == {
416+ 'header' : {
417+ 'api_key' : 12345 ,
418+ },
419+ 'cookie' : {
420+ 'user' : 123 ,
421+ },
422+ }
409423
410424 body = request .get_body (spec )
411425
@@ -443,15 +457,29 @@ def test_post_cats(self, spec, spec_dict):
443457 }
444458 }
445459 data = json .dumps (data_json )
460+ headers = {
461+ 'api_key' : '12345' ,
462+ }
463+ cookies = {
464+ 'user' : '123' ,
465+ }
446466
447467 request = MockRequest (
448468 host_url , 'POST' , '/pets' ,
449469 path_pattern = path_pattern , data = data ,
470+ headers = headers , cookies = cookies ,
450471 )
451472
452473 parameters = request .get_parameters (spec )
453474
454- assert parameters == {}
475+ assert parameters == {
476+ 'header' : {
477+ 'api_key' : 12345 ,
478+ },
479+ 'cookie' : {
480+ 'user' : 123 ,
481+ },
482+ }
455483
456484 body = request .get_body (spec )
457485
@@ -489,15 +517,29 @@ def test_post_cats_boolean_string(self, spec, spec_dict):
489517 }
490518 }
491519 data = json .dumps (data_json )
520+ headers = {
521+ 'api_key' : '12345' ,
522+ }
523+ cookies = {
524+ 'user' : '123' ,
525+ }
492526
493527 request = MockRequest (
494528 host_url , 'POST' , '/pets' ,
495529 path_pattern = path_pattern , data = data ,
530+ headers = headers , cookies = cookies ,
496531 )
497532
498533 parameters = request .get_parameters (spec )
499534
500- assert parameters == {}
535+ assert parameters == {
536+ 'header' : {
537+ 'api_key' : 12345 ,
538+ },
539+ 'cookie' : {
540+ 'user' : 123 ,
541+ },
542+ }
501543
502544 body = request .get_body (spec )
503545
@@ -523,15 +565,29 @@ def test_post_no_one_of_schema(self, spec, spec_dict):
523565 'alias' : alias ,
524566 }
525567 data = json .dumps (data_json )
568+ headers = {
569+ 'api_key' : '12345' ,
570+ }
571+ cookies = {
572+ 'user' : '123' ,
573+ }
526574
527575 request = MockRequest (
528576 host_url , 'POST' , '/pets' ,
529577 path_pattern = path_pattern , data = data ,
578+ headers = headers , cookies = cookies ,
530579 )
531580
532581 parameters = request .get_parameters (spec )
533582
534- assert parameters == {}
583+ assert parameters == {
584+ 'header' : {
585+ 'api_key' : 12345 ,
586+ },
587+ 'cookie' : {
588+ 'user' : 123 ,
589+ },
590+ }
535591
536592 with pytest .raises (NoOneOfSchema ):
537593 request .get_body (spec )
@@ -548,15 +604,29 @@ def test_post_cats_only_required_body(self, spec, spec_dict):
548604 }
549605 }
550606 data = json .dumps (data_json )
607+ headers = {
608+ 'api_key' : '12345' ,
609+ }
610+ cookies = {
611+ 'user' : '123' ,
612+ }
551613
552614 request = MockRequest (
553615 host_url , 'POST' , '/pets' ,
554616 path_pattern = path_pattern , data = data ,
617+ headers = headers , cookies = cookies ,
555618 )
556619
557620 parameters = request .get_parameters (spec )
558621
559- assert parameters == {}
622+ assert parameters == {
623+ 'header' : {
624+ 'api_key' : 12345 ,
625+ },
626+ 'cookie' : {
627+ 'user' : 123 ,
628+ },
629+ }
560630
561631 body = request .get_body (spec )
562632
@@ -575,19 +645,101 @@ def test_post_pets_raises_invalid_mimetype(self, spec):
575645 'tag' : 'cats' ,
576646 }
577647 data = json .dumps (data_json )
648+ headers = {
649+ 'api_key' : '12345' ,
650+ }
651+ cookies = {
652+ 'user' : '123' ,
653+ }
578654
579655 request = MockRequest (
580656 host_url , 'POST' , '/pets' ,
581657 path_pattern = path_pattern , data = data , mimetype = 'text/html' ,
658+ headers = headers , cookies = cookies ,
582659 )
583660
584661 parameters = request .get_parameters (spec )
585662
586- assert parameters == {}
663+ assert parameters == {
664+ 'header' : {
665+ 'api_key' : 12345 ,
666+ },
667+ 'cookie' : {
668+ 'user' : 123 ,
669+ },
670+ }
587671
588672 with pytest .raises (InvalidContentType ):
589673 request .get_body (spec )
590674
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+
591743 def test_post_pets_raises_invalid_server_error (self , spec ):
592744 host_url = 'http://flowerstore.swagger.io/v1'
593745 path_pattern = '/v1/pets'
@@ -596,10 +748,17 @@ def test_post_pets_raises_invalid_server_error(self, spec):
596748 'tag' : 'cats' ,
597749 }
598750 data = json .dumps (data_json )
751+ headers = {
752+ 'api_key' : '12345' ,
753+ }
754+ cookies = {
755+ 'user' : '123' ,
756+ }
599757
600758 request = MockRequest (
601759 host_url , 'POST' , '/pets' ,
602760 path_pattern = path_pattern , data = data , mimetype = 'text/html' ,
761+ headers = headers , cookies = cookies ,
603762 )
604763
605764 with pytest .raises (InvalidServer ):
0 commit comments