Skip to content

Commit

Permalink
Jsondecodeerror not in python 3.4.
Browse files Browse the repository at this point in the history
Extends from ValueError. Thus catch ValueError instead.
  • Loading branch information
smarlowucf committed Feb 28, 2018
1 parent 22512c3 commit 7491206
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
3 changes: 1 addition & 2 deletions ipa/ipa_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import json
import os

from azure.common.client_factory import get_client_from_auth_file
Expand Down Expand Up @@ -312,7 +311,7 @@ def _get_management_client(self, client_class):
client = get_client_from_auth_file(
client_class, auth_path=self.service_account_file
)
except json.JSONDecodeError as error:
except ValueError as error:
raise AzureProviderException(
'Service account file format is invalid: {0}.'.format(error)
)
Expand Down
7 changes: 3 additions & 4 deletions tests/test_ipa_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import json
import pytest

from ipa.ipa_azure import AzureProvider
Expand Down Expand Up @@ -82,8 +81,8 @@ def test_get_management_client(self, mock_get_client):
@patch('ipa.ipa_azure.get_client_from_auth_file')
def test_get_management_client_json_error(self, mock_get_client):
client_class = MagicMock()
mock_get_client.side_effect = json.JSONDecodeError(
'Not valid', 'tests/azure/test-sa.json', 34
mock_get_client.side_effect = ValueError(
'Not valid'
)

provider = self.helper_get_provider()
Expand All @@ -92,7 +91,7 @@ def test_get_management_client_json_error(self, mock_get_client):
provider._get_management_client(client_class)

assert str(error.value) == 'Service account file format is invalid: ' \
'Not valid: line 1 column 35 (char 34).'
'Not valid.'

@patch('ipa.ipa_azure.get_client_from_auth_file')
def test_get_management_client_key_error(self, mock_get_client):
Expand Down

0 comments on commit 7491206

Please sign in to comment.