def test_scopes(self): response = self.client.get('/keys', headers={'Authorization': 'Key %s' % self.api_keys_scopes['read-only']}) self.assertEqual(response.status_code, 200) data = json.loads(response.data.decode('utf-8')) for key in data['keys']: self.assertEqual(self.api_keys_scopes[key['text']], key['key']) if key['text'] == 'admin': self.assertEqual('read-write', key['type']) else: self.assertEqual(key['text'], key['type']) self.assertEqual(sorted(key_helper.type_to_scopes(key['user'], key['text'])), sorted(key['scopes']))
def test_scopes(self): response = self.client.get('/keys', headers={'Authorization': 'Key %s' % self.api_keys_scopes['read-only']}) self.assertEqual(response.status_code, 200) data = json.loads(response.data.decode('utf-8')) for key in data['keys']: self.assertEqual(self.api_keys_scopes[key['text']], key['key']) if key['text'] == 'admin': self.assertEqual('read-write', key['type']) else: self.assertEqual(key['text'], key['type']) self.assertEqual(sorted(key_helper.type_to_scopes(key['user'], key['text'])), sorted(key['scopes']))
def from_document(cls, doc): return ApiKey(id=doc.get('id', None) or doc.get('_id'), key=doc.get('key', None) or doc.get('_id'), user=doc.get('user', None), scopes=doc.get('scopes', None) or key_helper.type_to_scopes(doc.get( 'user', None), doc.get('type', None)) or list(), text=doc.get('text', None), expire_time=doc.get('expireTime', None), count=doc.get('count', None), last_used_time=doc.get('lastUsedTime', None), customer=doc.get('customer', None))
def from_document(cls, doc): return ApiKey( id=doc.get('id', None) or doc.get('_id'), key=doc.get('key', None) or doc.get('_id'), user=doc.get('user', None), scopes=doc.get('scopes', None) or key_helper.type_to_scopes(doc.get('user', None), doc.get('type', None)) or list(), text=doc.get('text', None), expire_time=doc.get('expireTime', None), count=doc.get('count', None), last_used_time=doc.get('lastUsedTime', None), customer=doc.get('customer', None) )
def parse(cls, json): if not isinstance(json.get('scopes', []), list): raise ValueError('scopes must be a list') api_key = ApiKey(user=json.get('user', None), scopes=json.get('scopes', None) or list(), text=json.get('text', None), expire_time=DateTime.parse(json.get('expireTime')), customer=json.get('customer', None)) if 'type' in json: api_key.scopes = key_helper.type_to_scopes(api_key.user, json['type']) return api_key
def parse(cls, json: JSON) -> 'ApiKey': if not isinstance(json.get('scopes', []), list): raise ValueError('scopes must be a list') api_key = ApiKey( user=json.get('user', None), scopes=[Scope(s) for s in json.get('scopes', [])], text=json.get('text', None), expire_time=DateTime.parse(json['expireTime']) if 'expireTime' in json else None, customer=json.get('customer', None) ) if 'type' in json: api_key.scopes = key_helper.type_to_scopes(api_key.user, json['type']) return api_key
def parse(cls, json): if not isinstance(json.get('scopes', []), list): raise ValueError('scopes must be a list') api_key = ApiKey( user=json.get('user', None), scopes=json.get('scopes', None) or list(), text=json.get('text', None), expire_time=DateTime.parse(json.get('expireTime')), customer=json.get('customer', None) ) if 'type' in json: api_key.scopes = key_helper.type_to_scopes(api_key.user, json['type']) return api_key
def parse(cls, json: JSON) -> 'ApiKey': if not isinstance(json.get('scopes', []), list): raise ValueError('scopes must be a list') api_key = ApiKey( user=json.get('user', None), scopes=[Scope(s) for s in json.get('scopes', [])], text=json.get('text', None), expire_time=DateTime.parse(json['expireTime']) if 'expireTime' in json else None, customer=json.get('customer', None) ) if 'type' in json: api_key.scopes = key_helper.type_to_scopes(api_key.user, json['type']) return api_key