14198: Federation feature and testing
[arvados.git] / sdk / cwl / tests / federation / framework / setup_user.py
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
5 import arvados
6 import arvados.errors
7 import time
8 import json
9
10 while True:
11     try:
12         api = arvados.api()
13         break
14     except arvados.errors.ApiError:
15         time.sleep(2)
16
17 existing = api.users().list(filters=[["email", "=", "test@example.com"],
18                                      ["is_active", "=", True]], limit=1).execute()
19 if existing["items"]:
20     u = existing["items"][0]
21 else:
22     u = api.users().create(body={
23         'first_name': 'Test',
24         'last_name': 'User',
25         'email': 'test@example.com',
26         'is_admin': False
27     }).execute()
28     api.users().activate(uuid=u["uuid"]).execute()
29
30 tok = api.api_client_authorizations().create(body={
31     "api_client_authorization": {
32         "owner_uuid": u["uuid"]
33     }
34 }).execute()
35
36 with open("cwl.output.json", "w") as f:
37     json.dump({
38         "test_user_uuid": u["uuid"],
39         "test_user_token": "v2/%s/%s" % (tok["uuid"], tok["api_token"])
40     }, f)