Tests for our URL handling.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Cory Benfield · committed by Cory Benfield · parent 402a55b · Browse files · 1 file·+71 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+71 added−0 removed
- tests:+71 added−0 removed
Provenance
- Commit
6f659a4- Tree
25f0e27- Author
Cory Benfield <lukasaoz@gmail.com>- Committer
Cory Benfield <lukasaoz@gmail.com>- Parent
402a55b
1 file changed+71 added−0 removed
modified:tests/test_requests.py+71 added
2173 unmodified lines2174 def test_preparing_bad_url(self, url):2175 r = requests.Request('GET', url=url)2176 with pytest.raises(requests.exceptions.InvalidURL):2177 r.prepare()2178+2179+ @pytest.mark.parametrize(2180+ 'input, expected',2181+ (2182+ (2183+ b"http+unix://%2Fvar%2Frun%2Fsocket/path",2184+ u"http+unix://%2fvar%2frun%2fsocket/path",2185+ ),2186+ (2187+ u"http+unix://%2Fvar%2Frun%2Fsocket/path",2188+ u"http+unix://%2fvar%2frun%2fsocket/path",2189+ ),2190+ (2191+ b"mailto:user@example.org",2192+ u"mailto:user@example.org",2193+ ),2194+ (2195+ u"mailto:user@example.org",2196+ u"mailto:user@example.org",2197+ ),2198+ (2199+ b"data:SSDimaUgUHl0aG9uIQ==",2200+ u"data:SSDimaUgUHl0aG9uIQ==",2201+ )2202+ )2203+ )2204+ def test_url_mutation(self, input, expected):2205+ """2206+ This test validates that we correctly exclude some URLs from2207+ preparation, and that we handle others. Specifically, it tests that2208+ any URL whose scheme doesn't begin with "http" is left alone, and2209+ those whose scheme *does* begin with "http" are mutated.2210+ """2211+ r = requests.Request('GET', url=input)2212+ p = r.prepare()2213+ assert p.url == expected2214+2215+ @pytest.mark.parametrize(2216+ 'input, params, expected',2217+ (2218+ (2219+ b"http+unix://%2Fvar%2Frun%2Fsocket/path",2220+ {"key": "value"},2221+ u"http+unix://%2fvar%2frun%2fsocket/path?key=value",2222+ ),2223+ (2224+ u"http+unix://%2Fvar%2Frun%2Fsocket/path",2225+ {"key": "value"},2226+ u"http+unix://%2fvar%2frun%2fsocket/path?key=value",2227+ ),2228+ (2229+ b"mailto:user@example.org",2230+ {"key": "value"},2231+ u"mailto:user@example.org",2232+ ),2233+ (2234+ u"mailto:user@example.org",2235+ {"key": "value"},2236+ u"mailto:user@example.org",2237+ ),2238+ )2239+ )2240+ def test_parameters_for_nonstandard_schemes(self, input, params, expected):2241+ """2242+ Setting paramters for nonstandard schemes is allowed if those schemes2243+ begin with "http", and is forbidden otherwise.2244+ """2245+ r = requests.Request('GET', url=input, params=params)2246+ p = r.prepare()2247+ assert p.url == expected2248+