88from six .moves import mock
99
1010from sasctl .core import RestObj
11-
11+ from sasctl . _services . model_repository import ModelRepository
1212
1313def test_sklearn_metadata ():
1414 pytest .importorskip ('sklearn' )
@@ -77,7 +77,7 @@ def test_parse_module_url():
7777def test_save_performance_project_types ():
7878 from sasctl .tasks import update_model_performance
7979
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 :
8181 with mock .patch ('sasctl._services.model_repository.ModelRepository.get_project' ) as project :
8282 model .return_value = RestObj (name = 'fakemodel' , projectId = 1 )
8383
@@ -98,3 +98,34 @@ def test_save_performance_project_types():
9898 update_model_performance (None , None , None )
9999
100100 # 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