8
8
from six .moves import mock
9
9
10
10
from sasctl .core import RestObj
11
-
11
+ from sasctl . _services . model_repository import ModelRepository
12
12
13
13
def test_sklearn_metadata ():
14
14
pytest .importorskip ('sklearn' )
@@ -77,7 +77,7 @@ def test_parse_module_url():
77
77
def test_save_performance_project_types ():
78
78
from sasctl .tasks import update_model_performance
79
79
80
- with mock .patch ('sasctl._services.model_repository.ModelRepository' ' .get_model' ) as model :
80
+ with mock .patch ('sasctl._services.model_repository.ModelRepository.get_model' ) as model :
81
81
with mock .patch ('sasctl._services.model_repository.ModelRepository.get_project' ) as project :
82
82
model .return_value = RestObj (name = 'fakemodel' , projectId = 1 )
83
83
@@ -98,3 +98,34 @@ def test_save_performance_project_types():
98
98
update_model_performance (None , None , None )
99
99
100
100
# Check projects w/ invalid properties
101
+
102
+
103
+ @mock .patch .object (ModelRepository , 'get_repository' )
104
+ @mock .patch .object (ModelRepository , 'get_project' )
105
+ def test_register_model_403_error (get_project , get_repository ):
106
+ """Verify HTTP 403 is converted to a user-friendly error.
107
+
108
+ Depending on environment configuration, this can happen when attempting to
109
+ find a repository.
110
+
111
+ See: https://github.com/sassoftware/python-sasctl/issues/39
112
+ """
113
+
114
+ from six .moves .urllib .error import HTTPError
115
+ from sasctl .exceptions import AuthorizationError
116
+ from sasctl .tasks import register_model
117
+
118
+ get_project .return_value = {'name' : 'Project Name' }
119
+ get_repository .side_effect = HTTPError (None , 403 , None , None , None )
120
+
121
+ # HTTP 403 error when getting repository should throw a user-friendly
122
+ # AuthorizationError
123
+ with pytest .raises (AuthorizationError ):
124
+ register_model (None , 'model name' , 'project name' )
125
+
126
+ # All other errors should be bubbled up
127
+ get_repository .side_effect = HTTPError (None , 404 , None , None , None )
128
+ with pytest .raises (HTTPError ):
129
+ register_model (None , 'model name' , 'project name' )
130
+
131
+
0 commit comments