2
2
from .utils import http
3
3
4
4
5
- def _stringify (fixture ):
6
- return fixture + ''
7
-
8
-
9
- @pytest .mark .parametrize ('instance' , [
10
- pytest .lazy_fixture ('httpbin' ),
11
- pytest .lazy_fixture ('remote_httpbin' ),
5
+ @pytest .mark .parametrize ('target_httpbin' , [
6
+ 'httpbin' ,
7
+ 'remote_httpbin' ,
12
8
])
13
- def test_explicit_user_set_cookie (httpbin , instance ):
14
- # User set cookies ARE NOT persisted within redirects
15
- # when there is no session, even on the same domain.
16
-
9
+ def test_explicit_user_set_cookie (httpbin , target_httpbin , request ):
10
+ """User set cookies ARE NOT persisted within redirects when there is no session, even on the same domain."""
11
+ target_httpbin = request .getfixturevalue (target_httpbin )
17
12
r = http (
18
13
'--follow' ,
19
14
httpbin + '/redirect-to' ,
20
- f'url=={ _stringify ( instance ) } /cookies' ,
15
+ f'url=={ target_httpbin . url } /cookies' ,
21
16
'Cookie:a=b'
22
17
)
23
18
assert r .json == {'cookies' : {}}
24
19
25
20
26
- @pytest .mark .parametrize ('instance ' , [
27
- pytest . lazy_fixture ( 'httpbin' ) ,
28
- pytest . lazy_fixture ( 'remote_httpbin' ) ,
21
+ @pytest .mark .parametrize ('target_httpbin ' , [
22
+ 'httpbin' ,
23
+ 'remote_httpbin' ,
29
24
])
30
- def test_explicit_user_set_cookie_in_session (tmp_path , httpbin , instance ):
31
- # User set cookies ARE persisted within redirects
32
- # when there is A session, even on the same domain.
33
-
25
+ def test_explicit_user_set_cookie_in_session (tmp_path , httpbin , target_httpbin , request ):
26
+ """User set cookies ARE persisted within redirects when there is A session, even on the same domain."""
27
+ target_httpbin = request .getfixturevalue (target_httpbin )
34
28
r = http (
35
29
'--follow' ,
36
30
'--session' ,
37
31
str (tmp_path / 'session.json' ),
38
32
httpbin + '/redirect-to' ,
39
- f'url=={ _stringify ( instance ) } /cookies' ,
33
+ f'url=={ target_httpbin } /cookies' ,
40
34
'Cookie:a=b'
41
35
)
42
36
assert r .json == {'cookies' : {'a' : 'b' }}
43
37
44
38
45
- @pytest .mark .parametrize ('instance ' , [
46
- pytest . lazy_fixture ( 'httpbin' ) ,
47
- pytest . lazy_fixture ( 'remote_httpbin' ) ,
39
+ @pytest .mark .parametrize ('target_httpbin ' , [
40
+ 'httpbin' ,
41
+ 'remote_httpbin' ,
48
42
])
49
- def test_saved_user_set_cookie_in_session (tmp_path , httpbin , instance ):
50
- # User set cookies ARE persisted within redirects
51
- # when there is A session, even on the same domain.
52
-
43
+ def test_saved_user_set_cookie_in_session (tmp_path , httpbin , target_httpbin , request ):
44
+ """User set cookies ARE persisted within redirects when there is A session, even on the same domain."""
45
+ target_httpbin = request .getfixturevalue (target_httpbin )
53
46
http (
54
47
'--follow' ,
55
48
'--session' ,
@@ -62,49 +55,47 @@ def test_saved_user_set_cookie_in_session(tmp_path, httpbin, instance):
62
55
'--session' ,
63
56
str (tmp_path / 'session.json' ),
64
57
httpbin + '/redirect-to' ,
65
- f'url=={ _stringify ( instance ) } /cookies' ,
58
+ f'url=={ target_httpbin } /cookies' ,
66
59
)
67
60
assert r .json == {'cookies' : {'a' : 'b' }}
68
61
69
62
70
- @pytest .mark .parametrize ('instance ' , [
71
- pytest . lazy_fixture ( 'httpbin' ) ,
72
- pytest . lazy_fixture ( 'remote_httpbin' ) ,
63
+ @pytest .mark .parametrize ('target_httpbin ' , [
64
+ 'httpbin' ,
65
+ 'remote_httpbin' ,
73
66
])
74
67
@pytest .mark .parametrize ('session' , [True , False ])
75
- def test_explicit_user_set_headers (httpbin , tmp_path , instance , session ):
76
- # User set headers ARE persisted within redirects
77
- # even on different domains domain with or without
78
- # an active session.
68
+ def test_explicit_user_set_headers (httpbin , tmp_path , target_httpbin , session , request ):
69
+ """
70
+ User set headers ARE persisted within redirects even on different domains domain with or without an active session.
71
+
72
+ """
73
+ target_httpbin = request .getfixturevalue (target_httpbin )
79
74
session_args = []
80
75
if session :
81
76
session_args .extend ([
82
77
'--session' ,
83
78
str (tmp_path / 'session.json' )
84
79
])
85
-
86
80
r = http (
87
81
'--follow' ,
88
82
* session_args ,
89
83
httpbin + '/redirect-to' ,
90
- f'url=={ _stringify ( instance ) } /get' ,
84
+ f'url=={ target_httpbin } /get' ,
91
85
'X-Custom-Header:value'
92
86
)
93
87
assert 'X-Custom-Header' in r .json ['headers' ]
94
88
95
89
96
90
@pytest .mark .parametrize ('session' , [True , False ])
97
91
def test_server_set_cookie_on_redirect_same_domain (tmp_path , httpbin , session ):
98
- # Server set cookies ARE persisted on the same domain
99
- # when they are forwarded.
100
-
92
+ """Server set cookies ARE persisted on the same domain when they are forwarded."""
101
93
session_args = []
102
94
if session :
103
95
session_args .extend ([
104
96
'--session' ,
105
97
str (tmp_path / 'session.json' )
106
98
])
107
-
108
99
r = http (
109
100
'--follow' ,
110
101
* session_args ,
@@ -136,8 +127,7 @@ def test_server_set_cookie_on_redirect_different_domain(tmp_path, http_server, h
136
127
137
128
138
129
def test_saved_session_cookies_on_same_domain (tmp_path , httpbin ):
139
- # Saved session cookies ARE persisted when making a new
140
- # request to the same domain.
130
+ """Saved session cookies ARE persisted when making a new request to the same domain."""
141
131
http (
142
132
'--session' ,
143
133
str (tmp_path / 'session.json' ),
@@ -152,8 +142,7 @@ def test_saved_session_cookies_on_same_domain(tmp_path, httpbin):
152
142
153
143
154
144
def test_saved_session_cookies_on_different_domain (tmp_path , httpbin , remote_httpbin ):
155
- # Saved session cookies ARE persisted when making a new
156
- # request to a different domain.
145
+ """Saved session cookies ARE persisted when making a new request to a different domain."""
157
146
http (
158
147
'--session' ,
159
148
str (tmp_path / 'session.json' ),
@@ -167,45 +156,49 @@ def test_saved_session_cookies_on_different_domain(tmp_path, httpbin, remote_htt
167
156
assert r .json == {'cookies' : {}}
168
157
169
158
170
- @pytest .mark .parametrize ('initial_domain, first_request_domain, second_request_domain, expect_cookies' , [
159
+ @pytest .mark .parametrize ([ 'initial_domain' , ' first_request_domain' , ' second_request_domain' , ' expect_cookies'] , [
171
160
(
172
161
# Cookies are set by Domain A
173
162
# Initial domain is Domain A
174
163
# Redirected domain is Domain A
175
- pytest . lazy_fixture ( 'httpbin' ) ,
176
- pytest . lazy_fixture ( 'httpbin' ) ,
177
- pytest . lazy_fixture ( 'httpbin' ) ,
164
+ 'httpbin' ,
165
+ 'httpbin' ,
166
+ 'httpbin' ,
178
167
True ,
179
168
),
180
169
(
181
170
# Cookies are set by Domain A
182
171
# Initial domain is Domain B
183
172
# Redirected domain is Domain B
184
- pytest . lazy_fixture ( 'httpbin' ) ,
185
- pytest . lazy_fixture ( 'remote_httpbin' ) ,
186
- pytest . lazy_fixture ( 'remote_httpbin' ) ,
173
+ 'httpbin' ,
174
+ 'remote_httpbin' ,
175
+ 'remote_httpbin' ,
187
176
False ,
188
177
),
189
178
(
190
179
# Cookies are set by Domain A
191
180
# Initial domain is Domain A
192
181
# Redirected domain is Domain B
193
- pytest . lazy_fixture ( 'httpbin' ) ,
194
- pytest . lazy_fixture ( 'httpbin' ) ,
195
- pytest . lazy_fixture ( 'remote_httpbin' ) ,
182
+ 'httpbin' ,
183
+ 'httpbin' ,
184
+ 'remote_httpbin' ,
196
185
False ,
197
186
),
198
187
(
199
188
# Cookies are set by Domain A
200
189
# Initial domain is Domain B
201
190
# Redirected domain is Domain A
202
- pytest . lazy_fixture ( 'httpbin' ) ,
203
- pytest . lazy_fixture ( 'remote_httpbin' ) ,
204
- pytest . lazy_fixture ( 'httpbin' ) ,
191
+ 'httpbin' ,
192
+ 'remote_httpbin' ,
193
+ 'httpbin' ,
205
194
True ,
206
195
),
207
196
])
208
- def test_saved_session_cookies_on_redirect (tmp_path , initial_domain , first_request_domain , second_request_domain , expect_cookies ):
197
+ def test_saved_session_cookies_on_redirect (
198
+ tmp_path , initial_domain , first_request_domain , second_request_domain , expect_cookies , request ):
199
+ initial_domain = request .getfixturevalue (initial_domain )
200
+ first_request_domain = request .getfixturevalue (first_request_domain )
201
+ second_request_domain = request .getfixturevalue (second_request_domain )
209
202
http (
210
203
'--session' ,
211
204
str (tmp_path / 'session.json' ),
@@ -216,7 +209,7 @@ def test_saved_session_cookies_on_redirect(tmp_path, initial_domain, first_reque
216
209
str (tmp_path / 'session.json' ),
217
210
'--follow' ,
218
211
first_request_domain + '/redirect-to' ,
219
- f'url=={ _stringify ( second_request_domain ) } /cookies'
212
+ f'url=={ second_request_domain } /cookies'
220
213
)
221
214
if expect_cookies :
222
215
expected_data = {'cookies' : {'a' : 'b' }}
0 commit comments