Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions syncano/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ class SyncanoDoesNotExist(SyncanoException):

class RevisionMismatchException(SyncanoRequestError):
"""Revision do not match with expected one"""


class UserNotFound(SyncanoRequestError):
"""Special error to handle user not found case."""
11 changes: 9 additions & 2 deletions syncano/models/accounts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from syncano.exceptions import SyncanoValueError
from syncano.exceptions import SyncanoRequestError, SyncanoValueError, UserNotFound

from . import fields
from .base import Model
Expand Down Expand Up @@ -214,7 +214,14 @@ def _group_users_method(self, user_id=None, method='GET'):
if user_id is not None:
endpoint += '{}/'.format(user_id)
connection = self._get_connection()
return connection.request(method, endpoint)
try:
response = connection.request(method, endpoint)
except SyncanoRequestError as e:
if e.status_code == 404:
raise UserNotFound(e.status_code, 'User not found.')
raise

return response

def list_users(self):
return self._group_users_method()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from syncano.exceptions import UserNotFound
from syncano.models import User
from tests.integration_test import InstanceMixin, IntegrationTest

Expand Down Expand Up @@ -39,3 +40,18 @@ def test_profile_change_schema(self):
self.user.profile.save()
user = User.please.get(id=self.user.id)
self.assertEqual(user.profile.profile_pic, self.SAMPLE_PROFILE_PIC)


class UserTest(InstanceMixin, IntegrationTest):

@classmethod
def setUpClass(cls):
super(UserTest, cls).setUpClass()

cls.group = cls.instance.groups.create(
label='testgroup'
)

def test_if_custom_error_is_raised_on_user_group(self):
with self.assertRaises(UserNotFound):
self.group.user_details(user_id=221)