diff --git a/alternator-test/test_expected.py b/alternator-test/test_expected.py index a48084fe7f..5febcf9402 100644 --- a/alternator-test/test_expected.py +++ b/alternator-test/test_expected.py @@ -82,6 +82,29 @@ def test_update_expected_1_eq_true(test_table_s): 'AttributeValueList': [2, 3]}} ) +# Check that set equality is checked correctly. Unlike string equality (for +# example), it cannot be done with just naive string comparison of the JSON +# representation, and we need to allow for any order. +@pytest.mark.xfail(reason="bug in EQ test of sets") +def test_update_expected_1_eq_set(test_table_s): + p = random_string() + # Because boto3 sorts the set values we give it, in order to generate a + # set with a different order, we need to build it incrementally. + test_table_s.update_item(Key={'p': p}, + AttributeUpdates={'a': {'Value': set(['dog', 'chinchilla']), 'Action': 'PUT'}}) + test_table_s.update_item(Key={'p': p}, + UpdateExpression='ADD a :val1', + ExpressionAttributeValues={':val1': set(['cat', 'mouse'])}) + # Sanity check - the attribute contains the set we think it does + assert test_table_s.get_item(Key={'p': p}, ConsistentRead=True)['Item']['a'] == set(['chinchilla', 'cat', 'dog', 'mouse']) + # Now finally check that "Expected"'s equality check knows the equality too. + test_table_s.update_item(Key={'p': p}, + AttributeUpdates={'b': {'Value': 3, 'Action': 'PUT'}}, + Expected={'a': {'ComparisonOperator': 'EQ', + 'AttributeValueList': [set(['chinchilla', 'cat', 'dog', 'mouse'])]}} + ) + assert 'b' in test_table_s.get_item(Key={'p': p}, ConsistentRead=True)['Item'] + def test_update_expected_1_eq_false(test_table_s): p = random_string() test_table_s.update_item(Key={'p': p},