From 336c90daaa4de1f231cf1f417e2b01dec756124b Mon Sep 17 00:00:00 2001 From: Piotr Sarna Date: Fri, 12 Jul 2019 12:18:25 +0200 Subject: [PATCH] alternator-test: add stub case for set add duplication The test case for adding two sets with common values is added. This case is a stub, because boto3 transforms the result into a Python set, which removes duplicates on its own. A proper TODO is left in order to migrate this case to a lower-level API and check the returned JSON directly for lack of duplicates. --- alternator-test/test_update_expression.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/alternator-test/test_update_expression.py b/alternator-test/test_update_expression.py index f99ba4c3eb..6705ec0ac8 100644 --- a/alternator-test/test_update_expression.py +++ b/alternator-test/test_update_expression.py @@ -654,6 +654,17 @@ def test_update_expression_add_sets(test_table_s): UpdateExpression='ADD a :val1', ExpressionAttributeValues={':val1': set(['pig'])}) assert test_table_s.get_item(Key={'p': p}, ConsistentRead=True)['Item']['a'] == set(['dog', 'cat', 'mouse', 'pig']) + + # TODO: right now this test won't detect duplicated values in the returned result, + # because boto3 parses a set out of the returned JSON anyway. This check should leverage + # lower level API (if exists) to ensure that the JSON contains no duplicates + # in the set representation. It has been verified manually. + test_table_s.put_item(Item={'p': p, 'a': set(['beaver', 'lynx', 'coati']), 'b': 'hi'}) + test_table_s.update_item(Key={'p': p}, + UpdateExpression='ADD a :val1', + ExpressionAttributeValues={':val1': set(['coati', 'beaver', 'badger'])}) + assert test_table_s.get_item(Key={'p': p}, ConsistentRead=True)['Item']['a'] == set(['beaver', 'badger', 'lynx', 'coati']) + # The value to be added needs to be a set of the same type - it can't # be a single element or anything else. If the value has the wrong type, # we get an error like "Invalid UpdateExpression: Incorrect operand type