fixes for python api
This commit is contained in:
parent
2ede168518
commit
d68abec2e5
70
tests/api.py
70
tests/api.py
@ -21,7 +21,7 @@ class User():
|
||||
name: string
|
||||
password: string
|
||||
|
||||
def __init__(self, email, password, name, token = ""):
|
||||
def __init__(self, email, password, name, id="", token = ""):
|
||||
self.email = email
|
||||
self.password = password
|
||||
self.name = name
|
||||
@ -32,45 +32,49 @@ class BackendApi():
|
||||
def __init__(self, httpClient):
|
||||
self.httpClient = httpClient
|
||||
|
||||
def user_create(self) -> User:
|
||||
email = ''.join(random.choices(string.ascii_lowercase + string.digits, k=10)) + '@test.test'
|
||||
name = ''.join(random.choices(string.ascii_letters, k=10))
|
||||
password = 'Abcdef1!!1'
|
||||
def parse_response(self, response):
|
||||
if response.status != 200:
|
||||
raise AssertionError('something wrong')
|
||||
|
||||
response = self.httpClient.post(
|
||||
"/v1/user/create",
|
||||
json={
|
||||
"email": email,
|
||||
"password": password,
|
||||
"name": name,
|
||||
},
|
||||
json = response.json()
|
||||
if json['status'] == 'success':
|
||||
if 'result' in json:
|
||||
return json['result']
|
||||
return None
|
||||
|
||||
error = json['error']
|
||||
raise AssertionError(error['id'], error['message'])
|
||||
|
||||
def user_create(self, user: User | None) -> User:
|
||||
if user == None:
|
||||
email = ''.join(random.choices(string.ascii_lowercase + string.digits, k=10)) + '@test.test'
|
||||
name = ''.join(random.choices(string.ascii_letters, k=10))
|
||||
password = 'Abcdef1!!1'
|
||||
user = User(email, password, name)
|
||||
|
||||
res = self.parse_response(
|
||||
self.httpClient.post(
|
||||
"/v1/user/create", json={
|
||||
"email": user.email,
|
||||
"password": user.password,
|
||||
"name": user.name,
|
||||
}
|
||||
)
|
||||
)
|
||||
if response.status_code != 200:
|
||||
raise AssertionError('can not create user')
|
||||
|
||||
return User(email, password, name)
|
||||
return User(res['email'], res['password'], res['name'], res['id'])
|
||||
|
||||
def user_login(self, user: User) -> Auth:
|
||||
response = self.httpClient.post(
|
||||
"/v1/user/login",
|
||||
json={
|
||||
"email": user.email+"a",
|
||||
"password": user.password,
|
||||
},
|
||||
res = self.parse_response(
|
||||
self.httpClient.post(
|
||||
"/v1/user/login", json={
|
||||
"email": user.email+"a",
|
||||
"password": user.password,
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
status = response.json()['status']
|
||||
if status == 'error':
|
||||
raise AssertionError(response.json()['error']['message'])
|
||||
|
||||
if response.status_code != 200:
|
||||
raise AssertionError('can not login user')
|
||||
|
||||
token = response.json()['result']['token']
|
||||
if token == '':
|
||||
raise AssertionError('empty user token')
|
||||
|
||||
return Auth(token)
|
||||
return Auth(res['status'])
|
||||
|
||||
def dummy_get(self, auth: Auth):
|
||||
headers = {"X-Auth": auth.token}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user