def test_all_apis(self, client, token_generator):
    headers = {'content-type': 'application/json', 'authorization': f'bearer {token_generator.get_token(client)}'}
    user_ids = post_users(USERS, client, token_generator.get_token(client))
    client_ids = self._post_clients(client, user_ids, token_generator)
    role_ids = []
    for role in ROLES:
        response = client.post('/roles', data=json.dumps(role), headers=headers)
        expect(response.status_code).to(equal(201))
        role_ids.append(response.json['response'][0]['id'])
    for (i, client_id) in enumerate(client_ids):
        request_body = {'user_id': user_ids[i], 'roles': role_ids}
        response = client.patch('/clients/{}'.format(client_id), data=json.dumps(request_body), headers=headers)
        expect(response.status_code).to(equal(200))
    for client_id in client_ids:
        response = client.get('/clients/{}'.format(client_id), headers=headers)
        result = response.json['response']
        expect(result['id']).to(equal(client_id))
        expect(result['client_id_issued_at']).to(be_above(0))
        expect(user_ids).to(contain(result['user_id']))
        expect(len(result['roles'])).to(equal(len(role_ids)))
    self._cleanup(client, token_generator, user_ids=user_ids, role_ids=role_ids)
def test_all_apis(self, client, token_generator):
    headers = {'content-type': 'application/json', 'authorization': f'bearer {token_generator.get_token(client)}'}
    user_ids = post_users(USERS, client, token_generator.get_token(client))
    client_ids = self._post_clients(client, user_ids, token_generator)
    role_ids = []
    for role in ROLES:
        response = client.post('/roles', data=json.dumps(role), headers=headers)
        expect(response.status_code).to(equal(201))
        role_ids.append(response.json['response'][0]['id'])
    for (i, client_id) in enumerate(client_ids):
        request_body = {'user_id': user_ids[i], 'roles': role_ids}
        response = client.patch('/clients/{}'.format(client_id), data=json.dumps(request_body), headers=headers)
        expect(response.status_code).to(equal(200))
    for client_id in client_ids:
        response = client.get('/clients/{}'.format(client_id), headers=headers)
        result = response.json['response']
        expect(result['id']).to(equal(client_id))
        expect(result['client_id_issued_at']).to(be_above(0))
        expect(user_ids).to(contain(result['user_id']))
        expect(len(result['roles'])).to(equal(len(role_ids)))
    self._cleanup(client, token_generator, user_ids=user_ids, role_ids=role_ids)