Commits

Jean-Tiare Le Bigot committed 889c39a

add pyramic fct test for create_table, restored broken pyramid entry point

Comments (0)

Files changed (43)

 include *.txt *.ini *.cfg *.rst
 recursive-include ddbmock *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml
 recursive-include docs *.py *.rst Makefile make.bat
+recursive-include tests *.py

ddbmock/__init__.py

 
     config.add_tween('ddbmock.router.dynamodb.dynamodb_router_factory')
     # Add routes
-    for src, dest in routes:
-        config.add_route(dest, '/'.src)
+    for src, dest in routes.iteritems():
+        config.add_route(dest, '/{}'.format(src))
 
     config.scan()
     return config.make_wsgi_app()
     from boto.dynamodb.layer1 import Layer1
     from router.botopatch import boto_make_request
     Layer1.make_request = boto_make_request
-    return boto.connect_dynamodb()
+    return boto.connect_dynamodb()

ddbmock/database/table.py

 # All validations are performed on *incomming* data => already done :)
 
 class Table(object):
-    def __init__(self, name, rt, wt, hash_key, range_key):
+    def __init__(self, name, rt, wt, hash_key, range_key, status='CREATING'):
         self.name = name
         self.rt = rt
         self.wt = wt
         self.hash_key = hash_key
         self.range_key = range_key
-        self.status = "ACTIVE"
+        self.status = status
         self.data = defaultdict(lambda: defaultdict(Item))
         self.creation_time = time.time()
         self.last_increase_time = 0
         #stub
         self.status = "DELETING"
 
+    def activate(self):
+        #stub
+        self.status = "ACTIVE"
+
     def update_throughput(self, rt, wt):
         # is decrease ?
         if self.rt > rt or self.wt > wt:
                     range_key,
                   )
 
-    def to_dict(self):
+    def to_dict(self, verbose=True):
         """Serialize table metadata for the describe table method. ItemCount and
         TableSizeBytes are accurate but highly depends on CPython > 2.6. Do not
         rely on it to project the actual size on a real DynamoDB implementation.
         """
         ret = {
             "CreationDateTime": self.creation_time,
-            "ItemCount": self.count,
             "KeySchema": {
                 "HashKeyElement": self.hash_key.to_dict(),
             },
                 "WriteCapacityUnits": self.wt,
             },
             "TableName": self.name,
-            "TableSizeBytes": getsizeof(self.data),
             "TableStatus": self.status
         }
 
+        if verbose:
+            ret[u'ItemCount'] = self.count
+            ret[u'TableSizeBytes'] = getsizeof(self.data)
+
         if self.last_increase_time:
             ret[u'ProvisionedThroughput'][u'LastIncreaseDateTime'] = self.last_increase_time
         if self.last_decrease_time:
         if self.range_key is not None:
             ret[u'KeySchema'][u'RangeKeyElement'] = self.range_key.to_dict()
 
-        return ret
+        return ret

ddbmock/tests.py

-# -*- coding: utf-8 -*-
-
-import unittest
-
-from pyramid import testing
-
-class ViewTests(unittest.TestCase):
-    def setUp(self):
-        self.config = testing.setUp()
-
-    def tearDown(self):
-        testing.tearDown()
-
-    def test_my_view(self):
-        from .views import my_view
-        request = testing.DummyRequest()
-        info = my_view(request)
-        self.assertEqual(info['project'], 'ddb-mock')

ddbmock/tests/__init__.py

-# -*- coding: utf-8 -*-

ddbmock/tests/functional/__init__.py

-# -*- coding: utf-8 -*-

ddbmock/tests/functional/boto/__init__.py

-# -*- coding: utf-8 -*-

ddbmock/tests/functional/boto/test_batch_get_item.py

-# -*- coding: utf-8 -*-
-
-import unittest
-import boto
-
-TABLE_NAME1 = 'Table-HR'
-TABLE_NAME2 = 'Table-H'
-TABLE_NAME_404 = 'Waldo'
-TABLE_RT = 45
-TABLE_WT = 123
-TABLE_RT2 = 10
-TABLE_WT2 = 10
-TABLE_HK_NAME = u'hash_key'
-TABLE_HK_TYPE = u'N'
-TABLE_RK_NAME = u'range_key'
-TABLE_RK_TYPE = u'S'
-
-HK_VALUE1 = u'123'
-HK_VALUE2 = u'456'
-HK_VALUE3 = u'789'
-RK_VALUE1 = u'Waldo-1'
-RK_VALUE2 = u'Waldo-2'
-RK_VALUE3 = u'Waldo-3'
-RK_VALUE4 = u'Waldo-4'
-RK_VALUE5 = u'Waldo-5'
-
-
-ITEM1 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE1},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE1},
-    u'relevant_data': {u'S': u'tata'},
-}
-ITEM2 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE1},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE2},
-    u'relevant_data': {u'S': u'tete'},
-}
-ITEM3 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE2},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE3},
-    u'relevant_data': {u'S': u'titi'},
-}
-ITEM4 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE2},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE4},
-    u'relevant_data': {u'S': u'toto'},
-}
-ITEM5 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE3},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE5},
-    u'relevant_data': {u'S': u'tutu'},
-}
-
-# Please note that most query features are not yet implemented hence not tested
-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
-
-        db = DynamoDB()
-        db.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)
-
-        db.data[TABLE_NAME1]  = self.t1
-        db.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_nominal(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        db = connect_boto()
-
-        expected = {
-            "Responses": {
-                "Table-HR": {
-                    "Items": [
-                        {"relevant_data": {"S": "tata"}, "hash_key": {"N": "123"}, "range_key": {"S": "Waldo-1"}},
-                        {"relevant_data": {"S": "tata"}, "hash_key": {"N": "123"}, "range_key": {"S": "Waldo-1"}},
-                    ],
-                    "ConsumedCapacityUnits": 1.0
-                },
-                "Table-H": {
-                    "Items": [
-                        {"relevant_data": {"S": "tutu"}, "hash_key": {"N": "789"}, "range_key": {"S": "Waldo-5"}},
-                    ],
-                    "ConsumedCapacityUnits": 0.5
-                }
-            }
-        }
-
-        ret = db.layer1.batch_get_item({
-            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}},
-                ],
-            },
-            TABLE_NAME2: {
-                u"Keys": [
-                    {u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE3}},
-                    {u"HashKeyElement": {TABLE_HK_TYPE: u"404"}},
-                ],
-            },
-        })
-        self.assertEqual(expected, ret)
-
-    def test_batch_get_item_filter_one(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        db = connect_boto()
-
-        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
-                }
-            }
-        }
-
-        ret = db.layer1.batch_get_item({
-            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}},
-                ],
-            },
-        })
-        self.assertEqual(expected, ret)
-
-    def test_batch_get_item_table_404(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-        from boto.exception import BotoServerError
-
-        db = connect_boto()
-
-        self.assertRaises(BotoServerError, db.layer1.batch_get_item, {
-            TABLE_NAME_404: {
-                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}},
-                ],
-            },
-            TABLE_NAME2: {
-                u"Keys": [
-                    {u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE3}},
-                ],
-            },
-        })
-
-    def test_batch_get_item_bad_key(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-        from boto.dynamodb.exceptions import DynamoDBValidationError
-
-        db = connect_boto()
-
-        self.assertRaises(DynamoDBValidationError, db.layer1.batch_get_item,
-        {
-            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}},
-                ],
-            },
-            TABLE_NAME2: {
-                u"Keys": [
-                    {u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE3}},
-                ],
-            },
-        })
-
-        self.assertRaises(DynamoDBValidationError, db.layer1.batch_get_item,
-        {
-            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}},
-                ],
-            },
-            TABLE_NAME2: {
-                u"Keys": [
-                    {u"HashKeyElement": {TABLE_HK_TYPE: HK_VALUE3}, u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE1}},
-                ],
-            },
-        })

