|
| 1 | +import pytest |
| 2 | + |
| 3 | + |
| 4 | +@pytest.mark.parametrize( |
| 5 | + "examples_client", [["complete_db", "create_app"]], indirect=True |
| 6 | +) |
| 7 | +def test_complete(examples_client): |
| 8 | + r = examples_client.post( |
| 9 | + "/v1/authors", |
| 10 | + json=dict( |
| 11 | + name="asdf", |
| 12 | + ), |
| 13 | + ) |
| 14 | + assert r.status_code == 201 |
| 15 | + assert r.json["name"] == "asdf" |
| 16 | + |
| 17 | + r = examples_client.post( |
| 18 | + "/v1/authors", |
| 19 | + json=dict( |
| 20 | + name="qwer", |
| 21 | + ), |
| 22 | + ) |
| 23 | + assert r.status_code == 201 |
| 24 | + assert r.json["name"] == "qwer" |
| 25 | + |
| 26 | + r = examples_client.get("/v1/authors") |
| 27 | + assert r.status_code == 200 |
| 28 | + assert len(r.json["items"]) == 2 |
| 29 | + |
| 30 | + r = examples_client.post( |
| 31 | + "/v1/books", |
| 32 | + json=dict( |
| 33 | + author_id=1, |
| 34 | + title="asdf 1", |
| 35 | + year=1982, |
| 36 | + description="asdf1 asdf1 asdf1", |
| 37 | + ), |
| 38 | + ) |
| 39 | + assert r.status_code == 201 |
| 40 | + |
| 41 | + r = examples_client.post( |
| 42 | + "/v1/books", |
| 43 | + json=dict( |
| 44 | + author_id=1, |
| 45 | + title="asdf 2", |
| 46 | + year=1982, |
| 47 | + description="asdf2 asdf2 asdf2", |
| 48 | + ), |
| 49 | + ) |
| 50 | + assert r.status_code == 201 |
| 51 | + |
| 52 | + r = examples_client.post( |
| 53 | + "/v1/books", |
| 54 | + json=dict( |
| 55 | + author_id=2, |
| 56 | + title="asdf 3", |
| 57 | + year=1982, |
| 58 | + description="asdf3 asdf3 asdf3", |
| 59 | + ), |
| 60 | + ) |
| 61 | + assert r.status_code == 201 |
| 62 | + |
| 63 | + r = examples_client.post( |
| 64 | + "/v1/books", |
| 65 | + json=dict( |
| 66 | + year=1982, |
| 67 | + ), |
| 68 | + ) |
| 69 | + assert r.status_code == 400 |
| 70 | + assert r.json["source"] == "body" |
| 71 | + |
| 72 | + r = examples_client.get("/v1/books") |
| 73 | + assert r.status_code == 200 |
| 74 | + assert len(r.json["items"]) == 3 |
| 75 | + |
| 76 | + r = examples_client.get("/v1/authors/1/books") |
| 77 | + assert r.status_code == 200 |
| 78 | + assert len(r.json["items"]) == 2 |
| 79 | + |
| 80 | + r = examples_client.get("/v1/books/1") |
| 81 | + assert r.status_code == 200 |
| 82 | + assert r.json["id"] == 1 |
| 83 | + assert r.json["title"] == "asdf 1" |
| 84 | + |
| 85 | + r = examples_client.get("/v1/books/asdf") |
| 86 | + assert r.status_code == 400 |
| 87 | + assert r.json["source"] == "kwargs" |
| 88 | + |
| 89 | + r = examples_client.patch( |
| 90 | + "/v1/books/1", |
| 91 | + json=dict( |
| 92 | + title="something else", |
| 93 | + ), |
| 94 | + ) |
| 95 | + assert r.status_code == 200 |
| 96 | + assert r.json["title"] == "something else" |
| 97 | + |
| 98 | + r = examples_client.get("/v1/books/1") |
| 99 | + assert r.status_code == 200 |
| 100 | + assert r.json["id"] == 1 |
| 101 | + assert r.json["title"] == "something else" |
| 102 | + assert r.json["description"] == "asdf1 asdf1 asdf1" |
| 103 | + |
| 104 | + r = examples_client.put( |
| 105 | + "/v1/books/1", |
| 106 | + json=dict( |
| 107 | + title="zxcv", |
| 108 | + ), |
| 109 | + ) |
| 110 | + assert r.status_code == 400 |
| 111 | + |
| 112 | + r = examples_client.put( |
| 113 | + "/v1/books/1", |
| 114 | + json=dict( |
| 115 | + title="zxcv", |
| 116 | + year=1983, |
| 117 | + description="zxcv zxcv zxcv", |
| 118 | + ), |
| 119 | + ) |
| 120 | + assert r.status_code == 200 |
| 121 | + |
| 122 | + r = examples_client.get("/v1/books/1") |
| 123 | + assert r.status_code == 200 |
| 124 | + assert r.json["id"] == 1 |
| 125 | + assert r.json["title"] == "zxcv" |
| 126 | + assert r.json["year"] == 1983 |
| 127 | + assert r.json["description"] == "zxcv zxcv zxcv" |
| 128 | + |
| 129 | + r = examples_client.delete("/v1/books/1") |
| 130 | + assert r.status_code == 200 |
| 131 | + |
| 132 | + r = examples_client.get("/v1/books/1") |
| 133 | + assert r.status_code == 404 |
0 commit comments