From cc1dee03f504581cb95621c56f66dc07624071d1 Mon Sep 17 00:00:00 2001 From: Ian Auld Date: Wed, 16 Mar 2016 21:32:54 -0700 Subject: [PATCH] Reorganized tests --- .../test_dynamodb_table_with_range_key.py | 344 +++++++++--------- 1 file changed, 171 insertions(+), 173 deletions(-) diff --git a/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py b/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py index 73ee30791..d61785033 100644 --- a/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py +++ b/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py @@ -60,176 +60,6 @@ def iterate_results(res): pass -@requires_boto_gte("2.9") -@mock_dynamodb2 -def test_query_filter_eq(): - table = create_table_with_local_indexes() - item_data = [ - { - 'forum_name': 'Cool Forum', - 'subject': 'Check this out!', - 'version': '1', - 'threads': 1, - }, - { - 'forum_name': 'Awesome Forum', - 'subject': 'Read this now!', - 'version': '1', - 'threads': 5, - }, - { - 'forum_name': 'Not So Awesome Forum', - 'subject': 'Please read this... please', - 'version': '1', - 'threads': 0, - } - ] - for data in item_data: - item = Item(table, data) - item.save(overwrite=True) - - results = table.query( - forum_name__eq='Cool Forum', index='threads_index', threads__eq=5 - ) - list(results).should.have.length_of(1) - - -@requires_boto_gte("2.9") -@mock_dynamodb2 -def test_query_filter_lt(): - table = create_table_with_local_indexes() - item_data = [ - { - 'forum_name': 'Cool Forum', - 'subject': 'Check this out!', - 'version': '1', - 'threads': 1, - }, - { - 'forum_name': 'Awesome Forum', - 'subject': 'Read this now!', - 'version': '1', - 'threads': 5, - }, - { - 'forum_name': 'Not So Awesome Forum', - 'subject': 'Please read this... please', - 'version': '1', - 'threads': 0, - } - ] - for data in item_data: - item = Item(table, data) - item.save(overwrite=True) - - results = table.query( - forum_name__eq='Cool Forum', index='threads_index', threads__lt=5 - ) - list(results).should.have.length_of(2) - - -@requires_boto_gte("2.9") -@mock_dynamodb2 -def test_query_filter_gt(): - table = create_table_with_local_indexes() - item_data = [ - { - 'forum_name': 'Cool Forum', - 'subject': 'Check this out!', - 'version': '1', - 'threads': 1, - }, - { - 'forum_name': 'Awesome Forum', - 'subject': 'Read this now!', - 'version': '1', - 'threads': 5, - }, - { - 'forum_name': 'Not So Awesome Forum', - 'subject': 'Please read this... please', - 'version': '1', - 'threads': 0, - } - ] - for data in item_data: - item = Item(table, data) - item.save(overwrite=True) - - results = table.query( - forum_name__eq='Cool Forum', index='threads_index', threads__gt=1 - ) - list(results).should.have.length_of(1) - - -@requires_boto_gte("2.9") -@mock_dynamodb2 -def test_query_filter_lte(): - table = create_table_with_local_indexes() - item_data = [ - { - 'forum_name': 'Cool Forum', - 'subject': 'Check this out!', - 'version': '1', - 'threads': 1, - }, - { - 'forum_name': 'Awesome Forum', - 'subject': 'Read this now!', - 'version': '1', - 'threads': 5, - }, - { - 'forum_name': 'Not So Awesome Forum', - 'subject': 'Please read this... please', - 'version': '1', - 'threads': 0, - } - ] - for data in item_data: - item = Item(table, data) - item.save(overwrite=True) - - results = table.query( - forum_name__eq='Cool Forum', index='threads_index', threads__lte=5 - ) - list(results).should.have.length_of(3) - - -@requires_boto_gte("2.9") -@mock_dynamodb2 -def test_query_filter_gte(): - table = create_table_with_local_indexes() - item_data = [ - { - 'forum_name': 'Cool Forum', - 'subject': 'Check this out!', - 'version': '1', - 'threads': 1, - }, - { - 'forum_name': 'Awesome Forum', - 'subject': 'Read this now!', - 'version': '1', - 'threads': 5, - }, - { - 'forum_name': 'Not So Awesome Forum', - 'subject': 'Please read this... please', - 'version': '1', - 'threads': 0, - } - ] - for data in item_data: - item = Item(table, data) - item.save(overwrite=True) - - results = table.query( - forum_name__eq='Cool Forum', index='threads_index', threads__gte=1 - ) - list(results).should.have.length_of(2) - - @requires_boto_gte("2.9") @mock_dynamodb2 @freeze_time("2012-01-14") @@ -810,7 +640,6 @@ def test_query_with_global_indexes(): @mock_dynamodb2 def test_query_with_local_indexes(): - # testing table = create_table_with_local_indexes() item_data = { 'forum_name': 'Cool Forum', @@ -824,11 +653,180 @@ def test_query_with_local_indexes(): item['version'] = '2' item.save(overwrite=True) - # Revisit this query once support for QueryFilter is added - results = table.query(forum_name__eq='Cool Forum', index='threads_index') + results = table.query(forum_name__eq='Cool Forum', index='threads_index', threads__eq=1) list(results).should.have.length_of(1) +@requires_boto_gte("2.9") +@mock_dynamodb2 +def test_query_filter_eq(): + table = create_table_with_local_indexes() + item_data = [ + { + 'forum_name': 'Cool Forum', + 'subject': 'Check this out!', + 'version': '1', + 'threads': 1, + }, + { + 'forum_name': 'Cool Forum', + 'subject': 'Read this now!', + 'version': '1', + 'threads': 5, + }, + { + 'forum_name': 'Cool Forum', + 'subject': 'Please read this... please', + 'version': '1', + 'threads': 0, + } + ] + for data in item_data: + item = Item(table, data) + item.save(overwrite=True) + results = table.query_2( + forum_name__eq='Cool Forum', index='threads_index', threads__eq=5 + ) + list(results).should.have.length_of(1) + + +@requires_boto_gte("2.9") +@mock_dynamodb2 +def test_query_filter_lt(): + table = create_table_with_local_indexes() + item_data = [ + { + 'forum_name': 'Cool Forum', + 'subject': 'Check this out!', + 'version': '1', + 'threads': 1, + }, + { + 'forum_name': 'Cool Forum', + 'subject': 'Read this now!', + 'version': '1', + 'threads': 5, + }, + { + 'forum_name': 'Cool Forum', + 'subject': 'Please read this... please', + 'version': '1', + 'threads': 0, + } + ] + for data in item_data: + item = Item(table, data) + item.save(overwrite=True) + + results = table.query( + forum_name__eq='Cool Forum', index='threads_index', threads__lt=5 + ) + results = list(results) + results.should.have.length_of(2) + + +@requires_boto_gte("2.9") +@mock_dynamodb2 +def test_query_filter_gt(): + table = create_table_with_local_indexes() + item_data = [ + { + 'forum_name': 'Cool Forum', + 'subject': 'Check this out!', + 'version': '1', + 'threads': 1, + }, + { + 'forum_name': 'Cool Forum', + 'subject': 'Read this now!', + 'version': '1', + 'threads': 5, + }, + { + 'forum_name': 'Cool Forum', + 'subject': 'Please read this... please', + 'version': '1', + 'threads': 0, + } + ] + for data in item_data: + item = Item(table, data) + item.save(overwrite=True) + + results = table.query( + forum_name__eq='Cool Forum', index='threads_index', threads__gt=1 + ) + list(results).should.have.length_of(1) + + +@requires_boto_gte("2.9") +@mock_dynamodb2 +def test_query_filter_lte(): + table = create_table_with_local_indexes() + item_data = [ + { + 'forum_name': 'Cool Forum', + 'subject': 'Check this out!', + 'version': '1', + 'threads': 1, + }, + { + 'forum_name': 'Cool Forum', + 'subject': 'Read this now!', + 'version': '1', + 'threads': 5, + }, + { + 'forum_name': 'Cool Forum', + 'subject': 'Please read this... please', + 'version': '1', + 'threads': 0, + } + ] + for data in item_data: + item = Item(table, data) + item.save(overwrite=True) + + results = table.query( + forum_name__eq='Cool Forum', index='threads_index', threads__lte=5 + ) + list(results).should.have.length_of(3) + + +@requires_boto_gte("2.9") +@mock_dynamodb2 +def test_query_filter_gte(): + table = create_table_with_local_indexes() + item_data = [ + { + 'forum_name': 'Cool Forum', + 'subject': 'Check this out!', + 'version': '1', + 'threads': 1, + }, + { + 'forum_name': 'Cool Forum', + 'subject': 'Read this now!', + 'version': '1', + 'threads': 5, + }, + { + 'forum_name': 'Cool Forum', + 'subject': 'Please read this... please', + 'version': '1', + 'threads': 0, + } + ] + for data in item_data: + item = Item(table, data) + item.save(overwrite=True) + + results = table.query( + forum_name__eq='Cool Forum', index='threads_index', threads__gte=1 + ) + list(results).should.have.length_of(2) + + @mock_dynamodb2 def test_reverse_query(): conn = boto.dynamodb2.layer1.DynamoDBConnection()