def test_populate_keys_happy_case(mocked_dbo, pointer_item): mocked_dbo._populate_key_records(pointer_item) calls = [] for key in pointer_item.context.keys(): ctx_key = ContextItem(key, pointer_item.partition_key) calls.append(call(Item=ctx_key.to_item())) mocked_dbo.table.put_item.assert_has_calls(calls, any_order=True)
def test_list_items(mocked_dbo, random_ddb_pointer_table): mocked_dbo.table.scan = mock.Mock(return_value=random_ddb_pointer_table) expected_guids = set() for item in random_ddb_pointer_table["Items"]: partition_key = item[BaseItem.partition_key_name()] if not partition_key.startswith(ContextItem._prefix()): expected_guids.add(partition_key) pointers = mocked_dbo.list() actual_guids = set() for p in pointers: # Ensure we filtered out context keys assert ContextItem._prefix() not in p.partition_key # Add this guid actual_guids.add(p.partition_key) assert expected_guids == actual_guids
def random_context_item(): return ContextItem(random_key_or_value(), get_pointer_key())
def test_prefix_added_once(ctx_prefix): test_key = ctx_prefix + "c00L" assert test_key == ContextItem.canonicalize(test_key)
def test_canonicalize(ctx_prefix): test_key = "toTalLy_pUbl1c_7ag" c = ContextItem.canonicalize(test_key) assert test_key in c assert ctx_prefix in c
def test_unset_partition_raises_context_item(): with pytest.raises(DataModelException): ContextItem(None, "sort_key")
def test_context_item_happy_case(suuid): context_key = "FLEET" test_item = ContextItem(context_key, suuid) assert context_key in test_item.partition_key assert suuid in test_item.sort_key
def test_context_eq(suuid): context1 = ContextItem("coolkey", suuid) context2 = ContextItem("coolkey", suuid) assert context1 == context2 assert context1 is not context2
def test_object_type_neq(sample_context): pointer = PointerItem.generate(sample_context) context = ContextItem("stuff", pointer.partition_key) assert pointer != context