remove prefix

This commit is contained in:
2025-03-25 22:38:30 -03:00
parent cd6fdd58ad
commit 02f0b317ae
4 changed files with 186 additions and 43 deletions

View File

@@ -12,6 +12,7 @@ from layercake.dynamodb import (
KeyPair,
MissingError,
PartitionKey,
PrefixKey,
TransactItems,
serialize,
)
@@ -34,7 +35,11 @@ def test_serialize():
def test_composekey():
assert ComposeKey(('122', 'abc'), prefix='schedules') == 'schedules#122#abc'
key = ComposeKey(('122', 'abc'), prefix='schedules', delimiter=':')
assert key == 'schedules:122:abc'
assert key.prefix == 'schedules'
assert key.delimiter == ':'
assert ComposeKey(('122', 'abc')) == '122#abc'
assert ComposeKey('122') == '122'
@@ -51,6 +56,12 @@ def test_keypair():
assert KeyPair('123', 'abc').expr_attr_values() == {':pk': '123', ':sk': 'abc'}
def test_prefixkey():
key = PrefixKey('emails')
assert key == 'emails'
assert isinstance(key, PrefixKey)
def test_transact_write_items(
dynamodb_seeds,
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
@@ -63,7 +74,10 @@ def test_transact_write_items(
cond_expr='attribute_not_exists(sk)',
)
transact.put(
item=KeyPair('5OxmMjL-ujoR5IMGegQz', 'emails#sergio@somosbeta.com.br'),
item=KeyPair(
'5OxmMjL-ujoR5IMGegQz',
ComposeKey('sergio@somosbeta.com.br', prefix='emails'),
),
cond_expr='attribute_not_exists(sk)',
)
@@ -163,3 +177,22 @@ def test_collection_get_items(
),
)
assert len(data['items']) == 2
# This data was added from seeds
data = collect.get_items(
KeyPair('5OxmMjL-ujoR5IMGegQz', PrefixKey('emails#')),
)
assert data == {
'items': [
{
'email_verified': True,
'mx_record_exists': True,
'sk': 'sergio@somosbeta.com.br', # Removed prefix from Sort Key
'email_primary': True,
'id': '5OxmMjL-ujoR5IMGegQz',
'create_date': '2019-03-25T00:00:00-03:00',
'update_date': '2023-11-09T12:13:04.308986-03:00',
}
],
'last_key': None,
}