-
Notifications
You must be signed in to change notification settings - Fork 22
/
test_httpie_edgegrid.py
58 lines (44 loc) · 1.79 KB
/
test_httpie_edgegrid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
from test.utils import normalize_path
import pytest
from httpie_edgegrid import EdgeGridPlugin
from requests import Request
class TestHttpieEdgegrid:
_host = "https://xxxx-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx.luna.akamaiapis.net/"
@pytest.fixture
def setUp(self, request):
old_rc_path = os.getenv("RC_PATH")
os.environ["RC_PATH"] = normalize_path('testfiles/sample_edgerc')
yield
if old_rc_path:
os.environ["RC_PATH"] = old_rc_path
else:
os.unsetenv("RC_PATH")
def _test_case(self, url, expected_url, entry):
edge_grid_plugin = EdgeGridPlugin()
auth = edge_grid_plugin.get_auth(username=entry, password='')
r = Request(method="GET", url=url).prepare()
p = auth.__call__(r)
assert expected_url == str(p.url)
def test_http_to_https_conversion(self, setUp):
self._test_case("http://abc.com", "https://abc.com/", "default")
def test_localhost(self):
self._test_case("https://localhost/", self._host, "default")
@pytest.mark.parametrize(
'rc_path, exception_code',
[
('testfiles/not_existing_edgerc', 1),
('test_httpie_edgegrid.py', 2),
('testfiles/sample_edgerc_duplicated_section', 2),
('testfiles/binary', 2),
]
)
def test_bad_rc(self, rc_path, exception_code, setUp):
with pytest.raises(SystemExit) as e:
os.environ['RC_PATH'] = normalize_path(rc_path)
self._test_case("https://localhost/", self._host, "default")
assert e.value.code == exception_code
def test_bad_rc_entry(self, setUp):
with pytest.raises(SystemExit) as e:
self._test_case("https://localhost/", self._host, "not_default")
assert e.value.code == 3