Test improvements.

This commit is contained in:
Jakub Roztocil
2014-04-25 12:18:35 +02:00
parent 27faf06327
commit af4aa3a761
6 changed files with 47 additions and 31 deletions

View File

@ -11,8 +11,10 @@ class TestAuth:
r = http('--auth=user:password', 'GET',
httpbin('/basic-auth/user/password'))
assert HTTP_OK in r
assert '"authenticated": true' in r
assert '"user": "user"' in r
assert r.json == {
'authenticated': True,
'user': 'user'
}
@pytest.mark.skipif(
requests.__version__ == '0.13.6',
@ -21,23 +23,29 @@ class TestAuth:
r = http('--auth-type=digest', '--auth=user:password', 'GET',
httpbin('/digest-auth/auth/user/password'))
assert HTTP_OK in r
assert r'"authenticated": true' in r
assert r'"user": "user"', r
assert r.json == {
'authenticated': True,
'user': 'user'
}
def test_password_prompt(self):
httpie.input.AuthCredentials._getpass = lambda self, prompt: 'password'
r = http('--auth', 'user', 'GET', httpbin('/basic-auth/user/password'))
assert HTTP_OK in r
assert '"authenticated": true' in r
assert '"user": "user"' in r
assert r.json == {
'authenticated': True,
'user': 'user'
}
def test_credentials_in_url(self):
url = httpbin('/basic-auth/user/password')
url = 'http://user:password@' + url.split('http://', 1)[1]
r = http('GET', url)
assert HTTP_OK in r
assert '"authenticated": true' in r
assert '"user": "user"' in r
assert r.json == {
'authenticated': True,
'user': 'user'
}
def test_credentials_in_url_auth_flag_has_priority(self):
"""When credentials are passed in URL and via -a at the same time,
@ -46,5 +54,7 @@ class TestAuth:
url = 'http://user:wrong_password@' + url.split('http://', 1)[1]
r = http('--auth=user:password', 'GET', url)
assert HTTP_OK in r
assert '"authenticated": true' in r
assert '"user": "user"' in r
assert r.json == {
'authenticated': True,
'user': 'user'
}