-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from jsangmeister/fix-create-reserve-ids
Adjust id_sequences on create events
- Loading branch information
Showing
6 changed files
with
100 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import copy | ||
|
||
import pytest | ||
|
||
from shared.tests.util import assert_response_code | ||
from writer.flask_frontend.routes import RESERVE_IDS_URL, WRITE_URL | ||
|
||
|
||
@pytest.fixture() | ||
def data(): | ||
yield copy.deepcopy( | ||
{ | ||
"user_id": 1, | ||
"information": {}, | ||
"locked_fields": {}, | ||
"events": [{"type": "create", "fqid": "a/1", "fields": {"f": 1}}], | ||
} | ||
) | ||
|
||
|
||
def test_create_reserve(json_client, data, db_cur): | ||
response = json_client.post(WRITE_URL, data) | ||
assert_response_code(response, 201) | ||
|
||
response = json_client.post(RESERVE_IDS_URL, {"amount": 1, "collection": "a"}) | ||
assert response.status_code == 200 | ||
|
||
assert response.json == {"ids": [2]} | ||
|
||
db_cur.execute("select * from id_sequences") | ||
result = db_cur.fetchall() | ||
assert result == [("a", 3)] | ||
|
||
|
||
def test_reserve_create(json_client, data, db_cur): | ||
response = json_client.post(RESERVE_IDS_URL, {"amount": 5, "collection": "a"}) | ||
assert_response_code(response, 200) | ||
assert response.json == {"ids": [1, 2, 3, 4, 5]} | ||
|
||
db_cur.execute("select * from id_sequences") | ||
result = db_cur.fetchall() | ||
assert result == [("a", 6)] | ||
|
||
response = json_client.post(WRITE_URL, data) | ||
assert_response_code(response, 201) | ||
|
||
db_cur.execute("select * from id_sequences") | ||
result = db_cur.fetchall() | ||
assert result == [("a", 6)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters