Skip to content

Commit

Permalink
Remove deprecated AttributesToGet
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquev6 committed Oct 24, 2014
1 parent 79a4c11 commit fabaef9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 88 deletions.
42 changes: 2 additions & 40 deletions LowVoltage/operations/batch_operations.py
Expand Up @@ -17,6 +17,8 @@


class BatchGetItem(_Operation, ReturnConsumedCapacityMixin):
# @todo ProjectionExpression

class Result(object):
def __init__(
self,
Expand Down Expand Up @@ -65,15 +67,6 @@ def consistent_read_false(self):
self.__last_table["ConsistentRead"] = False
return self

def attributes_to_get(self, *names):
if "AttributesToGet" not in self.__last_table:
self.__last_table["AttributesToGet"] = []
for name in names:
if isinstance(name, basestring):
name = [name]
self.__last_table["AttributesToGet"].extend(name)
return self


class BatchGetItemUnitTests(unittest.TestCase):
def testEmpty(self):
Expand Down Expand Up @@ -143,21 +136,6 @@ def testConsistentRead(self):
}
)

def testAttributesToGet(self):
self.assertEqual(
BatchGetItem().table("Table2").attributes_to_get("a").table("Table1").attributes_to_get("b", "c").table("Table2").attributes_to_get(["d", "e"]).build(),
{
"RequestItems": {
"Table1": {
"AttributesToGet": ["b", "c"],
},
"Table2": {
"AttributesToGet": ["a", "d", "e"],
},
}
}
)


class BatchGetItemIntegTests(LowVoltage.tests.dynamodb_local.TestCase):
def setUp(self):
Expand All @@ -183,22 +161,6 @@ def testSimpleBatchGet(self):
)
self.assertEqual(r.unprocessed_keys, {})

def testBatchGetSpecificAttributes(self):
self.connection.request(LowVoltage.operations.item_operations.PutItem("Aaa", {"h": "1", "a": "xxx"}))
self.connection.request(LowVoltage.operations.item_operations.PutItem("Aaa", {"h": "2", "a": "yyy"}))
self.connection.request(LowVoltage.operations.item_operations.PutItem("Aaa", {"h": "3", "a": "zzz"}))

r = self.connection.request(BatchGetItem().table("Aaa").keys({"h": "1"}, {"h": "2"}, {"h": "3"}).attributes_to_get("a"))

with cover("r", r) as r:
self.assertEqual(r.responses.keys(), ["Aaa"])
self.assertEqual(
sorted(r.responses["Aaa"], key=lambda i: i["a"]),
[{"a": "xxx"}, {"a": "yyy"}, {"a": "zzz"}]
)
self.assertEqual(r.unprocessed_keys, {})


class BatchWriteItem(_Operation, ReturnConsumedCapacityMixin, ReturnItemCollectionMetricsMixin):
class Result(object):
def __init__(
Expand Down
50 changes: 2 additions & 48 deletions LowVoltage/operations/item_operations.py
Expand Up @@ -182,6 +182,8 @@ def testReturnOldValues(self):


class GetItem(_Operation, ReturnConsumedCapacityMixin):
# @todo ProjectionExpression

class Result(object):
def __init__(
self,
Expand All @@ -197,7 +199,6 @@ def __init__(self, table_name, key):
self.__key = key
ReturnConsumedCapacityMixin.__init__(self)
self.__consistent_read = None
self.__attributes_to_get = []

def build(self):
data = {
Expand All @@ -207,8 +208,6 @@ def build(self):
self._build_return_consumed_capacity(data)
if self.__consistent_read is not None:
data["ConsistentRead"] = self.__consistent_read
if self.__attributes_to_get:
data["AttributesToGet"] = self.__attributes_to_get
return data

def consistent_read_true(self):
Expand All @@ -221,13 +220,6 @@ def _set_consistent_read(self, value):
self.__consistent_read = value
return self

def attributes_to_get(self, *names):
for name in names:
if isinstance(name, basestring):
name = [name]
self.__attributes_to_get.extend(name)
return self


class GetItemUnitTests(unittest.TestCase):
def testKey(self):
Expand Down Expand Up @@ -289,36 +281,6 @@ def testConsistentReadFalse(self):
}
)

def testOneAttributesToGet(self):
self.assertEqual(
GetItem("Table", {"hash": "h"}).attributes_to_get("a").build(),
{
"TableName": "Table",
"Key": {"hash": {"S": "h"}},
"AttributesToGet": ["a"],
}
)

def testSeveralAttributesToGet(self):
self.assertEqual(
GetItem("Table", {"hash": "h"}).attributes_to_get("a", "b").build(),
{
"TableName": "Table",
"Key": {"hash": {"S": "h"}},
"AttributesToGet": ["a", "b"],
}
)

def testListAttributesToGet(self):
self.assertEqual(
GetItem("Table", {"hash": "h"}).attributes_to_get(["a", "b"]).build(),
{
"TableName": "Table",
"Key": {"hash": {"S": "h"}},
"AttributesToGet": ["a", "b"],
}
)


class GetItemIntegTests(LowVoltage.tests.dynamodb_local.TestCase):
def setUp(self):
Expand All @@ -337,14 +299,6 @@ def testSimpleGet(self):
with cover("r", r) as r:
self.assertEqual(r.item, {"h": "get", "a": "yyy"})

def testGetSpecificAttributes(self):
self.connection.request(PutItem("Aaa", {"h": "attrs", "a": "yyy", "b": "zzz"}))

r = self.connection.request(GetItem("Aaa", {"h": "attrs"}).attributes_to_get("a"))

with cover("r", r) as r:
self.assertEqual(r.item, {"a": "yyy"})


class PutItem(_Operation, ReturnOldValuesMixin, ReturnConsumedCapacityMixin, ReturnItemCollectionMetricsMixin):
class Result(object):
Expand Down

0 comments on commit fabaef9

Please sign in to comment.