ddbmock/tests/functional/boto/test_create_table.py

-# -*- coding: utf-8 -*-
-
-import unittest
-import boto
-
-TABLE_NAME1 = 'Table-1'
-TABLE_NAME2 = 'Table-2'
-TABLE_NAME_INVALID1 = 'Table-invalid 1'
-
-TABLE_RT = 45
-TABLE_WT = 123
-
-TABLE_SCHEMA1 = {
-    'hash_key_name': 'hash_key',
-    'hash_key_proto_value': int,
-    'range_key_name': 'range_key',
-    'range_key_proto_value': unicode,
-}
-
-TABLE_SCHEMA2 = {
-    'hash_key_name': 'hash_key',
-    'hash_key_proto_value': int,
-}
-
-TABLE_SCHEMA_INVALID1 = {
-    'hash_key_name': 'hash_key',
-    'hash_key_proto_value': unicode,
-}
-
-# Not much can be tested here as most bugs are caught by Boto :)
-
-class TestCreateTable(unittest.TestCase):
-    def setUp(self):
-        from ddbmock.database.db import DynamoDB
-        DynamoDB().hard_reset()
-
-    def tearDown(self):
-        from ddbmock.database.db import DynamoDB
-        DynamoDB().hard_reset()
-
-    def test_create_table_hash_range(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        db = connect_boto()
-
-        table = db.create_table(
-            name=TABLE_NAME1,
-            schema=db.create_schema(**TABLE_SCHEMA1),
-            read_units=TABLE_RT,
-            write_units=TABLE_WT,
-        )
-
-        self.assertEqual(TABLE_NAME1, table.name)
-        self.assertEqual(TABLE_RT, table.read_units)
-        self.assertEqual(TABLE_WT, table.write_units)
-        self.assertEqual(u'ACTIVE', table.status)
-        self.assertEqual(TABLE_SCHEMA1['hash_key_name'], table.schema.hash_key_name)
-        self.assertEqual(TABLE_SCHEMA1['range_key_name'], table.schema.range_key_name)
-        self.assertEqual(u'N', table.schema.hash_key_type)
-        self.assertEqual(u'S', table.schema.range_key_type)
-
-        data = DynamoDB().data
-        assert TABLE_NAME1 in data
-        table = data[TABLE_NAME1]
-
-        self.assertEqual(TABLE_NAME1, table.name)
-        self.assertEqual(TABLE_RT, table.rt)
-        self.assertEqual(TABLE_WT, table.wt)
-        self.assertEqual(TABLE_SCHEMA1['hash_key_name'], table.hash_key.name)
-        self.assertEqual(TABLE_SCHEMA1['range_key_name'], table.range_key.name)
-        self.assertEqual(u'N', table.hash_key.typename)
-        self.assertEqual(u'S', table.range_key.typename)
-
-    def test_create_table_hash(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        db = connect_boto()
-
-        table = db.create_table(
-            name=TABLE_NAME2,
-            schema=db.create_schema(**TABLE_SCHEMA2),
-            read_units=TABLE_RT,
-            write_units=TABLE_WT,
-        )
-
-        self.assertEqual(TABLE_NAME2, table.name)
-        self.assertEqual(TABLE_RT, table.read_units)
-        self.assertEqual(TABLE_WT, table.write_units)
-        self.assertEqual(u'ACTIVE', table.status)
-        self.assertEqual(TABLE_SCHEMA2['hash_key_name'], table.schema.hash_key_name)
-        self.assertEqual(u'N', table.schema.hash_key_type)
-        self.assertIsNone(table.schema.range_key_name)
-        self.assertIsNone(table.schema.range_key_type)
-
-        data = DynamoDB().data
-        assert TABLE_NAME2 in data
-        table = data[TABLE_NAME2]
-
-        self.assertEqual(TABLE_NAME2, table.name)
-        self.assertEqual(TABLE_RT, table.rt)
-        self.assertEqual(TABLE_WT, table.wt)
-        self.assertEqual(TABLE_SCHEMA2['hash_key_name'], table.hash_key.name)
-        self.assertEqual(u'N', table.hash_key.typename)
-        self.assertIsNone(table.range_key)
-
-
-    def test_create_table_invalid_name(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-        from boto.dynamodb.exceptions import DynamoDBValidationError as DDBValidationErr
-
-        db = connect_boto()
-
-        assert TABLE_NAME_INVALID1 not in DynamoDB().data
-
-        self.assertRaises(DDBValidationErr, db.create_table,
-            name=TABLE_NAME_INVALID1,
-            schema=db.create_schema(**TABLE_SCHEMA_INVALID1),
-            read_units=TABLE_RT,
-            write_units=TABLE_WT,
-        )

ddbmock/tests/functional/boto/test_delete_item.py

-# -*- coding: utf-8 -*-
-
-import unittest
-import boto
-
-TABLE_NAME = 'Table-HR'
-TABLE_NAME2 = 'Table-H'
-TABLE_NAME_404 = 'Waldo'
-TABLE_RT = 45
-TABLE_WT = 123
-TABLE_RT2 = 10
-TABLE_WT2 = 10
-TABLE_HK_NAME = u'hash_key'
-TABLE_HK_TYPE = u'N'
-TABLE_RK_NAME = u'range_key'
-TABLE_RK_TYPE = u'S'
-
-HK_VALUE = u'123'
-RK_VALUE = u'Decode this data if you are a coder'
-
-
-ITEM = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE},
-    u'relevant_data': {u'B': u'THVkaWEgaXMgdGhlIGJlc3QgY29tcGFueSBldmVyIQ=='},
-}
-ITEM2 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
-    u'relevant_data': {u'B': u'THVkaWEgaXMgdGhlIGJlc3QgY29tcGFueSBldmVyIQ=='},
-}
-
-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
-
-        db = DynamoDB()
-        db.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)
-
-        db.data[TABLE_NAME]  = self.t1
-        db.data[TABLE_NAME2] = self.t2
-
-        self.t1.put(ITEM, {})
-        self.t2.put(ITEM2, {})
-
-    def tearDown(self):
-        from ddbmock.database.db import DynamoDB
-        DynamoDB().hard_reset()
-
-    def test_delete_item_hr(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        db = connect_boto()
-
-        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.assertEqual({}, self.t1.data[HK_VALUE][RK_VALUE])
-
-    def test_delete_item_hr_old(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        db = connect_boto()
-
-        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.assertEqual({}, self.t1.data[HK_VALUE][RK_VALUE])
-
-    def test_delete_item_h(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        db = connect_boto()
-
-        key = {
-            u"HashKeyElement":  {TABLE_HK_TYPE: HK_VALUE},
-        }
-
-        self.assertEqual({
-                u'ConsumedCapacityUnits': 1,
-            },
-            db.layer1.delete_item(TABLE_NAME2, key),
-        )
-        self.assertEqual({}, self.t2.data[HK_VALUE][False])
-
-    def test_delete_item_h_old(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        db = connect_boto()
-
-        expected = {
-            u'ConsumedCapacityUnits': 1,
-            u'Attributes': ITEM2,
-        }
-
-        key = {
-            u"HashKeyElement":  {TABLE_HK_TYPE: HK_VALUE},
-        }
-
-        self.assertEqual(
-            expected,
-            db.layer1.delete_item(TABLE_NAME2, key, return_values=u'ALL_OLD'),
-        )
-        self.assertEqual({}, self.t1.data[HK_VALUE][False])
-
-    def test_delete_item_hr_missing_r(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-        from boto.dynamodb.exceptions import DynamoDBValidationError
-
-        db = connect_boto()
-
-        key = {
-            u"HashKeyElement":  {TABLE_HK_TYPE: HK_VALUE},
-        }
-
-        self.assertRaises(DynamoDBValidationError,
-                          db.layer1.delete_item,
-                          TABLE_NAME, key)
-
-    def test_delete_item_h_missing_h(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-        from boto.dynamodb.exceptions import DynamoDBValidationError
-
-        db = connect_boto()
-
-        key = {}
-
-        self.assertRaises(DynamoDBValidationError,
-                          db.layer1.delete_item,
-                          TABLE_NAME2, key)
-
-    def test_delete_item_h_expect_field_value_ok(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-        from boto.exception import DynamoDBResponseError
-
-        db = connect_boto()
-
-        ddb_expected = {
-            u'relevant_data': {
-                u'Exists': True,
-                u'Value': {u'B': u'THVkaWEgaXMgdGhlIGJlc3QgY29tcGFueSBldmVyIQ=='}
-            }
-        }
-
-        key = {
-            u"HashKeyElement":  {TABLE_HK_TYPE: HK_VALUE},
-            u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE},
-        }
-
-        db.layer1.delete_item(TABLE_NAME, key, expected=ddb_expected)
-        self.assertEqual({}, self.t1.data[HK_VALUE][RK_VALUE])
-
-    def test_delete_item_h_expect_field_value_fail(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-        from boto.exception import DynamoDBResponseError
-
-        db = connect_boto()
-
-        ddb_expected = {
-            u'relevant_data_et_bah_non': {
-                u'Exists': True,
-                u'Value': {u'B': u'THVkaWEgaXMgdGhlIGJlc3QgY29tcGFueSBldmVyIQ=='}
-            }
-        }
-
-        key = {
-            u"HashKeyElement":  {TABLE_HK_TYPE: HK_VALUE},
-            u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE},
-        }
-
-        self.assertRaisesRegexp(DynamoDBResponseError, 'ConditionalCheckFailedException',
-            db.layer1.delete_item,
-            TABLE_NAME, key, expected=ddb_expected
-        )
-        self.assertEqual(ITEM, self.t1.data[HK_VALUE][RK_VALUE])

ddbmock/tests/functional/boto/test_delete_table.py

-# -*- coding: utf-8 -*-
-
-import unittest
-import boto
-
-TABLE_NAME = 'Table-1'
-TABLE_NAME_404= 'Waldo'
-TABLE_RT = 45
-TABLE_WT = 123
-TABLE_HK_NAME = u'hash_key'
-TABLE_HK_TYPE = u'N'
-TABLE_RK_NAME = u'range_key'
-TABLE_RK_TYPE = u'S'
-
-class TestDeleteTables(unittest.TestCase):
-    def setUp(self):
-        from ddbmock.database.db import DynamoDB
-        from ddbmock.database.table import Table
-        from ddbmock.database.key import PrimaryKey
-
-        db = DynamoDB()
-        db.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)
-
-        db.data[TABLE_NAME] = t1
-
-    def tearDown(self):
-        from ddbmock.database.db import DynamoDB
-        DynamoDB().hard_reset()
-
-    def test_delete(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        db = connect_boto()
-
-        db.layer1.delete_table(TABLE_NAME)
-
-        data = DynamoDB().data
-        assert TABLE_NAME not in DynamoDB().data
-
-    def test_delete_404(self):
-        from ddbmock import connect_boto
-        from boto.exception import BotoServerError
-
-        db = connect_boto()
-
-        self.assertRaises(BotoServerError, db.layer1.delete_table,
-                          TABLE_NAME_404,
-                         )

ddbmock/tests/functional/boto/test_describe_table.py

-# -*- coding: utf-8 -*-
-
-import unittest
-import boto
-
-TABLE_NAME = 'Table-1'
-TABLE_NAME_404= 'Waldo'
-TABLE_RT = 45
-TABLE_WT = 123
-TABLE_HK_NAME = u'hash_key'
-TABLE_HK_TYPE = u'N'
-TABLE_RK_NAME = u'range_key'
-TABLE_RK_TYPE = u'S'
-
-class TestDescribeTables(unittest.TestCase):
-    def setUp(self):
-        from ddbmock.database.db import DynamoDB
-        from ddbmock.database.table import Table
-        from ddbmock.database.key import PrimaryKey
-
-        db = DynamoDB()
-        db.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)
-
-        db.data[TABLE_NAME] = t1
-
-    def tearDown(self):
-        from ddbmock.database.db import DynamoDB
-        DynamoDB().hard_reset()
-
-    def test_describe_table(self):
-        from ddbmock import connect_boto
-        db = connect_boto()
-
-        table = db.get_table(TABLE_NAME)
-
-        self.assertEqual(TABLE_NAME, table.name)
-        self.assertEqual(TABLE_RT, table.read_units)
-        self.assertEqual(TABLE_WT, table.write_units)
-        self.assertEqual(u'ACTIVE', table.status)
-        self.assertEqual(TABLE_HK_NAME, table.schema.hash_key_name)
-        self.assertEqual(TABLE_HK_TYPE, table.schema.hash_key_type)
-        self.assertEqual(TABLE_RK_NAME, table.schema.range_key_name)
-        self.assertEqual(TABLE_RK_TYPE, table.schema.range_key_type)
-
-    def describe_table_404(self):
-        from ddbmock import connect_boto
-        db = connect_boto()
-
-        self.assertRaises(DDBValidationErr, db.get_table,
-            TABLE_NAME_404,
-        )
-

ddbmock/tests/functional/boto/test_get_item.py

-# -*- coding: utf-8 -*-
-
-import unittest
-import boto
-
-TABLE_NAME = 'Table-HR'
-TABLE_NAME2 = 'Table-H'
-TABLE_NAME_404 = 'Waldo'
-TABLE_RT = 45
-TABLE_WT = 123
-TABLE_RT2 = 10
-TABLE_WT2 = 10
-TABLE_HK_NAME = u'hash_key'
-TABLE_HK_TYPE = u'N'
-TABLE_RK_NAME = u'range_key'
-TABLE_RK_TYPE = u'S'
-
-HK_VALUE = u'123'
-RK_VALUE = u'Decode this data if you are a coder'
-
-
-ITEM = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE},
-    u'relevant_data': {u'B': u'THVkaWEgaXMgdGhlIGJlc3QgY29tcGFueSBldmVyIQ=='},
-}
-ITEM2 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
-    u'relevant_data': {u'B': u'THVkaWEgaXMgdGhlIGJlc3QgY29tcGFueSBldmVyIQ=='},
-}
-
-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
-
-        db = DynamoDB()
-        db.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)
-
-        db.data[TABLE_NAME]  = self.t1
-        db.data[TABLE_NAME2] = self.t2
-
-        self.t1.put(ITEM, {})
-        self.t2.put(ITEM2, {})
-
-    def tearDown(self):
-        from ddbmock.database.db import DynamoDB
-        DynamoDB().hard_reset()
-
-    def test_get_hr(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        db = connect_boto()
-
-        expected = {
-            u'ConsumedCapacityUnits': 0.5,
-            u'Item': {
-                u'hash_key': {u'N': u'123'},
-                u'range_key': {u'S': u'Decode this data if you are a coder'},
-                u'relevant_data': {u'B': u'THVkaWEgaXMgdGhlIGJlc3QgY29tcGFueSBldmVyIQ=='}}
-        }
-
-        key = {
-            u"HashKeyElement":  {TABLE_HK_TYPE: HK_VALUE},
-            u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE},
-        }
-
-        self.assertEquals(expected, db.layer1.get_item(TABLE_NAME, key))
-
-    def test_get_hr_consistent(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        db = connect_boto()
-
-        expected = {
-            u'ConsumedCapacityUnits': 1,
-            u'Item': {
-                u'hash_key': {u'N': u'123'},
-                u'range_key': {u'S': u'Decode this data if you are a coder'},
-                u'relevant_data': {u'B': u'THVkaWEgaXMgdGhlIGJlc3QgY29tcGFueSBldmVyIQ=='}}
-        }
-
-        key = {
-            u"HashKeyElement":  {TABLE_HK_TYPE: HK_VALUE},
-            u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE},
-        }
-
-        self.assertEquals(expected, db.layer1.get_item(TABLE_NAME, key, consistent_read=True))
-
-    def test_get_h(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        db = connect_boto()
-
-        expected = {
-            u'ConsumedCapacityUnits': 0.5,
-            u'Item': {
-                u'hash_key': {u'N': u'123'},
-                u'relevant_data': {u'B': u'THVkaWEgaXMgdGhlIGJlc3QgY29tcGFueSBldmVyIQ=='}}
-        }
-
-        key = {
-            u"HashKeyElement":  {TABLE_HK_TYPE: HK_VALUE},
-        }
-
-        self.assertEquals(expected, db.layer1.get_item(TABLE_NAME2, key))
-
-    def test_get_hr_attr_to_get(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        db = connect_boto()
-
-        expected = {
-            u'ConsumedCapacityUnits': 0.5,
-            u'Item': {
-                u'relevant_data': {u'B': u'THVkaWEgaXMgdGhlIGJlc3QgY29tcGFueSBldmVyIQ=='}}
-        }
-
-        key = {
-            u"HashKeyElement":  {TABLE_HK_TYPE: HK_VALUE},
-            u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE},
-        }
-
-        self.assertEquals(expected, db.layer1.get_item(TABLE_NAME, key, attributes_to_get=[u'relevant_data']))

ddbmock/tests/functional/boto/test_list_tables.py

-# -*- coding: utf-8 -*-
-
-import unittest
-import boto
-
-TABLE_NAME1 = 'Table-1'
-TABLE_NAME2 = 'Table-2'
-
-class TestListTables(unittest.TestCase):
-    def setUp(self):
-        from ddbmock.database.db import DynamoDB
-        from ddbmock.database.table import Table
-        from ddbmock.database.key import PrimaryKey
-
-        db = DynamoDB()
-        db.hard_reset()
-
-        hash_key = PrimaryKey('hash_key', 'N')
-        range_key = PrimaryKey('range_key', 'S')
-
-        t1 = Table(TABLE_NAME1, 10, 10, hash_key, range_key)
-        t2 = Table(TABLE_NAME2, 10, 10, hash_key, range_key)
-
-        db.data[TABLE_NAME1] = t1
-        db.data[TABLE_NAME2] = t2
-
-    def tearDown(self):
-        from ddbmock.database.db import DynamoDB
-        DynamoDB().hard_reset()
-
-    def test_list_tables(self):
-        from ddbmock import connect_boto
-        db = connect_boto()
-
-        expected = [TABLE_NAME1, TABLE_NAME2]
-
-        self.assertEqual(expected, db.list_tables())
-

ddbmock/tests/functional/boto/test_put_item.py

-# -*- coding: utf-8 -*-
-
-import unittest
-import boto
-
-TABLE_NAME = 'Table-HR'
-TABLE_NAME2 = 'Table-H'
-TABLE_NAME_404 = 'Waldo'
-TABLE_RT = 45
-TABLE_WT = 123
-TABLE_RT2 = 10
-TABLE_WT2 = 10
-TABLE_HK_NAME = u'hash_key'
-TABLE_HK_TYPE = u'N'
-TABLE_RK_NAME = u'range_key'
-TABLE_RK_TYPE = u'S'
-
-HK_VALUE = u'123'
-RK_VALUE = u'Decode this data if you are a coder'
-
-
-ITEM = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE},
-    u'relevant_data': {u'B': u'THVkaWEgaXMgdGhlIGJlc3QgY29tcGFueSBldmVyIQ=='},
-}
-ITEM2 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE},
-    u'irelevant_data': {u'B': u'WW91IHdpc2ggeW91IGNvdWxkIGNoYW5nZSB5b3VyIGpvYi4uLg=='},
-}
-ITEM3 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
-    u'relevant_data': {u'B': u'THVkaWEgaXMgdGhlIGJlc3QgY29tcGFueSBldmVyIQ=='},
-}
-ITEM4 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
-    u'irelevant_data': {u'B': u'WW91IHdpc2ggeW91IGNvdWxkIGNoYW5nZSB5b3VyIGpvYi4uLg=='},
-}
-ITEM5 = {
-    u'relevant_data': {u'B': u'THVkaWEgaXMgdGhlIGJlc3QgY29tcGFueSBldmVyIQ=='},
-}
-
-class TestPutItem(unittest.TestCase):
-    def setUp(self):
-        from ddbmock.database.db import DynamoDB
-        from ddbmock.database.table import Table
-        from ddbmock.database.key import PrimaryKey
-
-        db = DynamoDB()
-        db.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)
-
-        db.data[TABLE_NAME]  = self.t1
-        db.data[TABLE_NAME2] = self.t2
-
-    def tearDown(self):
-        from ddbmock.database.db import DynamoDB
-        DynamoDB().hard_reset()
-
-    # TODO test with expected
-
-    def test_put_hr(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        db = connect_boto()
-
-        self.assertEqual({
-                u'ConsumedCapacityUnits': 1,
-            },
-            db.layer1.put_item(TABLE_NAME, ITEM),
-        )
-        self.assertEqual(ITEM, self.t1.data[HK_VALUE][RK_VALUE])
-
-        self.assertEqual({
-                u'ConsumedCapacityUnits': 1,
-                u'Attributes': ITEM,
-            },
-            db.layer1.put_item(TABLE_NAME, ITEM2, return_values=u'ALL_OLD'),
-        )
-
-    def test_put_h(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        db = connect_boto()
-
-        self.assertEqual({
-                u'ConsumedCapacityUnits': 1,
-            },
-            db.layer1.put_item(TABLE_NAME2, ITEM3),
-        )
-        self.assertEqual(ITEM3, self.t2.data[HK_VALUE][False])
-
-        self.assertEqual({
-                u'ConsumedCapacityUnits': 1,
-                u'Attributes': ITEM3,
-            },
-            db.layer1.put_item(TABLE_NAME2, ITEM4, return_values=u'ALL_OLD'),
-        )
-
-    def test_put_hr_404(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-        from boto.exception import DynamoDBResponseError
-
-        db = connect_boto()
-
-        self.assertRaisesRegexp(DynamoDBResponseError, 'ResourceNotFoundException',
-                                db.layer1.put_item,
-                                TABLE_NAME_404, ITEM)
-
-    def test_put_h_404(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-        from boto.exception import DynamoDBResponseError
-
-        db = connect_boto()
-
-        self.assertRaisesRegexp(DynamoDBResponseError, 'ResourceNotFoundException',
-                                db.layer1.put_item,
-                                TABLE_NAME_404, ITEM3)
-
-    def test_put_hr_missing_r(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-        from boto.dynamodb.exceptions import DynamoDBValidationError
-
-        db = connect_boto()
-
-        self.assertRaises(DynamoDBValidationError,
-                          db.layer1.put_item,
-                          TABLE_NAME, ITEM3)
-
-    def test_put_h_missing_h(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-        from boto.dynamodb.exceptions import DynamoDBValidationError
-
-        db = connect_boto()
-
-        self.assertRaises(DynamoDBValidationError,
-                          db.layer1.put_item,
-                          TABLE_NAME2, ITEM5)
-
-    def test_put_h_expect_no_exist(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-        from boto.exception import DynamoDBResponseError
-
-        db = connect_boto()
-
-        ddb_expected = {
-            TABLE_HK_NAME: {u'Exists': False}
-        }
-
-        db.layer1.put_item(TABLE_NAME2, ITEM3, expected=ddb_expected)
-
-        self.assertRaisesRegexp(DynamoDBResponseError, 'ConditionalCheckFailedException',
-            db.layer1.put_item,
-            TABLE_NAME2, ITEM4, expected=ddb_expected
-        )
-        self.assertEqual(ITEM3, self.t2.data[HK_VALUE][False])
-
-    def test_put_h_expect_field_value(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-        from boto.exception import DynamoDBResponseError
-
-        db = connect_boto()
-
-        ddb_expected = {
-            u'relevant_data': {
-                u'Exists': True,
-                u'Value': {u'B': u'THVkaWEgaXMgdGhlIGJlc3QgY29tcGFueSBldmVyIQ=='}
-            }
-        }
-
-        db.layer1.put_item(TABLE_NAME2, ITEM3)
-        self.assertEqual(ITEM3, self.t2.data[HK_VALUE][False])
-        db.layer1.put_item(TABLE_NAME2, ITEM4, expected=ddb_expected)
-        self.assertEqual(ITEM4, self.t2.data[HK_VALUE][False])
-        self.assertRaisesRegexp(DynamoDBResponseError, 'ConditionalCheckFailedException',
-            db.layer1.put_item,
-            TABLE_NAME2, ITEM4, expected=ddb_expected
-        )

ddbmock/tests/functional/boto/test_query.py

-# -*- coding: utf-8 -*-
-
-import unittest
-import boto
-
-TABLE_NAME = 'Table-HR'
-TABLE_NAME_404 = 'Waldo'
-TABLE_RT = 45
-TABLE_WT = 123
-TABLE_RT2 = 10
-TABLE_WT2 = 10
-TABLE_HK_NAME = u'hash_key'
-TABLE_HK_TYPE = u'N'
-TABLE_RK_NAME = u'range_key'
-TABLE_RK_TYPE = u'S'
-
-HK_VALUE = u'123'
-RK_VALUE1 = u'Waldo-1'
-RK_VALUE2 = u'Waldo-2'
-RK_VALUE3 = u'Waldo-3'
-RK_VALUE4 = u'Waldo-4'
-RK_VALUE5 = u'Waldo-5'
-
-
-ITEM1 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE1},
-    u'relevant_data': {u'S': u'tata'},
-}
-ITEM2 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE2},
-    u'relevant_data': {u'S': u'tete'},
-}
-ITEM3 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE3},
-    u'relevant_data': {u'S': u'titi'},
-}
-ITEM4 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE4},
-    u'relevant_data': {u'S': u'toto'},
-}
-ITEM5 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE5},
-    u'relevant_data': {u'S': u'tutu'},
-}
-
-# Please note that most query features are not yet implemented hence not tested
-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
-
-        db = DynamoDB()
-        db.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)
-
-        db.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_all(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        expected = {
-            u"Count": 5,
-            u"Items": [
-                {u"relevant_data": {u"S": u"titi"}, u"hash_key": {u"N": u"123"}, u"range_key": {u"S": u"Waldo-3"}},
-                {u"relevant_data": {u"S": u"tete"}, u"hash_key": {u"N": u"123"}, u"range_key": {u"S": u"Waldo-2"}},
-                {u"relevant_data": {u"S": u"tata"}, u"hash_key": {u"N": u"123"}, u"range_key": {u"S": u"Waldo-1"}},
-                {u"relevant_data": {u"S": u"tutu"}, u"hash_key": {u"N": u"123"}, u"range_key": {u"S": u"Waldo-5"}},
-                {u"relevant_data": {u"S": u"toto"}, u"hash_key": {u"N": u"123"}, u"range_key": {u"S": u"Waldo-4"}},
-            ],
-            u"ConsumedCapacityUnits": 2.5,
-        }
-
-        db = connect_boto()
-
-        ret = db.layer1.query(TABLE_NAME, {TABLE_HK_TYPE: HK_VALUE})
-        self.assertEqual(expected, ret)
-
-    def test_query_all_filter_fields(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        expected = {
-            u"Count": 5,
-            u"Items": [
-                {u"relevant_data": {u"S": "titi"}},
-                {u"relevant_data": {u"S": "tete"}},
-                {u"relevant_data": {u"S": "tata"}},
-                {u"relevant_data": {u"S": "tutu"}},
-                {u"relevant_data": {u"S": "toto"}},
-            ],
-            u"ConsumedCapacityUnits": 2.5,
-        }
-        fields = [u'relevant_data']
-
-        db = connect_boto()
-
-        ret = db.layer1.query(TABLE_NAME, {TABLE_HK_TYPE: HK_VALUE}, None, fields)
-        self.assertEqual(expected, ret)
-
-    # No need to test all conditions/type mismatch as they are unit tested
-    def test_query_condition_filter_fields(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        expected = {
-            u"Count": 3,
-            u"Items": [
-                {u"relevant_data": {u"S": u"titi"}},
-                {u"relevant_data": {u"S": u"tutu"}},
-                {u"relevant_data": {u"S": u"toto"}},
-            ],
-            u"ConsumedCapacityUnits": 1.5,
-        }
-
-        condition = {"AttributeValueList":[{"S":"Waldo-2"}],"ComparisonOperator":"GT"}
-        fields = [u'relevant_data']
-
-        db = connect_boto()
-
-        ret = db.layer1.query(TABLE_NAME, {TABLE_HK_TYPE: HK_VALUE}, condition, fields)
-        self.assertEqual(expected, ret)
-

ddbmock/tests/functional/boto/test_scan.py

-# -*- coding: utf-8 -*-
-
-import unittest
-import boto
-
-TABLE_NAME = 'Table-HR'
-TABLE_NAME_404 = 'Waldo'
-TABLE_RT = 45
-TABLE_WT = 123
-TABLE_RT2 = 10
-TABLE_WT2 = 10
-TABLE_HK_NAME = u'hash_key'
-TABLE_HK_TYPE = u'N'
-TABLE_RK_NAME = u'range_key'
-TABLE_RK_TYPE = u'S'
-
-HK_VALUE1 = u'123'
-HK_VALUE2 = u'456'
-HK_VALUE3 = u'789'
-RK_VALUE1 = u'Waldo-1'
-RK_VALUE2 = u'Waldo-2'
-RK_VALUE3 = u'Waldo-3'
-RK_VALUE4 = u'Waldo-4'
-RK_VALUE5 = u'Waldo-5'
-
-
-ITEM1 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE1},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE1},
-    u'relevant_data': {u'S': u'tata'},
-}
-ITEM2 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE1},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE2},
-    u'relevant_data': {u'S': u'tete'},
-}
-ITEM3 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE2},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE3},
-    u'relevant_data': {u'S': u'titi'},
-}
-ITEM4 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE3},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE4},
-    u'relevant_data': {u'S': u'toto'},
-}
-ITEM5 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE3},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE5},
-    u'relevant_data': {u'S': u'tutu'},
-}
-
-# Please note that most query features are not yet implemented hence not tested
-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
-
-        db = DynamoDB()
-        db.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)
-
-        db.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_all(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        expected = {
-            u"Count": 5,
-            u"ScannedCount": 5,
-            u"Items": [
-                {u"relevant_data": {u"S": u"tete"}, u"hash_key": {u"N": u"123"}, u"range_key": {u"S": u"Waldo-2"}},
-                {u"relevant_data": {u"S": u"tata"}, u"hash_key": {u"N": u"123"}, u"range_key": {u"S": u"Waldo-1"}},
-                {u"relevant_data": {u"S": u"tutu"}, u"hash_key": {u"N": u"789"}, u"range_key": {u"S": u"Waldo-5"}},
-                {u"relevant_data": {u"S": u"toto"}, u"hash_key": {u"N": u"789"}, u"range_key": {u"S": u"Waldo-4"}},
-                {u"relevant_data": {u"S": u"titi"}, u"hash_key": {u"N": u"456"}, u"range_key": {u"S": u"Waldo-3"}},
-            ],
-            u"ConsumedCapacityUnits": 2.5,
-        }
-
-        db = connect_boto()
-
-        ret = db.layer1.scan(TABLE_NAME, None)
-        self.assertEqual(expected, ret)
-
-    def test_scan_all_filter_fields(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        expected = {
-            u"Count": 5,
-            u"ScannedCount": 5,
-            u"Items": [
-                {u"relevant_data": {u"S": "tete"}},
-                {u"relevant_data": {u"S": "tata"}},
-                {u"relevant_data": {u"S": "tutu"}},
-                {u"relevant_data": {u"S": "toto"}},
-                {u"relevant_data": {u"S": "titi"}},
-            ],
-            u"ConsumedCapacityUnits": 2.5,
-        }
-        fields = [u'relevant_data']
-
-        db = connect_boto()
-
-        ret = db.layer1.scan(TABLE_NAME, None, fields)
-        self.assertEqual(expected, ret)
-
-    # No need to test all conditions/type mismatch as they are unit tested
-    def test_scan_condition_filter_fields_in(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        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": 2.5,
-        }
-
-        conditions = {
-            "relevant_data": {
-                "AttributeValueList": [{"S":"toto"},{"S":"titi"},{"S":"tata"}],
-                "ComparisonOperator": "IN",
-            }
-        }
-        fields = [u'relevant_data']
-
-        db = connect_boto()
-
-        ret = db.layer1.scan(TABLE_NAME, conditions, fields)
-        self.assertEqual(expected, ret)
-
-    def test_scan_condition_filter_fields_contains(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        expected = {
-            u"Count": 1,
-            u"ScannedCount": 5,
-            u"Items": [
-                {u"relevant_data": {u"S": u"toto"}},
-            ],
-            u"ConsumedCapacityUnits": 2.5,
-        }
-
-        conditions = {
-            "relevant_data": {
-                "AttributeValueList": [{"S":"to"}],
-                "ComparisonOperator": "CONTAINS",
-            }
-        }
-        fields = [u'relevant_data']
-
-        db = connect_boto()
-
-        ret = db.layer1.scan(TABLE_NAME, conditions, fields)
-        self.assertEqual(expected, ret)
-
-    def test_scan_validation_error(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-        from boto.dynamodb.exceptions import DynamoDBValidationError
-
-        expected = {
-            u"Count": 1,
-            u"ScannedCount": 5,
-            u"Items": [
-                {u"relevant_data": {u"S": u"toto"}},
-            ],
-            u"ConsumedCapacityUnits": 2.5,
-        }
-
-        conditions = {
-            "relevant_data": {
-                "AttributeValueList": [{"S":"to"},{"S":"ta"}],
-                "ComparisonOperator": "CONTAINS",
-            }
-        }
-        fields = [u'relevant_data']
-
-        db = connect_boto()
-
-        self.assertRaises(DynamoDBValidationError, db.layer1.scan,
-            TABLE_NAME, conditions, fields
-        )

ddbmock/tests/functional/boto/test_update_item.py

-# -*- coding: utf-8 -*-
-
-import unittest
-import boto
-from decimal import Decimal
-
-TABLE_NAME = 'Table-HR'
-TABLE_NAME2 = 'Table-H'
-TABLE_NAME_404 = 'Waldo'
-TABLE_RT = 45
-TABLE_WT = 123
-TABLE_RT2 = 10
-TABLE_WT2 = 10
-TABLE_HK_NAME = u'hash_key'
-TABLE_HK_TYPE = u'N'
-TABLE_RK_NAME = u'range_key'
-TABLE_RK_TYPE = u'S'
-
-HK_VALUE = u'123'
-HK_VALUE2 = u'456'
-RK_VALUE = u'Decode this data if you are a coder'
-
-RELEVANT_FIELD = {'S': 'Illyse'}
-IRELEVANT_FIELD = {'B': 'WW91IHdpc2ggeW91IGNvdWxkIGNoYW5nZSB5b3VyIGpvYi4uLg=='}
-
-FIELD_NAME = u"relevant_data"
-FIELD_SET_NAME = u"data list"
-FIELD_NUM_NAME = u"counter"
-
-ITEM = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
-    TABLE_RK_NAME: {TABLE_RK_TYPE: RK_VALUE},
-    FIELD_NAME: {u'B': u'THVkaWEgaXMgdGhlIGJlc3QgY29tcGFueSBldmVyIQ=='},
-    FIELD_SET_NAME: {u'SS': [u'item1', u'item2', u'item3', u'item4']}
-
-}
-ITEM2 = {
-    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
-    u'relevant_data': {u'B': u'THVkaWEgaXMgdGhlIGJlc3QgY29tcGFueSBldmVyIQ=='},
-    FIELD_NUM_NAME: {u'N': u'42'}
-
-}
-
-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
-
-        db = DynamoDB()
-        db.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)
-
-        db.data[TABLE_NAME]  = self.t1
-        db.data[TABLE_NAME2] = self.t2
-
-        self.t1.put(ITEM, {})
-        self.t2.put(ITEM2, {})
-
-    def tearDown(self):
-        from ddbmock.database.db import DynamoDB
-        DynamoDB().hard_reset()
-
-    def test_update_item_put_hr(self):
-        from ddbmock import connect_boto
-        db = connect_boto()
-
-        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.data[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.data[HK_VALUE][RK_VALUE]['relevant_data'])
-        self.assertEqual(IRELEVANT_FIELD, self.t1.data[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(HK_VALUE2, self.t1.data[HK_VALUE2][RK_VALUE][TABLE_HK_NAME])
-        self.assertEqual(RK_VALUE, self.t1.data[HK_VALUE2][RK_VALUE][TABLE_RK_NAME])
-        self.assertEqual(RELEVANT_FIELD, self.t1.data[HK_VALUE2][RK_VALUE]['relevant_data'])
-
-    def test_update_item_put_h(self):
-        from ddbmock import connect_boto
-        db = connect_boto()
-
-        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.data[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.data[HK_VALUE][False]['relevant_data'])
-        self.assertEqual(IRELEVANT_FIELD, self.t2.data[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(HK_VALUE2, self.t2.data[HK_VALUE2][False][TABLE_HK_NAME])
-        self.assertEqual(RELEVANT_FIELD, self.t2.data[HK_VALUE2][False]['relevant_data'])
-
-    def test_update_item_delete_primary_key_fails(self):
-        from ddbmock import connect_boto
-        from boto.dynamodb.exceptions import DynamoDBValidationError
-
-        db = connect_boto()
-
-        key = {
-            u"HashKeyElement":  {TABLE_HK_TYPE: HK_VALUE},
-            u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE},
-        }
-
-        self.assertRaises(DynamoDBValidationError,
-            db.layer1.update_item,
-            TABLE_NAME, key, {TABLE_RK_NAME: {'Action': 'DELETE'}}
-        )
-        self.assertEqual({TABLE_RK_TYPE: RK_VALUE}, self.t1.data[HK_VALUE][RK_VALUE][TABLE_RK_NAME])
-
-        self.assertRaises(DynamoDBValidationError,
-            db.layer1.update_item,
-            TABLE_NAME, key, {TABLE_HK_NAME: {'Action': 'DELETE'}}
-        )
-        self.assertEqual({TABLE_HK_TYPE: HK_VALUE}, self.t1.data[HK_VALUE][RK_VALUE][TABLE_HK_NAME])
-
-    def test_update_item_delete_field_ok(self):
-        from ddbmock import connect_boto
-        from boto.dynamodb.exceptions import DynamoDBValidationError
-
-        db = connect_boto()
-
-        key = {
-            u"HashKeyElement":  {TABLE_HK_TYPE: HK_VALUE},
-            u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE},
-        }
-
-        db.layer1.update_item(TABLE_NAME, key, {
-            FIELD_NAME: {'Action': 'DELETE'},
-        })
-        self.assertNotIn(FIELD_NAME, self.t1.data[HK_VALUE][RK_VALUE])
-
-    def test_update_item_delete_field_set_ok(self):
-        from ddbmock import connect_boto
-        from boto.dynamodb.exceptions import DynamoDBValidationError
-
-        db = connect_boto()
-
-        expected1 = {u'SS': [u'item1', u'item2', u'item3', u'item4']}
-        expected2 = {u'SS': [u'item3', u'item1']}
-
-        key = {
-            u"HashKeyElement":  {TABLE_HK_TYPE: HK_VALUE},
-            u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE},
-        }
-
-        # Can not remove a scalar value, even from a set
-        self.assertRaises(DynamoDBValidationError,
-            db.layer1.update_item,
-            TABLE_NAME, key, {
-                FIELD_SET_NAME: {'Action': 'DELETE', u'Value': {u'S': u'item1'}},
-            }
-        )
-        self.assertEqual(expected1, self.t1.data[HK_VALUE][RK_VALUE][FIELD_SET_NAME])
-
-        # remove a couple of existing or not item from the field
-        db.layer1.update_item(TABLE_NAME, key, {
-            FIELD_SET_NAME: {'Action': 'DELETE', u'Value': {u'SS': [u'item2', u'item4', u'item6']}},
-        })
-        self.assertEqual(expected2, self.t1.data[HK_VALUE][RK_VALUE][FIELD_SET_NAME])
-
-        # Field shoud disapear (Empty)
-        db.layer1.update_item(TABLE_NAME, key, {
-            FIELD_SET_NAME: {'Action': 'DELETE', u'Value': {u'SS': [u'item1', u'item3', u'item6']}},
-        })
-        self.assertNotIn(FIELD_SET_NAME, self.t1.data[HK_VALUE][RK_VALUE])
-
-    def test_update_item_delete_field_set_bad_type(self):
-        from ddbmock import connect_boto
-        from boto.dynamodb.exceptions import DynamoDBValidationError
-
-        db = connect_boto()
-
-        expected = {u'SS': [u'item1', u'item2', u'item3', u'item4']}
-
-        key = {
-            u"HashKeyElement":  {TABLE_HK_TYPE: HK_VALUE},
-            u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE},
-        }
-
-        self.assertRaises(DynamoDBValidationError,
-            db.layer1.update_item,
-            TABLE_NAME, key, {
-                FIELD_SET_NAME: {'Action': 'DELETE', u'Value': {u'B': u'item1'}},
-            }
-        )
-        self.assertEqual(expected, self.t1.data[HK_VALUE][RK_VALUE][FIELD_SET_NAME])
-
-        self.assertRaises(DynamoDBValidationError,
-            db.layer1.update_item,
-            TABLE_NAME, key, {
-                FIELD_SET_NAME: {'Action': 'DELETE', u'Value': {u'BS': [u'item2', u'item4', u'item6']}},
-            }
-        )
-        self.assertEqual(expected, self.t1.data[HK_VALUE][RK_VALUE][FIELD_SET_NAME])
-
-    def test_update_item_increment(self):
-        from ddbmock import connect_boto
-        from boto.dynamodb.exceptions import DynamoDBValidationError
-
-        db = connect_boto()
-
-        key = {
-            u"HashKeyElement":  {TABLE_HK_TYPE: HK_VALUE},
-        }
-
-        ADD_VALUE = 2
-
-        expected = {u'N': unicode(42 + ADD_VALUE)}
-
-        # regular increment
-        db.layer1.update_item(TABLE_NAME2, key, {
-            FIELD_NUM_NAME: {'Action': 'ADD', u'Value': {u'N': unicode(ADD_VALUE)}},
-        })
-        self.assertEqual(expected, self.t2.data[HK_VALUE][False][FIELD_NUM_NAME])
-
-    def test_update_item_push_to_set_ok(self):
-        from ddbmock import connect_boto
-        from boto.dynamodb.exceptions import DynamoDBValidationError
-
-        db = connect_boto()
-
-        expected1 = {u'SS': [u'item1', u'item2', u'item3', u'item4']}
-        expected2 = {u'SS': [u'item2', u'item3', u'item1', u'item4', u'item5']}
-
-        key = {
-            u"HashKeyElement":  {TABLE_HK_TYPE: HK_VALUE},
-            u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE},
-        }
-
-        self.assertRaises(DynamoDBValidationError,
-            db.layer1.update_item,
-            TABLE_NAME, key, {
-                FIELD_SET_NAME: {'Action': 'ADD', u'Value': {u'S': u'item5'}},
-            }
-        )
-        self.assertEqual(expected1, self.t1.data[HK_VALUE][RK_VALUE][FIELD_SET_NAME])
-
-        db.layer1.update_item(TABLE_NAME, key, {
-            FIELD_SET_NAME: {'Action': 'ADD', u'Value': {u'SS': [u'item5']}},
-        })
-        self.assertEqual(expected2, self.t1.data[HK_VALUE][RK_VALUE][FIELD_SET_NAME])
-
-    def test_update_item_push_to_non_set_fail(self):
-        # sometimes weird black magic types occures in test. these are related
-        # to internal "DB" logic. it does not affect real API output at all
-        from ddbmock import connect_boto
-        from boto.dynamodb.exceptions import DynamoDBValidationError
-
-        db = connect_boto()
-
-        expected1 = {u'SS': [u'item1', u'item2', u'item3', u'item4']}
-
-        key = {
-            u"HashKeyElement":  {TABLE_HK_TYPE: HK_VALUE},
-            u"RangeKeyElement": {TABLE_RK_TYPE: RK_VALUE},
-        }
-
-        self.assertRaises(DynamoDBValidationError,
-            db.layer1.update_item,
-            TABLE_NAME, key, {
-                FIELD_NAME: {'Action': 'ADD', u'Value': {u'B': u'item5'}},
-            }
-        )
-        self.assertEqual(expected1, self.t1.data[HK_VALUE][RK_VALUE][FIELD_SET_NAME])

ddbmock/tests/functional/boto/test_update_table.py

-# -*- coding: utf-8 -*-
-
-import unittest
-import boto
-
-TABLE_NAME = 'Table-1'
-TABLE_NAME_404 = 'Waldo'
-TABLE_RT = 45
-TABLE_WT = 123
-TABLE_RT2 = 10
-TABLE_WT2 = 10
-TABLE_HK_NAME = u'hash_key'
-TABLE_HK_TYPE = u'N'
-TABLE_RK_NAME = u'range_key'
-TABLE_RK_TYPE = u'S'
-
-class TestUpdateTables(unittest.TestCase):
-    def setUp(self):
-        from ddbmock.database.db import DynamoDB
-        from ddbmock.database.table import Table
-        from ddbmock.database.key import PrimaryKey
-
-        db = DynamoDB()
-        db.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)
-
-        db.data[TABLE_NAME] = t1
-
-    def tearDown(self):
-        from ddbmock.database.db import DynamoDB
-        DynamoDB().hard_reset()
-
-    def test_update(self):
-        from ddbmock import connect_boto
-        from ddbmock.database.db import DynamoDB
-
-        db = connect_boto()
-
-        db.layer1.update_table(TABLE_NAME, {'ReadCapacityUnits': TABLE_RT2,
-                                            'WriteCapacityUnits': TABLE_WT2})
-
-        data = DynamoDB().data
-        assert TABLE_NAME in DynamoDB().data
-        table = DynamoDB().data[TABLE_NAME]
-
-        self.assertEqual(TABLE_NAME, table.name)
-        self.assertEqual(TABLE_RT2, table.rt)
-        self.assertEqual(TABLE_WT2, table.wt)
-
-    def test_update_404(self):
-        from ddbmock import connect_boto
-        from boto.exception import BotoServerError
-
-        db = connect_boto()
-
-        self.assertRaises(BotoServerError, db.layer1.update_table,
-                          TABLE_NAME_404,
-                          {'ReadCapacityUnits': TABLE_RT2,
-                           'WriteCapacityUnits': TABLE_WT2},
-                         )

