-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate_user.py
More file actions
55 lines (45 loc) · 1.41 KB
/
create_user.py
File metadata and controls
55 lines (45 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from test_registeruserandconsumer import TestRegisteruserandconsumer, logger
from time import sleep
import bootstrap_config
import requests
import json
def create_obp_user():
url = f"{bootstrap_config.obp_apihost}/obp/v5.1.0/users"
payload = json.dumps({
"email": bootstrap_config.obp_email,
"username": bootstrap_config.obp_username,
"password": bootstrap_config.obp_password,
"first_name": bootstrap_config.obp_first_name,
"last_name": bootstrap_config.obp_last_name,
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
try:
user_id = response.json().get["user_id"]
except json.JSONDecodeError as e:
logger.error(f"Failed to decode JSON response from user creation: {e}")
logger.error(f"Response content: {response.content}")
exit(1)
except KeyError as e:
logger.error(f"KeyError: {e} from user creation: {response.content}")
exit(1)
return user_id
def create_obp_user_landing_page():
client = TestRegisteruserandconsumer()
client.use_firefox()
sleep(3)
try:
client.registeruser(
bootstrap_config.obp_apihost,
bootstrap_config.obp_username,
bootstrap_config.obp_password,
bootstrap_config.obp_first_name,
bootstrap_config.obp_last_name,
bootstrap_config.obp_email)
except Exception as e:
logger.error(f"could not register the user: {e}")
finally:
client.teardown_method()
# create http client