OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved |
| 2 # |
| 3 # Permission is hereby granted, free of charge, to any person obtaining a |
| 4 # copy of this software and associated documentation files (the |
| 5 # "Software"), to deal in the Software without restriction, including |
| 6 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 7 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 8 # persons to whom the Software is furnished to do so, subject to the fol- |
| 9 # lowing conditions: |
| 10 # |
| 11 # The above copyright notice and this permission notice shall be included |
| 12 # in all copies or substantial portions of the Software. |
| 13 # |
| 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 20 # IN THE SOFTWARE. |
| 21 # |
| 22 import time |
| 23 from tests.unit import unittest |
| 24 |
| 25 from boto.dynamodb.layer2 import Layer2 |
| 26 from boto.dynamodb.table import Table |
| 27 from boto.dynamodb.schema import Schema |
| 28 |
| 29 |
| 30 class TestDynamoDBTable(unittest.TestCase): |
| 31 dynamodb = True |
| 32 |
| 33 def setUp(self): |
| 34 self.dynamodb = Layer2() |
| 35 self.schema = Schema.create(('foo', 'N'), ('bar', 'S')) |
| 36 self.table_name = 'testtable%s' % int(time.time()) |
| 37 |
| 38 def create_table(self, table_name, schema, read_units, write_units): |
| 39 result = self.dynamodb.create_table(table_name, schema, read_units, writ
e_units) |
| 40 self.addCleanup(self.dynamodb.delete_table, result) |
| 41 return result |
| 42 |
| 43 def assertAllEqual(self, *items): |
| 44 first = items[0] |
| 45 for item in items[1:]: |
| 46 self.assertEqual(first, item) |
| 47 |
| 48 def test_table_retrieval_parity(self): |
| 49 created_table = self.dynamodb.create_table( |
| 50 self.table_name, self.schema, 1, 1) |
| 51 created_table.refresh(wait_for_active=True) |
| 52 |
| 53 retrieved_table = self.dynamodb.get_table(self.table_name) |
| 54 |
| 55 constructed_table = self.dynamodb.table_from_schema(self.table_name, |
| 56 self.schema) |
| 57 |
| 58 # All three tables should have the same name |
| 59 # and schema attributes. |
| 60 self.assertAllEqual(created_table.name, |
| 61 retrieved_table.name, |
| 62 constructed_table.name) |
| 63 |
| 64 self.assertAllEqual(created_table.schema, |
| 65 retrieved_table.schema, |
| 66 constructed_table.schema) |
| 67 |
| 68 # However for create_time, status, read/write units, |
| 69 # only the created/retrieved table will have equal |
| 70 # values. |
| 71 self.assertEqual(created_table.create_time, |
| 72 retrieved_table.create_time) |
| 73 self.assertEqual(created_table.status, |
| 74 retrieved_table.status) |
| 75 self.assertEqual(created_table.read_units, |
| 76 retrieved_table.read_units) |
| 77 self.assertEqual(created_table.write_units, |
| 78 retrieved_table.write_units) |
| 79 |
| 80 # The constructed table will have values of None. |
| 81 self.assertIsNone(constructed_table.create_time) |
| 82 self.assertIsNone(constructed_table.status) |
| 83 self.assertIsNone(constructed_table.read_units) |
| 84 self.assertIsNone(constructed_table.write_units) |
OLD | NEW |