Skip to content

Commit

Permalink
tests: fix units testing for generated item barcodes
Browse files Browse the repository at this point in the history
The current units testing ensures that the timestamp of the
generated barcode equals the sysdate timestamp. This was incorrect
because the time of the item creation/barcode generation is different
from the sysdate at running the assert command.

Now we test only if the barcode starts with f-.

Co-Authored-by: Aly Badr<aly.badr@rero.ch>
  • Loading branch information
Aly Badr committed May 7, 2020
1 parent 2e65b41 commit 1355be3
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions tests/api/test_items_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,25 +113,22 @@ def test_items_post_put_delete(client, document, loc_public_martigny,
)
assert res.status_code == 201
item_barcode = data['metadata']['barcode']
assert item_barcode[0:14] == 'f-{}'.format(
datetime.now().strftime('%Y%m%d%I%M'))
assert item_barcode.startswith('f-')
# test updating an item with no barcode, keeps the old barcode
created_item = Item.get_record_by_pid('pid')
assert created_item.pid == 'pid'
item_to_update = deepcopy(created_item)
del item_to_update['barcode']
updated_item = created_item.update(
data=item_to_update, dbcommit=True, reindex=True)
assert updated_item['barcode'][0:14] == 'f-{}'.format(
datetime.now().strftime('%Y%m%d%I%M'))
assert updated_item['barcode'].startswith('f-')

# test replacing an item with no barcode, regenerates a new barcode
item_to_replace = deepcopy(updated_item)
del item_to_replace['barcode']
replaced_item = created_item.replace(
data=item_to_replace, dbcommit=True, reindex=True)
assert replaced_item['barcode'][0:14] == 'f-{}'.format(
datetime.now().strftime('%Y%m%d%I%M'))
assert replaced_item['barcode'].startswith('f-')

# test when item has a dirty barcode
item_lib_martigny_data['pid'] = '1'
Expand Down

0 comments on commit 1355be3

Please sign in to comment.