@@ -55,6 +55,16 @@ def remove_by_slug():
55
55
return slug
56
56
57
57
58
+ @pytest .fixture ()
59
+ def no_fields (monkeypatch ):
60
+ """When we want to test the __init__ method of the jira.client.JIRA
61
+ we don't need any external calls to get the fields.
62
+
63
+ We don't need the features of a MagicMock, hence we don't use it here.
64
+ """
65
+ monkeypatch .setattr (jira .client .JIRA , "fields" , lambda * args , ** kwargs : [])
66
+
67
+
58
68
def test_delete_project (cl_admin , cl_normal , slug ):
59
69
60
70
assert cl_admin .delete_project (slug )
@@ -119,3 +129,69 @@ def test_result_list_if_empty():
119
129
120
130
with pytest .raises (StopIteration ):
121
131
next (results )
132
+
133
+
134
+ @pytest .mark .parametrize (
135
+ "options_arg" ,
136
+ [
137
+ {"headers" : {"Content-Type" : "application/json;charset=UTF-8" }},
138
+ {"headers" : {"random-header" : "nice random" }},
139
+ ],
140
+ ids = ["overwrite" , "new" ],
141
+ )
142
+ def test_headers_unclobbered_update (options_arg , no_fields ):
143
+
144
+ assert "headers" in options_arg , "test case options must contain headers"
145
+
146
+ # GIVEN: the headers and the expected value
147
+ header_to_check : str = list (options_arg ["headers" ].keys ())[0 ]
148
+ expected_header_value : str = options_arg ["headers" ][header_to_check ]
149
+
150
+ invariant_header_name : str = "X-Atlassian-Token"
151
+ invariant_header_value : str = jira .client .JIRA .DEFAULT_OPTIONS ["headers" ][
152
+ invariant_header_name
153
+ ]
154
+
155
+ # We arbitrarily chose a header to check it remains unchanged/unclobbered
156
+ # so should not be overwritten by a test case
157
+ assert (
158
+ invariant_header_name not in options_arg ["headers" ]
159
+ ), f"{ invariant_header_name } is checked as not being overwritten in this test"
160
+
161
+ # WHEN: we initialise the JIRA class and get the headers
162
+ jira_client = jira .client .JIRA (
163
+ server = "https://jira.atlasian.com" ,
164
+ get_server_info = False ,
165
+ validate = False ,
166
+ options = options_arg ,
167
+ )
168
+
169
+ session_headers = jira_client ._session .headers
170
+
171
+ # THEN: we have set the right headers and not affect the other headers' defaults
172
+ assert session_headers [header_to_check ] == expected_header_value
173
+ assert session_headers [invariant_header_name ] == invariant_header_value
174
+
175
+
176
+ def test_headers_unclobbered_update_with_no_provided_headers (no_fields ):
177
+
178
+ options_arg = {} # a dict with "headers" not set
179
+
180
+ # GIVEN:the headers and the expected value
181
+ invariant_header_name : str = "X-Atlassian-Token"
182
+ invariant_header_value : str = jira .client .JIRA .DEFAULT_OPTIONS ["headers" ][
183
+ invariant_header_name
184
+ ]
185
+
186
+ # WHEN: we initialise the JIRA class with no provided headers and get the headers
187
+ jira_client = jira .client .JIRA (
188
+ server = "https://jira.atlasian.com" ,
189
+ get_server_info = False ,
190
+ validate = False ,
191
+ options = options_arg ,
192
+ )
193
+
194
+ session_headers = jira_client ._session .headers
195
+
196
+ # THEN: we have not affected the other headers' defaults
197
+ assert session_headers [invariant_header_name ] == invariant_header_value
0 commit comments