| 122 | |
| 123 | |
| 124 | def test_url_from_scope() -> None: |
| 125 | u = URL(scope={"path": "/path/to/somewhere", "query_string": b"abc=123", "headers": []}) |
| 126 | assert u == "/path/to/somewhere?abc=123" |
| 127 | assert repr(u) == "URL('/path/to/somewhere?abc=123')" |
| 128 | |
| 129 | u = URL(scope={"path": "/path/to/somewhere", "query_string": b"", "headers": []}) |
| 130 | assert u == "/path/to/somewhere" |
| 131 | assert repr(u) == "URL('/path/to/somewhere')" |
| 132 | |
| 133 | u = URL( |
| 134 | scope={ |
| 135 | "scheme": "https", |
| 136 | "server": ("example.org", 123), |
| 137 | "path": "/path/to/somewhere", |
| 138 | "query_string": b"abc=123", |
| 139 | "headers": [], |
| 140 | } |
| 141 | ) |
| 142 | assert u == "https://example.org:123/path/to/somewhere?abc=123" |
| 143 | assert repr(u) == "URL('https://example.org:123/path/to/somewhere?abc=123')" |
| 144 | |
| 145 | u = URL( |
| 146 | scope={ |
| 147 | "scheme": "https", |
| 148 | "server": ("example.org", 443), |
| 149 | "path": "/path/to/somewhere", |
| 150 | "query_string": b"abc=123", |
| 151 | "headers": [], |
| 152 | } |
| 153 | ) |
| 154 | assert u == "https://example.org/path/to/somewhere?abc=123" |
| 155 | assert repr(u) == "URL('https://example.org/path/to/somewhere?abc=123')" |
| 156 | |
| 157 | u = URL( |
| 158 | scope={ |
| 159 | "scheme": "http", |
| 160 | "path": "/some/path", |
| 161 | "query_string": b"query=string", |
| 162 | "headers": [ |
| 163 | (b"content-type", b"text/html"), |
| 164 | (b"host", b"example.com:8000"), |
| 165 | (b"accept", b"text/html"), |
| 166 | ], |
| 167 | } |
| 168 | ) |
| 169 | assert u == "http://example.com:8000/some/path?query=string" |
| 170 | assert repr(u) == "URL('http://example.com:8000/some/path?query=string')" |
| 171 | |
| 172 | |
| 173 | @pytest.mark.parametrize( |