22import re
33
44import pytest
5- import requests
65
76from ..test_utils .utils import generate_test_cookies
87
98TEST_COOKIES = generate_test_cookies ()
109
1110
12- def test_exodus_basic (cdn_test_url ):
11+ def test_exodus_basic (cdn_test_url , requests_session ):
1312 url = (
1413 cdn_test_url
1514 + "/content/aus/rhel/server/6/6.5/x86_64/os/Packages/c/cpio-2.10-12.el6_5.x86_64.rpm"
1615 )
1716
18- r = requests .get (url , cookies = TEST_COOKIES )
17+ r = requests_session .get (url , cookies = TEST_COOKIES )
1918 print (json .dumps (dict (r .headers ), indent = 2 ))
2019 assert r .status_code == 200
2120 assert "cache-control" not in r .headers
2221
2322
24- def test_header_not_exist_file (cdn_test_url ):
23+ def test_header_not_exist_file (cdn_test_url , requests_session ):
2524 url = (
2625 cdn_test_url
2726 + "/content/aus/rhel/server/6/6.5/x86_64/os/Packages/c/cpio-2.10-12.el6_5.x86_64.rpm_not_exist" # noqa: E501
2827 )
29- r = requests .get (url , cookies = TEST_COOKIES )
28+ r = requests_session .get (url , cookies = TEST_COOKIES )
3029 print (json .dumps (dict (r .headers ), indent = 2 ))
3130 assert r .status_code == 404
3231 assert "cache-control" not in r .headers
@@ -42,21 +41,21 @@ def test_header_not_exist_file(cdn_test_url):
4241
4342
4443@pytest .mark .parametrize ("testdata_path" , testdata_cache_control_path )
45- def test_header_cache_control (cdn_test_url , testdata_path ):
44+ def test_header_cache_control (cdn_test_url , requests_session , testdata_path ):
4645 url = cdn_test_url + testdata_path
47- r = requests .get (url , cookies = TEST_COOKIES )
46+ r = requests_session .get (url , cookies = TEST_COOKIES )
4847 print (json .dumps (dict (r .headers ), indent = 2 ))
4948 assert r .status_code == 200
5049 assert re .match ("^max-age=[0-9]+$" , r .headers ["cache-control" ])
5150
5251
53- def test_header_want_digest_GET (cdn_test_url ):
52+ def test_header_want_digest_GET (cdn_test_url , requests_session ):
5453 headers = {"want-digest" : "id-sha-256" }
5554 url = (
5655 cdn_test_url
5756 + "/content/dist/rhel/server/7/7.2/x86_64/rhev-mgmt-agent/3/os/repodata/repomd.xml"
5857 )
59- r = requests .get (url , headers = headers , cookies = TEST_COOKIES )
58+ r = requests_session .get (url , headers = headers , cookies = TEST_COOKIES )
6059 print (json .dumps (dict (r .headers ), indent = 2 ))
6160 assert r .status_code == 200
6261 assert (
@@ -65,13 +64,13 @@ def test_header_want_digest_GET(cdn_test_url):
6564 )
6665
6766
68- def test_header_want_digest_HEAD (cdn_test_url ):
67+ def test_header_want_digest_HEAD (cdn_test_url , requests_session ):
6968 headers = {"want-digest" : "id-sha-256" }
7069 url = (
7170 cdn_test_url
7271 + "/content/dist/rhel/server/7/7.2/x86_64/rhev-mgmt-agent/3/os/repodata/repomd.xml"
7372 )
74- r = requests .head (url , headers = headers , cookies = TEST_COOKIES )
73+ r = requests_session .head (url , headers = headers , cookies = TEST_COOKIES )
7574 print (json .dumps (dict (r .headers ), indent = 2 ))
7675 assert r .status_code == 200
7776 assert (
@@ -101,18 +100,22 @@ def assert_content_type(url, content_type):
101100
102101
103102@pytest .mark .parametrize ("testdata_path" , testdata_content_type_path )
104- def test_content_type_header_GET (cdn_test_url , testdata_path ):
103+ def test_content_type_header_GET (
104+ cdn_test_url , requests_session , testdata_path
105+ ):
105106 url = cdn_test_url + testdata_path
106- r = requests .get (url , cookies = TEST_COOKIES )
107+ r = requests_session .get (url , cookies = TEST_COOKIES )
107108 print (json .dumps (dict (r .headers ), indent = 2 ))
108109 assert r .status_code == 200
109110 assert_content_type (url , r .headers ["Content-Type" ])
110111
111112
112113@pytest .mark .parametrize ("testdata_path" , testdata_content_type_path )
113- def test_content_type_header_HEAD (cdn_test_url , testdata_path ):
114+ def test_content_type_header_HEAD (
115+ cdn_test_url , requests_session , testdata_path
116+ ):
114117 url = cdn_test_url + testdata_path
115- r = requests .head (url , cookies = TEST_COOKIES )
118+ r = requests_session .head (url , cookies = TEST_COOKIES )
116119 print (json .dumps (dict (r .headers ), indent = 2 ))
117120 assert r .status_code == 200
118121 assert_content_type (url , r .headers ["Content-Type" ])
@@ -128,10 +131,10 @@ def test_content_type_header_HEAD(cdn_test_url, testdata_path):
128131
129132# use Want-Digest/Digest to check if alias take effect
130133@pytest .mark .parametrize ("testdata_path" , testdata_origin_alias_path )
131- def test_origin_path_alias (cdn_test_url , testdata_path ):
134+ def test_origin_path_alias (cdn_test_url , requests_session , testdata_path ):
132135 headers = {"want-digest" : "id-sha-256" }
133136 url = cdn_test_url + testdata_path
134- r = requests .head (url , headers = headers , cookies = TEST_COOKIES )
137+ r = requests_session .head (url , headers = headers , cookies = TEST_COOKIES )
135138 print (json .dumps (dict (r .headers ), indent = 2 ))
136139 assert r .status_code == 200
137140 assert (
@@ -147,10 +150,10 @@ def test_origin_path_alias(cdn_test_url, testdata_path):
147150
148151
149152@pytest .mark .parametrize ("testdata_path" , testdata_rhui_alias_path_aus )
150- def test_rhui_path_alias_aus (cdn_test_url , testdata_path ):
153+ def test_rhui_path_alias_aus (cdn_test_url , requests_session , testdata_path ):
151154 headers = {"want-digest" : "id-sha-256" }
152155 url = cdn_test_url + testdata_path
153- r = requests .head (url , headers = headers , cookies = TEST_COOKIES )
156+ r = requests_session .head (url , headers = headers , cookies = TEST_COOKIES )
154157 print (json .dumps (dict (r .headers ), indent = 2 ))
155158 assert r .status_code == 200
156159 assert (
@@ -166,10 +169,10 @@ def test_rhui_path_alias_aus(cdn_test_url, testdata_path):
166169
167170
168171@pytest .mark .parametrize ("testdata_path" , testdata_rhui_alias_path_rhel8 )
169- def test_rhui_path_alias_rhel8 (cdn_test_url , testdata_path ):
172+ def test_rhui_path_alias_rhel8 (cdn_test_url , requests_session , testdata_path ):
170173 headers = {"want-digest" : "id-sha-256" }
171174 url = cdn_test_url + testdata_path
172- r = requests .head (url , headers = headers , cookies = TEST_COOKIES )
175+ r = requests_session .head (url , headers = headers , cookies = TEST_COOKIES )
173176 print (json .dumps (dict (r .headers ), indent = 2 ))
174177 assert r .status_code == 200
175178 assert (
@@ -185,10 +188,10 @@ def test_rhui_path_alias_rhel8(cdn_test_url, testdata_path):
185188
186189
187190@pytest .mark .parametrize ("testdata_path" , testdata_releasever_alias_rhel6 )
188- def test_releasever_alias_rhel6 (cdn_test_url , testdata_path ):
191+ def test_releasever_alias_rhel6 (cdn_test_url , requests_session , testdata_path ):
189192 headers = {"want-digest" : "id-sha-256" }
190193 url = cdn_test_url + testdata_path
191- r = requests .head (url , headers = headers , cookies = TEST_COOKIES )
194+ r = requests_session .head (url , headers = headers , cookies = TEST_COOKIES )
192195 print (json .dumps (dict (r .headers ), indent = 2 ))
193196 assert r .status_code == 200
194197 assert (
@@ -203,9 +206,9 @@ def test_releasever_alias_rhel6(cdn_test_url, testdata_path):
203206
204207
205208@pytest .mark .parametrize ("testdata_path" , testdata_no_content_type )
206- def test_no_content_type (cdn_test_url , testdata_path ):
209+ def test_no_content_type (cdn_test_url , requests_session , testdata_path ):
207210 url = cdn_test_url + testdata_path
208- r = requests .get (url , cookies = TEST_COOKIES )
211+ r = requests_session .get (url , cookies = TEST_COOKIES )
209212 print (json .dumps (dict (r .headers ), indent = 2 ))
210213 assert r .status_code == 200
211214 assert r .headers ["Content-Type" ] == "application/octet-stream"
@@ -217,8 +220,8 @@ def test_no_content_type(cdn_test_url, testdata_path):
217220
218221
219222@pytest .mark .parametrize ("testdata_path" , testdata_absent_item )
220- def test_absent_item (cdn_test_url , testdata_path ):
223+ def test_absent_item (cdn_test_url , requests_session , testdata_path ):
221224 url = cdn_test_url + testdata_path
222- r = requests .get (url , cookies = TEST_COOKIES )
225+ r = requests_session .get (url , cookies = TEST_COOKIES )
223226 print (json .dumps (dict (r .headers ), indent = 2 ))
224227 assert r .status_code == 404
0 commit comments