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