4
4
5
5
import json
6
6
import pytest
7
- from unittest .mock import patch , Mock
7
+ from unittest .mock import Mock
8
8
9
9
10
10
def test_host ():
@@ -18,6 +18,7 @@ def _requests_mock_ok(method, url, **kwargs):
18
18
test_subject ._request = Mock (side_effect = _requests_mock_ok )
19
19
assert test_subject .host == 'almaexample.com'
20
20
21
+
21
22
def test_host_default ():
22
23
def _requests_mock_ok (method , url , ** kwargs ):
23
24
response = Mock ()
@@ -28,6 +29,7 @@ def _requests_mock_ok(method, url, **kwargs):
28
29
test_subject ._request = Mock (side_effect = _requests_mock_ok )
29
30
assert test_subject .host == 'asa.alma.cl'
30
31
32
+
31
33
def test_host_err ():
32
34
def _requests_mock_err (method , url , ** kwargs ):
33
35
response = Mock ()
@@ -40,14 +42,14 @@ def _requests_mock_err(method, url, **kwargs):
40
42
with pytest .raises (LoginError ):
41
43
test_subject .host
42
44
45
+
43
46
def test_login_bad_error ():
44
47
def _response_json ():
45
48
obj = {
46
49
'error' : 'Badness' ,
47
50
'error_description' : 'Something very bad'
48
51
}
49
- return obj
50
- # return json.dumps(obj, indent = 4)
52
+ return json .dumps (obj , indent = 4 )
51
53
52
54
def _requests_mock_err (method , url , ** kwargs ):
53
55
response = Mock ()
@@ -64,12 +66,13 @@ def _requests_mock_err(method, url, **kwargs):
64
66
test_subject .login ('TESTUSER' , 'TESTPASS' )
65
67
assert 'Could not log in to ALMA authorization portal' in e .value .args [0 ]
66
68
69
+
67
70
def test_login_missing_token ():
68
71
def _response_json ():
69
72
obj = {
70
73
'irrlevant' : 'Weird' ,
71
74
}
72
- return json .dumps (obj , indent = 4 )
75
+ return json .dumps (obj , indent = 4 )
73
76
74
77
def _requests_mock_err (method , url , ** kwargs ):
75
78
response = Mock ()
@@ -87,12 +90,13 @@ def _requests_mock_err(method, url, **kwargs):
87
90
88
91
assert 'No error from server, but missing access token from host' in e .value .args [0 ]
89
92
93
+
90
94
def test_login_success ():
91
95
def _response_json ():
92
96
obj = {
93
97
'access_token' : 'MYTOKEN'
94
98
}
95
- return json .dumps (obj , indent = 4 )
99
+ return json .dumps (obj , indent = 4 )
96
100
97
101
def _requests_mock_good (method , url , ** kwargs ):
98
102
response = Mock ()
0 commit comments