kodex-music-catalog/api-tests/test.py
2023-10-02 12:42:57 +03:00

49 lines
1.4 KiB
Python

import requests as req
class CreateItemChecks:
def createAuthor (this, result):
return 'response' in result
def invalidType (this, result):
return 'response' in result
class CreateItemActions:
def createAuthor (this):
return req.post(
"http://127.0.0.1:8080/api/v/1.0/create-item?response_format=json",
json={
"type" : "author",
"name" : "TestAuthor"
}
).json()
def invalidType (this):
return req.post(
"http://127.0.0.1:8080/api/v/1.0/create-item?response_format=json",
json={
"type" : "asdasdsad",
"name" : "TestAuthor"
}
).json()
createItemActions = CreateItemActions()
createItemChecks = CreateItemChecks()
def test (id, action, isDone, nextTest=lambda:None):
try:
print("""Test {id} runned..""")
result = action()
if isDone(result):
print("""Test {id} success!""")
nextTest()
else:
print("""Test {id} ERROR""")
print(result)
except Exception as exc:
print(exc)
test_3 = lambda : test(3, createItemActions.createAuthor, createItemChecks.createAuthor)
test_2 = lambda : test(2, createItemActions.createAuthor, createItemChecks.createAuthor)
test_1 = test(1, createItemActions.invalidType, createItemChecks.invalidType, test)