@@ -89,6 +89,24 @@ def assert_data_list_equal(self, data1, data2):
8989 )
9090 raise type (exceptions [0 ])(message )
9191
92+ def assert_headers_contain (self , response_data , spec_data ):
93+ """
94+ response_data headers contain all headers defined in spec_data
95+ """
96+ for expected_header , expected_value in spec_data .items ():
97+ django_expected_header = (
98+ 'HTTP_' + expected_header .upper ().replace ('-' , '_' )
99+ )
100+ actual_val = response_data .get (
101+ expected_header ,
102+ response_data .get (django_expected_header )
103+ )
104+ self .assertEqual (
105+ expected_value , actual_val ,
106+ "Incorrect or missing value specified for "
107+ "header {0}" .format (expected_header )
108+ )
109+
92110 def assert_matches_sample (self , path , label , url , response ):
93111 """
94112 Check a URL and response against a sample.
@@ -108,6 +126,11 @@ def assert_matches_sample(self, path, label, url, response):
108126 sample_response = sample .examples [label ].response
109127
110128 self .assertEqual (url , sample_request .url )
129+ if 'headers' in sample_request :
130+ self .assert_headers_contain (
131+ response .request , sample_request .headers
132+ )
133+
111134 self .assertEqual (response .status_code , sample_response .status )
112135 if 'body' in sample_response :
113136 response_parsed = response .data
0 commit comments