Skip to content

Commit

Permalink
ListAllTables!
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquev6 committed Apr 16, 2015
1 parent d0f8e50 commit e11d109
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions LowVoltage/__init__.py
Expand Up @@ -7,3 +7,4 @@
from actions import *
from exceptions import *
from attribute_types import *
from iterators import *
5 changes: 5 additions & 0 deletions LowVoltage/iterators/__init__.py
@@ -0,0 +1,5 @@
# coding: utf8

# Copyright 2014-2015 Vincent Jacques <vincent@vincent-jacques.net>

from .list_all_tables import ListAllTables
72 changes: 72 additions & 0 deletions LowVoltage/iterators/list_all_tables.py
@@ -0,0 +1,72 @@
# coding: utf8

# Copyright 2014-2015 Vincent Jacques <vincent@vincent-jacques.net>

import unittest

import LowVoltage as _lv
import LowVoltage.testing as _tst


class ListAllTables(object):
"""Make as many ListTables as needed to iterate over all tables"""
# Don't implement anything else than forward iteration. (Remember PyGithub's PaginatedList; it was too difficult to maintain for niche use-cases)
# Clients can use raw ListTables actions to implement their specific needs.

def __init__(self, connection):
self.__connection = connection
self.__current_iter = [].__iter__()
self.__next_start_table = None
self.__done = False

def __iter__(self):
return self

def next(self):
try:
return self.__current_iter.next()
except StopIteration:
if self.__done:
raise
else:
r = self.__connection.request(_lv.ListTables().exclusive_start_table_name(self.__next_start_table))
self.__next_start_table = r.last_evaluated_table_name
self.__done = self.__next_start_table is None
self.__current_iter = r.table_names.__iter__()
return self.__current_iter.next()


class ListAllTablesLocalIntegTests(_tst.dynamodb_local.TestCase):
def __test(self, tables_count):
table_names = ["Tab{:03}".format(i) for i in range(tables_count)]

for t in table_names:
self.connection.request(
_lv.CreateTable(t).hash_key("h", _lv.STRING).provisioned_throughput(1, 1)
)

self.assertEqual(
list(_lv.ListAllTables(self.connection)),
table_names
)

for t in table_names:
self.connection.request(_lv.DeleteTable(t))

def test_list_0_tables(self):
self.__test(0)

def test_list_99_tables(self):
self.__test(99)

def test_list_100_tables(self):
self.__test(100)

def test_list_101_tables(self):
self.__test(101)

def test_list_102_tables(self):
self.__test(102)

def test_list_250_tables(self):
self.__test(250)
3 changes: 3 additions & 0 deletions LowVoltage/iterators/tests/__init__.py
@@ -0,0 +1,3 @@
# coding: utf8

# Copyright 2014-2015 Vincent Jacques <vincent@vincent-jacques.net>
3 changes: 3 additions & 0 deletions LowVoltage/iterators/tests/integ/__init__.py
@@ -0,0 +1,3 @@
# coding: utf8

# Copyright 2014-2015 Vincent Jacques <vincent@vincent-jacques.net>
5 changes: 5 additions & 0 deletions LowVoltage/iterators/tests/integ/local.py
@@ -0,0 +1,5 @@
# coding: utf8

# Copyright 2014-2015 Vincent Jacques <vincent@vincent-jacques.net>

from ...list_all_tables import ListAllTablesLocalIntegTests
3 changes: 3 additions & 0 deletions LowVoltage/iterators/tests/unit.py
@@ -0,0 +1,3 @@
# coding: utf8

# Copyright 2014-2015 Vincent Jacques <vincent@vincent-jacques.net>
1 change: 1 addition & 0 deletions LowVoltage/tests/integ/local.py
Expand Up @@ -7,6 +7,7 @@
import LowVoltage.testing.dynamodb_local
from LowVoltage.actions.tests.integ.local import *
from LowVoltage.connection.tests.integ.local import *
from LowVoltage.iterators.tests.integ.local import *


if __name__ == "__main__": # pragma no branch (Test code)
Expand Down
1 change: 1 addition & 0 deletions LowVoltage/tests/unit.py
Expand Up @@ -8,6 +8,7 @@
from LowVoltage.testing.tests.unit import *
from LowVoltage.policies.tests.unit import *
from LowVoltage.connection.tests.unit import *
from LowVoltage.iterators.tests.unit import *


if __name__ == "__main__": # pragma no branch (Test code)
Expand Down

0 comments on commit e11d109

Please sign in to comment.