generated from mlibrary/python-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved fastapi to digifeeds/database; add tests for crud methods
- Loading branch information
Showing
13 changed files
with
78 additions
and
22 deletions.
There are no files selected for viewing
Empty file.
Empty file.
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
File renamed without changes.
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 was deleted.
Oops, something went wrong.
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
Empty file.
Empty file.
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,66 @@ | ||
from aim.digifeeds.database.crud import ( | ||
get_item, | ||
get_items, | ||
add_item, | ||
get_status, | ||
get_statuses, | ||
add_item_status | ||
) | ||
from aim.digifeeds.database.schemas import ItemCreate | ||
|
||
class TestCrud: | ||
def test_get_item(self, db_session): | ||
item = add_item(db=db_session, item=ItemCreate(barcode="valid_barcode")) | ||
barcode = item.barcode | ||
item_in_db = get_item(barcode=barcode, db=db_session) | ||
assert(item_in_db.barcode) == "valid_barcode" | ||
|
||
def test_get_item_that_does_not_exist(self, db_session): | ||
item_in_db = get_item(barcode="does not exist", db=db_session) | ||
assert(item_in_db) == None | ||
|
||
def test_get_items_all(self, db_session): | ||
item1 = add_item(db=db_session, item=ItemCreate(barcode="valid_barcode")) | ||
item2 = add_item(db=db_session, item=ItemCreate(barcode="valid_barcode2")) | ||
status = get_status(db=db_session, name="in_zephir") | ||
add_item_status(db=db_session,item=item1, status=status) | ||
items = get_items(db=db_session, in_zephir=None) | ||
db_session.refresh(item1) | ||
db_session.refresh(item2) | ||
assert(items[0]) == item1 | ||
assert(items[1]) == item2 | ||
|
||
def test_get_items_in_zephir(self, db_session): | ||
item1 = add_item(db=db_session, item=ItemCreate(barcode="valid_barcode")) | ||
item2 = add_item(db=db_session, item=ItemCreate(barcode="valid_barcode2")) | ||
status = get_status(db=db_session, name="in_zephir") | ||
add_item_status(db=db_session,item=item1, status=status) | ||
items = get_items(db=db_session, in_zephir=True) | ||
db_session.refresh(item1) | ||
db_session.refresh(item2) | ||
assert(len(items)) == 1 | ||
assert(items[0]) == item1 | ||
|
||
def test_get_items_not_in_zephir(self, db_session): | ||
item1 = add_item(db=db_session, item=ItemCreate(barcode="valid_barcode")) | ||
item2 = add_item(db=db_session, item=ItemCreate(barcode="valid_barcode2")) | ||
status = get_status(db=db_session, name="in_zephir") | ||
add_item_status(db=db_session,item=item1, status=status) | ||
items = get_items(db=db_session, in_zephir=False) | ||
db_session.refresh(item1) | ||
db_session.refresh(item2) | ||
assert(len(items)) == 1 | ||
assert(items[0]) == item2 | ||
|
||
def test_get_status_that_exists(self, db_session): | ||
status = get_status(db=db_session, name="in_zephir") | ||
assert(status.name) == "in_zephir" | ||
|
||
def test_get_status_that_does_not_exist(self, db_session): | ||
status = get_status(db=db_session, name="does_not_exist") | ||
assert(status) == None | ||
|
||
def test_get_statuses(self, db_session): | ||
statuses = get_statuses(db=db_session) | ||
assert(len(statuses)) > 1 | ||
assert(statuses[0].name) == "in_zephir" |
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 was deleted.
Oops, something went wrong.