ddbmock/tests/unit/__init__.py

-# -*- coding: utf-8 -*-

ddbmock/tests/unit/test_item_field_comparison.py

-# -*- coding: utf-8 -*-
-
-import unittest
-
-
-class TestItemFieldComparison(unittest.TestCase):
-    def test_eq(self):
-        from ddbmock.database.comparison import eq
-
-        self.assertTrue(eq({u'S': u'waldo'}, {u'S': u'waldo'}))
-        self.assertFalse(eq({u'S': u'waldo'}, {u'S': u'on-time'}))
-        self.assertFalse(eq(None, {u'S': u'on-time'}))
-
-    def test_le(self):
-        from ddbmock.database.comparison import le
-
-        self.assertTrue(le({u'S': u'waldo'}, {u'S': u'waldo'}))
-        self.assertTrue(le({u'S': u'waldo'}, {u'S': u'waldo1'}))
-        self.assertFalse(le({u'S': u'waldo'}, {u'S': u'wald'}))
-
-        self.assertTrue(le({u'N': u'42'}, {u'N': u'42'}))
-        self.assertTrue(le({u'N': u'42'}, {u'N': u'42.001'}))
-        self.assertFalse(le({u'N': u'42'}, {u'N': u'7'}))
-
-        self.assertFalse(le(None, {u'N': u'7'}))
-
-    def test_lt(self):
-        from ddbmock.database.comparison import lt
-
-        self.assertFalse(lt({u'S': u'waldo'}, {u'S': u'waldo'}))
-        self.assertTrue(lt({u'S': u'waldo'}, {u'S': u'waldo1'}))
-        self.assertFalse(lt({u'S': u'waldo'}, {u'S': u'wald'}))
-
-        self.assertFalse(lt({u'N': u'42'}, {u'N': u'42'}))
-        self.assertTrue(lt({u'N': u'42'}, {u'N': u'42.001'}))
-        self.assertFalse(lt({u'N': u'42'}, {u'N': u'7'}))
-
-        self.assertFalse(lt(None, {u'N': u'7'}))
-
-    def test_ge(self):
-        from ddbmock.database.comparison import ge