@@ -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,53 @@ 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
+ ],
141
+ ids = ["overwrite" , "new" , "none" ],
142
+ )
143
+ def test_headers_unclobbered_update (options_arg , no_fields ):
144
+
145
+ # GIVEN: the headers and the expected value
146
+ header_to_check : str
147
+ expected_header_value : str
148
+ if options_arg :
149
+ header_to_check = list (options_arg ["headers" ].keys ())[0 ]
150
+ expected_header_value = options_arg ["headers" ][header_to_check ]
151
+ elif "headers" not in options_arg :
152
+ # when we are checking not proving any headers
153
+ header_to_check = "Content-Type"
154
+ expected_header_value = jira .client .JIRA .DEFAULT_OPTIONS ["headers" ][
155
+ header_to_check
156
+ ]
157
+
158
+ invariant_header_name : str = "X-Atlassian-Token"
159
+ invariant_header_value : str = jira .client .JIRA .DEFAULT_OPTIONS ["headers" ][
160
+ invariant_header_name
161
+ ]
162
+ if options_arg :
163
+ # We arbitrarily chose a header to check it remains unchanged/unclobbered
164
+ # so should not be overwritten by a test case
165
+ assert (
166
+ invariant_header_name not in options_arg ["headers" ]
167
+ ), f"{ invariant_header_name } is checked as not being overwritten in this test"
168
+
169
+ # WHEN: we initialise the JIRA class and get the headers
170
+ jira_client = jira .client .JIRA (
171
+ server = "https://jira.atlasian.com" ,
172
+ get_server_info = False ,
173
+ validate = False ,
174
+ options = options_arg ,
175
+ )
176
+
177
+ session_headers = jira_client ._session .headers
178
+
179
+ # THEN: we have set the right headers and not affect the defaults
180
+ assert session_headers [header_to_check ] == expected_header_value
181
+ assert session_headers [invariant_header_name ] == invariant_header_value
0 commit comments