add partition key to env var
This commit is contained in:
@@ -1,2 +1,4 @@
|
||||
{"update_date": {"S": "2024-02-08T16:42:33.776409-03:00"}, "create_date": {"S": "2019-03-25T00:00:00-03:00"}, "email_verified": {"BOOL": true}, "cognito:sub": {"S": "58efed8d-d276-41a8-8502-4ab8b5a6415e"}, "cpf": {"S": "07879819908"}, "sk": {"S": "0"}, "email": {"S": "sergio@somosbeta.com.br"}, "id": {"S": "5OxmMjL-ujoR5IMGegQz"}, "name": {"S": "S\u00e9rgio Rafael de Siqueira"}, "last_login": {"S": "2024-02-08T20:53:45.818126-03:00"}, "tenant:org_id": {"L": [{"S": "cJtK9SsnJhKPyxESe7g3DG"}, {"S": "edp8njvgQuzNkLx2ySNfAD"}, {"S": "8TVSi5oACLxTiT8ycKPmaQ"}]}}
|
||||
{"email_verified": {"BOOL": true}, "update_date": {"S": "2024-02-08T16:42:33.776409-03:00"}, "create_date": {"S": "2019-03-25T00:00:00-03:00"}, "sk": {"S": "emails#sergio@somosbeta.com.br"}, "id": {"S": "5OxmMjL-ujoR5IMGegQz"}, "email_primary": {"BOOL": true}, "mx_record_exists": {"BOOL": true}, "update_date": {"S": "2023-11-09T12:13:04.308986-03:00"}}
|
||||
{"id": {"S": "5OxmMjL-ujoR5IMGegQz"}, "sk": {"S": "0"}, "update_date": {"S": "2024-02-08T16:42:33.776409-03:00"}, "create_date": {"S": "2019-03-25T00:00:00-03:00"}, "email_verified": {"BOOL": true}, "cognito:sub": {"S": "58efed8d-d276-41a8-8502-4ab8b5a6415e"}, "cpf": {"S": "07879819908"}, "email": {"S": "sergio@somosbeta.com.br"}, "name": {"S": "S\u00e9rgio Rafael de Siqueira"}, "last_login": {"S": "2024-02-08T20:53:45.818126-03:00"}, "tenant:org_id": {"L": [{"S": "cJtK9SsnJhKPyxESe7g3DG"}, {"S": "edp8njvgQuzNkLx2ySNfAD"}, {"S": "8TVSi5oACLxTiT8ycKPmaQ"}]}}
|
||||
{"id": {"S": "5OxmMjL-ujoR5IMGegQz"}, "sk": {"S": "emails#sergio@somosbeta.com.br"}, "email_verified": {"BOOL": true}, "update_date": {"S": "2024-02-08T16:42:33.776409-03:00"}, "create_date": {"S": "2019-03-25T00:00:00-03:00"}, "email_primary": {"BOOL": true}, "mx_record_exists": {"BOOL": true}, "update_date": {"S": "2023-11-09T12:13:04.308986-03:00"}}
|
||||
{"id": {"S": "logs#5OxmMjL-ujoR5IMGegQz"}, "sk": {"S": "2024-02-08T16:42:33.776409-03:00"}, "action": {"S": "OPEN_EMAIL"}}
|
||||
{"id": {"S": "logs#5OxmMjL-ujoR5IMGegQz"}, "sk": {"S": "2019-03-25T00:00:00-03:00"}, "action": {"S": "CLICK_EMAIL"}}
|
||||
|
||||
@@ -6,10 +6,11 @@ from botocore.exceptions import ClientError
|
||||
|
||||
from layercake.dateutils import ttl
|
||||
from layercake.dynamodb import (
|
||||
ComposeKey,
|
||||
DynamoDBCollection,
|
||||
DynamoDBPersistenceLayer,
|
||||
Key,
|
||||
KeyPair,
|
||||
PartitionKey,
|
||||
TransactItems,
|
||||
serialize,
|
||||
)
|
||||
@@ -31,12 +32,22 @@ def test_serialize():
|
||||
}
|
||||
|
||||
|
||||
def test_key():
|
||||
assert Key(('122', 'abc'), prefix='schedules') == 'schedules#122#abc'
|
||||
def test_composekey():
|
||||
assert ComposeKey(('122', 'abc'), prefix='schedules') == 'schedules#122#abc'
|
||||
assert ComposeKey(('122', 'abc')) == '122#abc'
|
||||
assert ComposeKey('122') == '122'
|
||||
|
||||
|
||||
def test_partitionkey():
|
||||
assert PartitionKey('123') == {'id': '123'}
|
||||
assert PartitionKey('123').expr_attr_name() == {'#pk': 'id'}
|
||||
assert PartitionKey('123').expr_attr_values() == {':pk': '123'}
|
||||
|
||||
|
||||
def test_keypair():
|
||||
assert KeyPair('123', 'abc') == {'id': '123', 'sk': 'abc'}
|
||||
assert KeyPair('123', 'abc').expr_attr_name() == {'#pk': 'id', '#sk': 'sk'}
|
||||
assert KeyPair('123', 'abc').expr_attr_values() == {':pk': '123', ':sk': 'abc'}
|
||||
|
||||
|
||||
def test_transact_write_items(
|
||||
@@ -65,7 +76,7 @@ def test_collection_get_item(
|
||||
):
|
||||
collect = DynamoDBCollection(dynamodb_persistence_layer)
|
||||
data_notfound = collect.get_item(
|
||||
key=KeyPair(
|
||||
KeyPair(
|
||||
pk='5OxmMjL-ujoR5IMGegQz',
|
||||
sk='tenant',
|
||||
),
|
||||
@@ -76,9 +87,9 @@ def test_collection_get_item(
|
||||
|
||||
# This item was added from seeds
|
||||
data = collect.get_item(
|
||||
key=KeyPair(
|
||||
KeyPair(
|
||||
pk='5OxmMjL-ujoR5IMGegQz',
|
||||
sk=Key('sergio@somosbeta.com.br', prefix='emails'),
|
||||
sk=ComposeKey('sergio@somosbeta.com.br', prefix='emails'),
|
||||
),
|
||||
default={},
|
||||
)
|
||||
@@ -102,18 +113,18 @@ def test_collection_put_item(
|
||||
collect = DynamoDBCollection(dynamodb_persistence_layer)
|
||||
|
||||
assert collect.put_item(
|
||||
key=KeyPair(
|
||||
KeyPair(
|
||||
'5OxmMjL-ujoR5IMGegQz',
|
||||
Key('6d1044d5-18c5-437c-9219-fc2ace7e5ebc', prefix='orgs'),
|
||||
ComposeKey('6d1044d5-18c5-437c-9219-fc2ace7e5ebc', prefix='orgs'),
|
||||
),
|
||||
name='Beta Educação',
|
||||
ttl=ttl(days=3),
|
||||
)
|
||||
|
||||
data = collect.get_item(
|
||||
key=KeyPair(
|
||||
KeyPair(
|
||||
pk='5OxmMjL-ujoR5IMGegQz',
|
||||
sk=Key('6d1044d5-18c5-437c-9219-fc2ace7e5ebc', prefix='orgs'),
|
||||
sk=ComposeKey('6d1044d5-18c5-437c-9219-fc2ace7e5ebc', prefix='orgs'),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -131,8 +142,23 @@ def test_collection_delete_item(
|
||||
|
||||
# This item was added from seeds
|
||||
assert collect.delete_item(
|
||||
key=KeyPair(
|
||||
KeyPair(
|
||||
'5OxmMjL-ujoR5IMGegQz',
|
||||
Key('sergio@somsbeta.com.br', prefix='emails'),
|
||||
ComposeKey('sergio@somsbeta.com.br', prefix='emails'),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_collection_get_items(
|
||||
dynamodb_seeds,
|
||||
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||
):
|
||||
collect = DynamoDBCollection(dynamodb_persistence_layer)
|
||||
|
||||
# This item was added from seeds
|
||||
data = collect.get_items(
|
||||
PartitionKey(
|
||||
ComposeKey('5OxmMjL-ujoR5IMGegQz', prefix='logs'),
|
||||
),
|
||||
)
|
||||
assert len(data['items']) == 2
|
||||
|
||||
Reference in New Issue
Block a user