Lägg till flera postman/newman-tester
This commit is contained in:
parent
d6e1bbd992
commit
07822f17b2
@ -151,6 +151,26 @@ def create_app(test_config: dict | None = None) -> Flask:
|
||||
|
||||
return redirect(url_for("dashboard"))
|
||||
|
||||
@app.get("/todo/get")
|
||||
def todo_get():
|
||||
with get_db(app) as conn:
|
||||
rows = conn.execute(
|
||||
"SELECT id, title, description, status, created, edited FROM todo ORDER BY id DESC"
|
||||
).fetchall()
|
||||
|
||||
todos = [
|
||||
{
|
||||
"id": r["id"],
|
||||
"title": r["title"],
|
||||
"description": r["description"],
|
||||
"status": r["status"],
|
||||
"created": r["created"],
|
||||
"edited": r["edited"],
|
||||
}
|
||||
for r in rows
|
||||
]
|
||||
return {"todos": todos}
|
||||
|
||||
return app
|
||||
|
||||
# =====================================================
|
||||
|
||||
@ -1,40 +1,45 @@
|
||||
{
|
||||
"info": {
|
||||
"name": "Todo API",
|
||||
"name": "Todo API (Newman)",
|
||||
"_postman_id": "11111111-1111-1111-1111-111111111111",
|
||||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
||||
},
|
||||
"item": [
|
||||
|
||||
{
|
||||
"name": "GET dashboard",
|
||||
"name": "Set unique title + dashboard ok",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "{{baseUrl}}/dashboard"
|
||||
},
|
||||
"event": [
|
||||
{
|
||||
"listen": "prerequest",
|
||||
"script": {
|
||||
"exec": [
|
||||
"pm.environment.set('title', 'Newman Todo ' + Date.now());"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"exec": [
|
||||
"pm.test('status 200', function () {",
|
||||
" pm.response.to.have.status(200);",
|
||||
"});"
|
||||
"pm.test('dashboard returns 200', () => pm.response.to.have.status(200));"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"name": "POST create todo",
|
||||
"name": "Create todo",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{ "key": "Content-Type", "value": "application/x-www-form-urlencoded" }
|
||||
],
|
||||
"body": {
|
||||
"mode": "urlencoded",
|
||||
"urlencoded": [
|
||||
{ "key": "title", "value": "Newman todo", "type": "text" },
|
||||
{ "key": "title", "value": "{{title}}", "type": "text" },
|
||||
{ "key": "description", "value": "Created by newman", "type": "text" },
|
||||
{ "key": "status", "value": "not-started", "type": "text" }
|
||||
]
|
||||
@ -46,13 +51,157 @@
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"exec": [
|
||||
"pm.test('status is 200 or redirect', function () {",
|
||||
"pm.test('title is set', () => {",
|
||||
" pm.expect(pm.environment.get('title')).to.be.ok;",
|
||||
"});",
|
||||
"pm.test('create returns 200 or 302', () => {",
|
||||
" pm.expect([200, 302]).to.include(pm.response.code);",
|
||||
"});"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"name": "Find created todo id (todo/get)",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "{{baseUrl}}/todo/get"
|
||||
},
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"exec": [
|
||||
"pm.test('todo/get returns 200', () => pm.response.to.have.status(200));",
|
||||
"var body = pm.response.json();",
|
||||
"pm.expect(body).to.have.property('todos');",
|
||||
"var title = pm.environment.get('title');",
|
||||
"var found = body.todos.find(t => t.title === title);",
|
||||
"pm.expect(found, 'created todo should exist').to.be.ok;",
|
||||
"pm.environment.set('todo_id', String(found.id));",
|
||||
"pm.test('todo_id saved', () => {",
|
||||
" pm.expect(pm.environment.get('todo_id')).to.be.ok;",
|
||||
"});"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"name": "Update status to done",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{ "key": "Content-Type", "value": "application/x-www-form-urlencoded" }
|
||||
],
|
||||
"body": {
|
||||
"mode": "urlencoded",
|
||||
"urlencoded": [
|
||||
{ "key": "status", "value": "done", "type": "text" }
|
||||
]
|
||||
},
|
||||
"url": "{{baseUrl}}/todo/{{todo_id}}/status"
|
||||
},
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"exec": [
|
||||
"pm.test('todo_id exists', () => {",
|
||||
" pm.expect(pm.environment.get('todo_id')).to.be.ok;",
|
||||
"});",
|
||||
"",
|
||||
"pm.test('update returns 200 or 302', () => {",
|
||||
" pm.expect([200, 302]).to.include(pm.response.code);",
|
||||
"});"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"name": "Verify status is done (todo/get)",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "{{baseUrl}}/todo/get"
|
||||
},
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"exec": [
|
||||
"pm.test('todo/get returns 200', () => pm.response.to.have.status(200));",
|
||||
"",
|
||||
"var body2 = pm.response.json();",
|
||||
"var id2 = pm.environment.get('todo_id');",
|
||||
"pm.expect(id2, 'todo_id should be set').to.be.ok;",
|
||||
"",
|
||||
"var found2 = body2.todos.find(t => String(t.id) === String(id2));",
|
||||
"pm.expect(found2, 'todo should exist').to.be.ok;",
|
||||
"",
|
||||
"pm.test('status is done', () => {",
|
||||
" pm.expect(found2.status).to.eql('done');",
|
||||
"});"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"name": "Delete todo",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "{{baseUrl}}/todo/{{todo_id}}/delete"
|
||||
},
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"exec": [
|
||||
"pm.test('todo_id exists', () => {",
|
||||
" pm.expect(pm.environment.get('todo_id')).to.be.ok;",
|
||||
"});",
|
||||
"",
|
||||
"pm.test('delete returns 200 or 302', () => {",
|
||||
" pm.expect([200, 302]).to.include(pm.response.code);",
|
||||
"});"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"name": "Verify todo removed (todo/get)",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "{{baseUrl}}/todo/get"
|
||||
},
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"exec": [
|
||||
"pm.test('todo/get returns 200', () => pm.response.to.have.status(200));",
|
||||
"",
|
||||
"var body3 = pm.response.json();",
|
||||
"var id3 = pm.environment.get('todo_id');",
|
||||
"pm.expect(id3, 'todo_id should be set').to.be.ok;",
|
||||
"",
|
||||
"var found3 = body3.todos.find(t => String(t.id) === String(id3));",
|
||||
"",
|
||||
"pm.test('todo is deleted', () => {",
|
||||
" pm.expect(found3).to.not.be.ok;",
|
||||
"});"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
"id": "22222222-2222-2222-2222-222222222222",
|
||||
"name": "local",
|
||||
"values": [
|
||||
{ "key": "baseUrl", "value": "http://127.0.0.1:5001", "enabled": true }
|
||||
{ "key": "baseUrl", "value": "http://127.0.0.1:5001", "enabled": true },
|
||||
{ "key": "title", "value": "", "enabled": true },
|
||||
{ "key": "todo_id", "value": "", "enabled": true }
|
||||
]
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user