本文整理汇总了Python中ddbmock.database.table.Table类的典型用法代码示例。如果您正苦于以下问题:Python Table类的具体用法?Python Table怎么用?Python Table使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Table类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
from ddbmock.database.db import dynamodb
from ddbmock.database.table import Table
from ddbmock.database.key import PrimaryKey
from ddbmock import main
app = main({})
from webtest import TestApp
self.app = TestApp(app)
dynamodb.hard_reset()
hash_key = PrimaryKey(TABLE_HK_NAME, TABLE_HK_TYPE)
range_key = PrimaryKey(TABLE_RK_NAME, TABLE_RK_TYPE)
self.t1 = Table(TABLE_NAME1, TABLE_RT, TABLE_WT, hash_key, range_key)
self.t2 = Table(TABLE_NAME2, TABLE_RT, TABLE_WT, hash_key, None)
dynamodb.data[TABLE_NAME1] = self.t1
dynamodb.data[TABLE_NAME2] = self.t2
self.t1.put(ITEM1, {})
self.t1.put(ITEM2, {})
self.t1.put(ITEM3, {})
self.t2.put(ITEM4, {})
self.t2.put(ITEM5, {})
示例2: TestTable
class TestTable(unittest.TestCase):
def setUp(self):
from ddbmock.database.table import Table
self.table = Table(NAME, RT, WT, None, None, status="ACTIVE")
def tearDown(self):
self.table = None
def test_update_throughput_nominal(self):
self.table.update_throughput(RT2, WT2)
self.assertEqual(RT2, self.table.rt)
self.assertEqual(WT2, self.table.wt)
def test_increase_throughtput_max_100_percents(self):
from ddbmock.errors import LimitExceededException
# Try on RT
self.assertRaisesRegexp(LimitExceededException,
"ReadCapacityUnits .* at most 100",
self.table.update_throughput,
RT100, WT)
self.assertEqual(RT, self.table.rt)
self.assertEqual(WT, self.table.wt)
# Try on WT
self.assertRaisesRegexp(LimitExceededException,
"WriteCapacityUnits .* at most 100",
self.table.update_throughput,
RT, WT100)
self.assertEqual(RT, self.table.rt)
self.assertEqual(WT, self.table.wt)
@mock.patch("ddbmock.database.table.time")
def test_decrease_max_once_a_day(self, m_time):
from ddbmock.errors import LimitExceededException
# 1st decrease 1 hour after creation (ok)
m_time.time.return_value = CREATION + 1*3600
self.table.update_throughput(RT3, WT3)
self.assertEqual(RT3, self.table.rt)
self.assertEqual(WT3, self.table.wt)
# bypass the timer
self.table.status = "ACTIVE"
# 2nd decrease 2 hour after creation (fail)
m_time.time.return_value = CREATION + 2*3600
self.assertRaisesRegexp(LimitExceededException,
"once .* day",
self.table.update_throughput,
RT4, WT4)
self.assertEqual(RT3, self.table.rt)
self.assertEqual(WT3, self.table.wt)
示例3: TestGetItem
class TestGetItem(unittest.TestCase):
def setUp(self):
from ddbmock.database.db import dynamodb
from ddbmock.database.table import Table
from ddbmock.database.key import PrimaryKey
from ddbmock.database.db import dynamodb
from ddbmock import main
app = main({})
from webtest import TestApp
self.app = TestApp(app)
dynamodb.hard_reset()
hash_key = PrimaryKey(TABLE_HK_NAME, TABLE_HK_TYPE)
range_key = PrimaryKey(TABLE_RK_NAME, TABLE_RK_TYPE)
self.t1 = Table(TABLE_NAME, TABLE_RT, TABLE_WT, hash_key, range_key)
dynamodb.data[TABLE_NAME] = self.t1
self.t1.put(ITEM, {})
def tearDown(self):
from ddbmock.database.db import dynamodb
dynamodb.hard_reset()
def test_get_hr_attr_to_get(self):
from ddbmock.database.db import dynamodb
request = {
"TableName": TABLE_NAME,
"Key": {
"HashKeyElement": HK,
"RangeKeyElement": RK,
},
"AttributesToGet": ["relevant_data"],
}
expected = {
u'ConsumedCapacityUnits': 0.5,
u'Item': {
u'relevant_data': ITEM[u'relevant_data'],
}
}
# Protocol check
res = self.app.post_json('/', request, headers=HEADERS, status=200)
self.assertEqual(expected, json.loads(res.body))
self.assertEqual('application/x-amz-json-1.0; charset=UTF-8', res.headers['Content-Type'])
示例4: setUp
def setUp(self):
from ddbmock.database.db import dynamodb
from ddbmock.database.table import Table
from ddbmock.database.key import PrimaryKey
dynamodb.hard_reset()
hash_key = PrimaryKey(TABLE_HK_NAME, TABLE_HK_TYPE)
range_key = PrimaryKey(TABLE_RK_NAME, TABLE_RK_TYPE)
t1 = Table(TABLE_NAME, TABLE_RT, TABLE_WT, hash_key, range_key, status='ACTIVE')
t1.put(ITEM1, {})
t1.put(ITEM2, {})
dynamodb.data[TABLE_NAME] = t1
示例5: TestDeleteItem
class TestDeleteItem(unittest.TestCase):
def setUp(self):
from ddbmock.database.db import dynamodb
from ddbmock.database.table import Table
from ddbmock.database.key import PrimaryKey
from ddbmock.database.db import dynamodb
from ddbmock import main
app = main({})
from webtest import TestApp
self.app = TestApp(app)
dynamodb.hard_reset()
hash_key = PrimaryKey(TABLE_HK_NAME, TABLE_HK_TYPE)
range_key = PrimaryKey(TABLE_RK_NAME, TABLE_RK_TYPE)
self.t1 = Table(TABLE_NAME, TABLE_RT, TABLE_WT, hash_key, range_key)
dynamodb.data[TABLE_NAME] = self.t1
self.t1.put(ITEM, {})
def tearDown(self):
from ddbmock.database.db import dynamodb
dynamodb.hard_reset()
def test_delete_item_hr(self):
from ddbmock.database.db import dynamodb
request = {
"TableName": TABLE_NAME,
"Key": {
"HashKeyElement": HK,
"RangeKeyElement": RK,
},
}
expected = {
u"ConsumedCapacityUnits": 1,
}
# Protocol check
res = self.app.post_json('/', request, headers=HEADERS, status=200)
self.assertEqual(expected, json.loads(res.body))
self.assertEqual('application/x-amz-json-1.0; charset=UTF-8', res.headers['Content-Type'])
# Live data check
self.assertNotIn((HK_VALUE, RK_VALUE), self.t1.store)
示例6: setUp
def setUp(self):
from ddbmock.database.db import dynamodb
from ddbmock.database.table import Table
from ddbmock.database.key import PrimaryKey
dynamodb.hard_reset()
hash_key = PrimaryKey(TABLE_HK_NAME, TABLE_HK_TYPE)
range_key = PrimaryKey(TABLE_RK_NAME, TABLE_RK_TYPE)
self.t1 = Table(TABLE_NAME, TABLE_RT, TABLE_WT, hash_key, range_key)
self.t2 = Table(TABLE_NAME2, TABLE_RT, TABLE_WT, hash_key, None)
dynamodb.data[TABLE_NAME] = self.t1
dynamodb.data[TABLE_NAME2] = self.t2
self.t1.put(cp(ITEM), {})
self.t2.put(cp(ITEM2), {})
示例7: TestUpdateItem
class TestUpdateItem(unittest.TestCase):
def setUp(self):
from ddbmock.database.db import dynamodb
from ddbmock.database.table import Table
from ddbmock.database.key import PrimaryKey
import helpers
self.app = helpers.makeTestApp()
dynamodb.hard_reset()
hash_key = PrimaryKey(TABLE_HK_NAME, TABLE_HK_TYPE)
range_key = PrimaryKey(TABLE_RK_NAME, TABLE_RK_TYPE)
self.t1 = Table(TABLE_NAME, TABLE_RT, TABLE_WT, hash_key, range_key)
dynamodb.data[TABLE_NAME] = self.t1
self.t1.put(ITEM, {})
def tearDown(self):
from ddbmock.database.db import dynamodb
dynamodb.hard_reset()
def test_update_item_put_hr(self):
request = {
"TableName": TABLE_NAME,
"Key": {
"HashKeyElement": HK,
"RangeKeyElement": RK,
},
"AttributeUpdates": {'relevant_data': {'Value': RELEVANT_FIELD}},
}
expected = {"ConsumedCapacityUnits": 1}
# Protocol check
res = self.app.post_json('/', request, headers=HEADERS, status=200)
self.assertEqual(expected, json.loads(res.body))
self.assertEqual('application/x-amz-json-1.0; charset=UTF-8',
res.headers['Content-Type'])
# Live data check
self.assertEqual(RELEVANT_FIELD,
self.t1.store[HK_VALUE, RK_VALUE]['relevant_data'])
示例8: setUp
def setUp(self):
from ddbmock.database.db import dynamodb
from ddbmock.database.table import Table
from ddbmock.database.key import PrimaryKey
import helpers
self.app = helpers.makeTestApp()
dynamodb.hard_reset()
hash_key = PrimaryKey(TABLE_HK_NAME, TABLE_HK_TYPE)
range_key = PrimaryKey(TABLE_RK_NAME, TABLE_RK_TYPE)
self.t1 = Table(TABLE_NAME1, TABLE_RT, TABLE_WT, hash_key, range_key)
self.t2 = Table(TABLE_NAME2, TABLE_RT, TABLE_WT, hash_key, None)
dynamodb.data[TABLE_NAME1] = self.t1
dynamodb.data[TABLE_NAME2] = self.t2
self.t1.put(ITEM1, {})
self.t2.put(ITEM4, {})
示例9: setUp
def setUp(self):
from ddbmock.database.db import dynamodb
from ddbmock.database.table import Table
from ddbmock.database.key import PrimaryKey
dynamodb.hard_reset()
hash_key = PrimaryKey(TABLE_HK_NAME, TABLE_HK_TYPE)
range_key = PrimaryKey(TABLE_RK_NAME, TABLE_RK_TYPE)
self.t1 = Table(TABLE_NAME, TABLE_RT, TABLE_WT, hash_key, range_key)
dynamodb.data[TABLE_NAME] = self.t1
self.t1.put(ITEM1, {})
self.t1.put(ITEM2, {})
self.t1.put(ITEM3, {})
self.t1.put(ITEM4, {})
self.t1.put(ITEM5, {})
示例10: setUp
def setUp(self):
from ddbmock.database.table import Table
self.table = Table(NAME, RT, WT, None, None, status="ACTIVE")
示例11: TestBatchGetItem
class TestBatchGetItem(unittest.TestCase):
def setUp(self):
from ddbmock.database.db import dynamodb
from ddbmock.database.table import Table
from ddbmock.database.key import PrimaryKey
import helpers
self.app = helpers.makeTestApp()
dynamodb.hard_reset()
hash_key = PrimaryKey(TABLE_HK_NAME, TABLE_HK_TYPE)
range_key = PrimaryKey(TABLE_RK_NAME, TABLE_RK_TYPE)
self.t1 = Table(TABLE_NAME1, TABLE_RT, TABLE_WT, hash_key, range_key)
self.t2 = Table(TABLE_NAME2, TABLE_RT, TABLE_WT, hash_key, None)
dynamodb.data[TABLE_NAME1] = self.t1
dynamodb.data[TABLE_NAME2] = self.t2
self.t1.put(ITEM1, {})
self.t1.put(ITEM2, {})
self.t1.put(ITEM3, {})
self.t2.put(ITEM4, {})
self.t2.put(ITEM5, {})
def tearDown(self):
from ddbmock.database.db import dynamodb
dynamodb.hard_reset()
def test_batch_get_item_filter_one(self):
request = {
u"RequestItems": {
TABLE_NAME1: {
u"Keys": [
{u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE1},
u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE1},
},
{u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE1},
u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE1}
},
],
u"AttributesToGet": [u"relevant_data"],
},
TABLE_NAME2: {
u"Keys": [
{u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE3}},
],
},
}
}
expected = {
"Responses": {
"Table-HR": {
"Items": [
{"relevant_data": {"S": "tata"}},
{"relevant_data": {"S": "tata"}},
],
"ConsumedCapacityUnits": 1.0
},
"Table-H": {
"Items": [
{"relevant_data": {"S": "tutu"},
"hash_key": {"N": "789"},
"range_key": {"S": "Waldo-5"}
},
],
"ConsumedCapacityUnits": 0.5
}
}
}
# Protocol check
res = self.app.post_json('/', request, headers=HEADERS, status=200)
self.assertEqual(expected, json.loads(res.body))
self.assertEqual('application/x-amz-json-1.0; charset=UTF-8',
res.headers['Content-Type'])
def test_batch_get_item_filter_one_consistent(self):
request = {
u"RequestItems": {
TABLE_NAME1: {
u"Keys": [
{u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE1},
u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE1}
},
{u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE1},
u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE1}
},
],
u"AttributesToGet": [u"relevant_data"],
u"ConsistentRead": True,
},
TABLE_NAME2: {
u"Keys": [
{u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE3}},
],
},
#.........这里部分代码省略.........
示例12: TestQuery
class TestQuery(unittest.TestCase):
def setUp(self):
from ddbmock.database.db import dynamodb
from ddbmock.database.table import Table
from ddbmock.database.key import PrimaryKey
from ddbmock import main
app = main({})
from webtest import TestApp
self.app = TestApp(app)
dynamodb.hard_reset()
hash_key = PrimaryKey(TABLE_HK_NAME, TABLE_HK_TYPE)
range_key = PrimaryKey(TABLE_RK_NAME, TABLE_RK_TYPE)
self.t1 = Table(TABLE_NAME, TABLE_RT, TABLE_WT, hash_key, range_key)
dynamodb.data[TABLE_NAME] = self.t1
self.t1.put(ITEM1, {})
self.t1.put(ITEM2, {})
self.t1.put(ITEM3, {})
self.t1.put(ITEM4, {})
self.t1.put(ITEM5, {})
def tearDown(self):
from ddbmock.database.db import dynamodb
dynamodb.hard_reset()
def test_query_condition_filter_fields(self):
request = {
"TableName": TABLE_NAME,
"HashKeyValue": {TABLE_HK_TYPE: HK_VALUE},
"RangeKeyCondition": {
"AttributeValueList": [{"S":"Waldo-2"}],
"ComparisonOperator": "GT",
},
"AttributesToGet": [u'relevant_data'],
}
expected = {
u"Count": 3,
u"Items": [
{u"relevant_data": {u"S": u"titi"}},
{u"relevant_data": {u"S": u"toto"}},
{u"relevant_data": {u"S": u"tutu"}},
],
u"ConsumedCapacityUnits": 0.5,
}
# Protocol check
res = self.app.post_json('/', request, headers=HEADERS, status=200)
self.assertEqual(expected, json.loads(res.body))
self.assertEqual('application/x-amz-json-1.0; charset=UTF-8',
res.headers['Content-Type'])
def test_query_count_and_attrs_to_get_fails(self):
request = {
"TableName": TABLE_NAME,
"HashKeyValue": {TABLE_HK_TYPE: HK_VALUE},
"RangeKeyCondition": {
"AttributeValueList": [{"S":"Waldo-2"}],
"ComparisonOperator": "GT",
},
"AttributesToGet": [u'relevant_data'],
"Count": True,
}
expected = {
u'__type': u'com.amazonaws.dynamodb.v20111205#ValidationException',
u'message': u'Can filter fields when only count is requested'
}
# Protocol check
res = self.app.post_json('/', request, headers=HEADERS, status=400)
self.assertEqual(expected, json.loads(res.body))
self.assertEqual('application/x-amz-json-1.0; charset=UTF-8',
res.headers['Content-Type'])
# Regression test for #9
def test_query_all_404(self):
request = {
"TableName": TABLE_NAME,
"HashKeyValue": {TABLE_HK_TYPE: HK_VALUE_404},
}
expected = {
u"Count": 0,
u'Items': [],
u"ConsumedCapacityUnits": 0.5,
}
# Protocol check
res = self.app.post_json('/', request, headers=HEADERS, status=200)
self.assertEqual(expected, json.loads(res.body))
self.assertEqual('application/x-amz-json-1.0; charset=UTF-8',
res.headers['Content-Type'])
示例13: TestUpdateItem
class TestUpdateItem(unittest.TestCase):
def setUp(self):
from ddbmock.database.db import dynamodb
from ddbmock.database.table import Table
from ddbmock.database.key import PrimaryKey
dynamodb.hard_reset()
hash_key = PrimaryKey(TABLE_HK_NAME, TABLE_HK_TYPE)
range_key = PrimaryKey(TABLE_RK_NAME, TABLE_RK_TYPE)
self.t1 = Table(TABLE_NAME, TABLE_RT, TABLE_WT, hash_key, range_key)
self.t2 = Table(TABLE_NAME2, TABLE_RT, TABLE_WT, hash_key, None)
dynamodb.data[TABLE_NAME] = self.t1
dynamodb.data[TABLE_NAME2] = self.t2
self.t1.put(cp(ITEM), {})
self.t2.put(cp(ITEM2), {})
def tearDown(self):
from ddbmock.database.db import dynamodb
from ddbmock import clean_boto_patch
dynamodb.hard_reset()
clean_boto_patch()
def test_update_item_put_hr(self):
from ddbmock import connect_boto_patch
db = connect_boto_patch()
key = {u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE}, u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE}}
key2 = {u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE2}, u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE}}
# use PUT as default action, champs existant
db.layer1.update_item(
TABLE_NAME, key, {"relevant_data": {"Value": RELEVANT_FIELD}} # Move type from 'B' to 'S'
)
self.assertEqual(RELEVANT_FIELD, self.t1.store[HK_VALUE, RK_VALUE]["relevant_data"])
# PUT explicite, champ non existant
db.layer1.update_item(TABLE_NAME, key, {"irelevant_data": {"Action": "PUT", "Value": IRELEVANT_FIELD}})
self.assertEqual(RELEVANT_FIELD, self.t1.store[HK_VALUE, RK_VALUE]["relevant_data"])
self.assertEqual(IRELEVANT_FIELD, self.t1.store[HK_VALUE, RK_VALUE]["irelevant_data"])
# PUT explicite, item non existant(full item creation)
db.layer1.update_item(TABLE_NAME, key2, {"relevant_data": {"Action": "PUT", "Value": RELEVANT_FIELD}})
self.assertEqual({TABLE_HK_TYPE: HK_VALUE2}, self.t1.store[HK_VALUE2, RK_VALUE][TABLE_HK_NAME])
self.assertEqual({TABLE_RK_TYPE: RK_VALUE}, self.t1.store[HK_VALUE2, RK_VALUE][TABLE_RK_NAME])
self.assertEqual(RELEVANT_FIELD, self.t1.store[HK_VALUE2, RK_VALUE]["relevant_data"])
def test_update_item_put_h(self):
from ddbmock import connect_boto_patch
db = connect_boto_patch()
key = {u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE}}
key2 = {u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE2}}
# use PUT as default action, champs existant
db.layer1.update_item(
TABLE_NAME2, key, {"relevant_data": {"Value": RELEVANT_FIELD}} # Move type from 'B' to 'S'
)
self.assertEqual(RELEVANT_FIELD, self.t2.store[HK_VALUE, False]["relevant_data"])
# PUT explicite, champ non existant
db.layer1.update_item(TABLE_NAME2, key, {"irelevant_data": {"Action": "PUT", "Value": IRELEVANT_FIELD}})
self.assertEqual(RELEVANT_FIELD, self.t2.store[HK_VALUE, False]["relevant_data"])
self.assertEqual(IRELEVANT_FIELD, self.t2.store[HK_VALUE, False]["irelevant_data"])
# PUT explicite, item non existant(full item creation)
db.layer1.update_item(TABLE_NAME2, key2, {"relevant_data": {"Action": "PUT", "Value": RELEVANT_FIELD}})
self.assertEqual({TABLE_HK_TYPE: HK_VALUE2}, self.t2.store[HK_VALUE2, False][TABLE_HK_NAME])
self.assertEqual(RELEVANT_FIELD, self.t2.store[HK_VALUE2, False]["relevant_data"])
def test_put_check_throughput_max_old_new(self):
from ddbmock import connect_boto_patch
from ddbmock.database.db import dynamodb
db = connect_boto_patch()
key = {u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE}}
self.assertEqual(
{u"ConsumedCapacityUnits": 1},
db.layer1.update_item(TABLE_NAME2, key, {FIELD_NAME: {"Action": "PUT", "Value": FIELD_SMALL}}),
)
self.assertEqual(
{u"ConsumedCapacityUnits": 2},
db.layer1.update_item(TABLE_NAME2, key, {FIELD_NAME: {"Action": "PUT", "Value": FIELD_BIG}}),
)
self.assertEqual(
{u"ConsumedCapacityUnits": 2},
db.layer1.update_item(TABLE_NAME2, key, {FIELD_NAME: {"Action": "PUT", "Value": FIELD_SMALL}}),
)
def test_update_item_delete_primary_key_fails(self):
#.........这里部分代码省略.........
示例14: TestDeleteItem
class TestDeleteItem(unittest.TestCase):
def setUp(self):
from ddbmock.database.db import dynamodb
from ddbmock.database.table import Table
from ddbmock.database.key import PrimaryKey
dynamodb.hard_reset()
hash_key = PrimaryKey(TABLE_HK_NAME, TABLE_HK_TYPE)
range_key = PrimaryKey(TABLE_RK_NAME, TABLE_RK_TYPE)
self.t1 = Table(TABLE_NAME, TABLE_RT, TABLE_WT, hash_key, range_key)
self.t2 = Table(TABLE_NAME2, TABLE_RT, TABLE_WT, hash_key, None)
dynamodb.data[TABLE_NAME] = self.t1
dynamodb.data[TABLE_NAME2] = self.t2
self.t1.put(ITEM, {})
self.t2.put(ITEM2, {})
self.t2.put(ITEM_BIG, {})
def tearDown(self):
from ddbmock.database.db import dynamodb
from ddbmock import clean_boto_patch
dynamodb.hard_reset()
clean_boto_patch()
def test_delete_item_hr(self):
from ddbmock import connect_boto_patch
from ddbmock.database.db import dynamodb
db = connect_boto_patch()
key = {
u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE},
u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE},
}
self.assertEqual({
u'ConsumedCapacityUnits': 1,
},
db.layer1.delete_item(TABLE_NAME, key),
)
self.assertNotIn((HK_VALUE, RK_VALUE), self.t1.store)
def test_delete_item_hr_404(self):
# same behavior as found
from ddbmock import connect_boto_patch
from ddbmock.database.db import dynamodb
db = connect_boto_patch()
key = {
u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE_404},
u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE},
}
self.assertEqual({
u'ConsumedCapacityUnits': 1,
},
db.layer1.delete_item(TABLE_NAME, key),
)
self.assertNotIn((HK_VALUE_404, RK_VALUE), self.t1.store)
def test_delete_item_hr_old(self):
from ddbmock import connect_boto_patch
from ddbmock.database.db import dynamodb
db = connect_boto_patch()
expected = {
u'ConsumedCapacityUnits': 1,
u'Attributes': ITEM,
}
key = {
u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE},
u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE},
}
self.assertEqual(
expected,
db.layer1.delete_item(TABLE_NAME, key, return_values=u'ALL_OLD'),
)
self.assertNotIn((HK_VALUE, RK_VALUE), self.t1.store)
def test_delete_item_h(self):
from ddbmock import connect_boto_patch
from ddbmock.database.db import dynamodb
db = connect_boto_patch()
key = {
u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE},
}
self.assertEqual({
u'ConsumedCapacityUnits': 1,
},
db.layer1.delete_item(TABLE_NAME2, key),
#.........这里部分代码省略.........
示例15: TestScan
class TestScan(unittest.TestCase):
def setUp(self):
from ddbmock.database.db import dynamodb
from ddbmock.database.table import Table
from ddbmock.database.key import PrimaryKey
import helpers
self.app = helpers.makeTestApp()
dynamodb.hard_reset()
hash_key = PrimaryKey(TABLE_HK_NAME, TABLE_HK_TYPE)
range_key = PrimaryKey(TABLE_RK_NAME, TABLE_RK_TYPE)
self.t1 = Table(TABLE_NAME, TABLE_RT, TABLE_WT, hash_key, range_key)
dynamodb.data[TABLE_NAME] = self.t1
self.t1.put(ITEM1, {})
self.t1.put(ITEM2, {})
self.t1.put(ITEM3, {})
self.t1.put(ITEM4, {})
self.t1.put(ITEM5, {})
def tearDown(self):
from ddbmock.database.db import dynamodb
dynamodb.hard_reset()
def test_scan_condition_filter_fields(self):
request = {
"TableName": TABLE_NAME,
"ScanFilter": {
"relevant_data": {
"AttributeValueList": [
{"S":"toto"},
{"S":"titi"},
{"S":"tata"},
],
"ComparisonOperator": "IN",
},
},
"AttributesToGet": [u'relevant_data'],
}
expected = {
u"Count": 3,
u"ScannedCount": 5,
u"Items": [
{u"relevant_data": {u"S": u"tata"}},
{u"relevant_data": {u"S": u"toto"}},
{u"relevant_data": {u"S": u"titi"}},
],
u"ConsumedCapacityUnits": 0.5,
}
# Protocol check
res = self.app.post_json('/', request, headers=HEADERS, status=200)
self.assertEqual(expected, json.loads(res.body))
self.assertEqual('application/x-amz-json-1.0; charset=UTF-8',
res.headers['Content-Type'])
def test_scan_count_and_attrs_to_get_fails(self):
request = {
"TableName": TABLE_NAME,
"ScanFilter": {
"relevant_data": {
"AttributeValueList": [
{"S":"toto"},
{"S":"titi"},
{"S":"tata"},
],
"ComparisonOperator": "IN",
},
},
"AttributesToGet": [u'relevant_data'],
"Count": True,
}
expected = {
u'__type': u'com.amazonaws.dynamodb.v20120810#ValidationException',
u'message': u'Can not filter fields when only count is requested'
}
# Protocol check
res = self.app.post_json('/', request, headers=HEADERS, status=400)
self.assertEqual(expected, json.loads(res.body))
self.assertEqual('application/x-amz-json-1.0; charset=UTF-8',
res.headers['Content-Type'])