Skip to content

Commit

Permalink
Remove assumption about set ordering
Browse files Browse the repository at this point in the history
Python >= 3.3
  • Loading branch information
jacquev6 committed Oct 24, 2014
1 parent b42c830 commit 1eaf95c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
14 changes: 14 additions & 0 deletions LowVoltage/operations/admin_operations.py
Expand Up @@ -12,6 +12,10 @@
import LowVoltage.exceptions as _exn


def _fix_order_for_tests(d):
d.attribute_definitions = sorted(d.attribute_definitions, key=lambda d: d.attribute_name)


class CreateTable(_Operation):
class Result(object):
def __init__(
Expand Down Expand Up @@ -427,6 +431,8 @@ def testSimpleGlobalSecondaryIndex(self):
.provisioned_throughput(3, 4)
)

_fix_order_for_tests(r.table_description)

with cover("r", r) as r:
self.assertEqual(r.table_description.attribute_definitions[0].attribute_name, "h")
self.assertEqual(r.table_description.attribute_definitions[0].attribute_type, "S")
Expand Down Expand Up @@ -464,6 +470,8 @@ def testSimpleLocalSecondaryIndex(self):
.local_secondary_index("the_lsi").hash_key("h").range_key("rr", _atyp.STRING).project_all()
)

_fix_order_for_tests(r.table_description)

with cover("r", r) as r:
self.assertEqual(r.table_description.attribute_definitions[0].attribute_name, "h")
self.assertEqual(r.table_description.attribute_definitions[0].attribute_type, "S")
Expand Down Expand Up @@ -505,6 +513,8 @@ def testGlobalSecondaryIndexWithProjection(self):
.provisioned_throughput(3, 4)
)

_fix_order_for_tests(r.table_description)

with cover("r", r) as r:
self.assertEqual(r.table_description.attribute_definitions[0].attribute_name, "h")
self.assertEqual(r.table_description.attribute_definitions[0].attribute_type, "S")
Expand Down Expand Up @@ -904,6 +914,8 @@ def testThroughput(self):
UpdateTable("Aaa").provisioned_throughput(2, 4)
)

_fix_order_for_tests(r.table_description)

with cover("r", r) as r:
self.assertEqual(r.table_description.attribute_definitions[0].attribute_name, "h")
self.assertEqual(r.table_description.attribute_definitions[0].attribute_type, "S")
Expand Down Expand Up @@ -940,6 +952,8 @@ def testGsiprovisioned_Throughput(self):
UpdateTable("Aaa").global_secondary_index("the_gsi").provisioned_throughput(6, 8)
)

_fix_order_for_tests(r.table_description)

with cover("r", r) as r:
self.assertEqual(r.table_description.attribute_definitions[0].attribute_name, "h")
self.assertEqual(r.table_description.attribute_definitions[0].attribute_type, "S")
Expand Down
2 changes: 1 addition & 1 deletion LowVoltage/operations/batch_operations.py
Expand Up @@ -178,7 +178,7 @@ def testSimpleBatchGet(self):
with cover("r", r) as r:
self.assertEqual(r.responses.keys(), ["Aaa"])
self.assertEqual(
sorted(r.responses["Aaa"]),
sorted(r.responses["Aaa"], key=lambda i: i["h"]),
[{"h": "1", "a": "xxx"}, {"h": "2", "a": "yyy"}, {"h": "3", "a": "zzz"}]
)
self.assertEqual(r.unprocessed_keys, {})
Expand Down
19 changes: 13 additions & 6 deletions LowVoltage/operations/item_operations.py
Expand Up @@ -575,13 +575,20 @@ def testSet(self):
)

def testSeveralSets(self):
self.assertEqual(
self.assertIn(
UpdateItem("Table", {"hash": 42}).set("a", "v").set("b", "w").build(),
{
"TableName": "Table",
"Key": {"hash": {"N": "42"}},
"UpdateExpression": "SET a=:v, b=:w",
}
[
{
"TableName": "Table",
"Key": {"hash": {"N": "42"}},
"UpdateExpression": "SET a=:v, b=:w",
},
{
"TableName": "Table",
"Key": {"hash": {"N": "42"}},
"UpdateExpression": "SET b=:w, a=:v",
}
]
)

def testValue(self):
Expand Down

0 comments on commit 1eaf95c

Please sign in to comment.