def test_token_scopes(self): from ..models import Client, Token from ..errors import ScopeDoesNotExists c = Client( client_id='dev2', client_secret='dev2', name='dev2', description='', is_confidential=False, user=self.objects[0], _redirect_uris='', _default_scopes="" ) t = Token( client=c, user=self.objects[0], token_type='bearer', access_token='dev_access', refresh_token='dev_refresh', expires=None, is_personal=False, is_internal=False, _scopes='', ) t.scopes = ['test:scope1', 'test:scope2', 'test:scope2'] self.create_objects([c, t]) self.assertEqual(t.scopes, ['test:scope1', 'test:scope2']) self.assertRaises(ScopeDoesNotExists, t.__setattr__, 'scopes', ['invalid']) self.assertEqual(t.get_visible_scopes(), ['test:scope1']) self.delete_objects([c])