|
2 | 2 | :copyright: © 2020 by the Lin team. |
3 | 3 | :license: MIT, see LICENSE for more details. |
4 | 4 | """ |
5 | | -from . import app, get_token |
| 5 | +import pytest |
6 | 6 |
|
| 7 | +from . import app, fixtureFunc, get_token |
7 | 8 |
|
8 | | -def test_a_create(): |
| 9 | + |
| 10 | +@pytest.mark.run(order=1) |
| 11 | +def test_create(fixtureFunc): |
9 | 12 | with app.test_client() as c: |
10 | 13 | rv = c.post( |
11 | 14 | "/v1/book", |
| 15 | + headers={"Authorization": "Bearer " + get_token()}, |
12 | 16 | json={ |
13 | 17 | "title": "create", |
14 | 18 | "author": "pedro", |
15 | | - "summary": "在写这章之前,笔者一直很踌躇,因为我并没有多年的开发经验,甚至是一年都没有。换言之,我还没有一个良好的软件开发习惯,没有一个标准的开发约束,如果你和我一样,那么请你一定要仔细阅读本小节,并且开始尝试认真,仔细的做单测,它将会让你受益匪浅。", |
| 19 | + "summary": "summary", |
16 | 20 | "image": "https://img3.doubanio.com/lpic/s1470003.jpg", |
17 | 21 | }, |
18 | 22 | ) |
19 | 23 | assert rv.status_code == 201 or rv.get_json().get("code") == 10030 |
20 | 24 |
|
21 | 25 |
|
22 | | -def test_b_get_books(): |
| 26 | +@pytest.mark.run(order=2) |
| 27 | +def test_get_books(): |
23 | 28 | with app.test_client() as c: |
24 | | - rv = c.get("/v1/book", headers={"Authorization": "Bearer " + get_token()}) |
| 29 | + rv = c.get("/v1/book", headers={"Authorization": "Bearer "}) |
25 | 30 | assert rv.status_code == 200 |
26 | 31 |
|
27 | 32 |
|
28 | | -def test_c_update(): |
| 33 | +@pytest.mark.run(order=3) |
| 34 | +def test_update(fixtureFunc): |
29 | 35 | with app.test_client() as c: |
| 36 | + id = ( |
| 37 | + c.get("/v1/book", headers={"Authorization": "Bearer "}) |
| 38 | + .get_json()[-1] |
| 39 | + .get("id") |
| 40 | + ) |
30 | 41 | rv = c.put( |
31 | | - "/v1/book/1", |
| 42 | + "/v1/book/{}".format(id), |
| 43 | + headers={"Authorization": "Bearer " + get_token()}, |
32 | 44 | json={ |
33 | 45 | "title": "update", |
34 | 46 | "author": "pedro & erik", |
35 | | - "summary": "在写这章之前,笔者一直很踌躇,因为我并没有多年的开发经验,甚至是一年都没有。换言之,我还没有一个良好的软件开发习惯,没有一个标准的开发约束,如果你和我一样", |
| 47 | + "summary": "summary", |
36 | 48 | "image": "https://img3.doubanio.com/lpic/s1470003.jpg", |
37 | 49 | }, |
38 | 50 | ) |
39 | 51 | assert rv.status_code == 201 |
40 | 52 |
|
41 | 53 |
|
42 | | -def test_d_delete(): |
| 54 | +@pytest.mark.run(order=4) |
| 55 | +def test_delete(): |
43 | 56 | with app.test_client() as c: |
44 | | - rv = c.delete("/v1/book/1", headers={"Authorization": "Bearer " + get_token()}) |
| 57 | + id = ( |
| 58 | + c.get("/v1/book", headers={"Authorization": "Bearer "}) |
| 59 | + .get_json()[-1] |
| 60 | + .get("id") |
| 61 | + ) |
| 62 | + rv = c.delete( |
| 63 | + "/v1/book/{}".format(id), headers={"Authorization": "Bearer " + get_token()} |
| 64 | + ) |
45 | 65 | assert rv.status_code == 201 |
0 commit comments