Port test suite from nose to pytest.
This just eliminates all errors on the tests collection. Elimination of failures is left to the next commit.
This commit is contained in:
parent
47dbad291e
commit
77dc60ea97
146 changed files with 1172 additions and 1277 deletions
1
tests/test_dynamodb2/__init__.py
Normal file
1
tests/test_dynamodb2/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
# This file is intentionally left blank.
|
||||
|
|
@ -17,7 +17,7 @@ from tests.helpers import requires_boto_gte
|
|||
import moto.dynamodb2.comparisons
|
||||
import moto.dynamodb2.models
|
||||
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
try:
|
||||
import boto.dynamodb2
|
||||
|
|
@ -72,7 +72,7 @@ def test_describe_missing_table():
|
|||
conn = boto.dynamodb2.connect_to_region(
|
||||
"us-west-2", aws_access_key_id="ak", aws_secret_access_key="sk"
|
||||
)
|
||||
with assert_raises(JSONResponseError):
|
||||
with pytest.raises(JSONResponseError):
|
||||
conn.describe_table("messages")
|
||||
|
||||
|
||||
|
|
@ -201,7 +201,7 @@ def test_item_add_empty_string_exception():
|
|||
ProvisionedThroughput={"ReadCapacityUnits": 5, "WriteCapacityUnits": 5},
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
conn.put_item(
|
||||
TableName=name,
|
||||
Item={
|
||||
|
|
@ -248,7 +248,7 @@ def test_update_item_with_empty_string_exception():
|
|||
},
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
conn.update_item(
|
||||
TableName=name,
|
||||
Key={"forum_name": {"S": "LOLCat Forum"}},
|
||||
|
|
@ -1354,7 +1354,7 @@ def test_put_empty_item():
|
|||
)
|
||||
table = dynamodb.Table("test")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
table.put_item(Item={})
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
"One or more parameter values were invalid: Missing the key structure_id in the item"
|
||||
|
|
@ -1373,7 +1373,7 @@ def test_put_item_nonexisting_hash_key():
|
|||
)
|
||||
table = dynamodb.Table("test")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
table.put_item(Item={"a_terribly_misguided_id_attribute": "abcdef"})
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
"One or more parameter values were invalid: Missing the key structure_id in the item"
|
||||
|
|
@ -1398,7 +1398,7 @@ def test_put_item_nonexisting_range_key():
|
|||
)
|
||||
table = dynamodb.Table("test")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
table.put_item(Item={"structure_id": "abcdef"})
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
"One or more parameter values were invalid: Missing the key added_at in the item"
|
||||
|
|
@ -1980,7 +1980,7 @@ def test_delete_item():
|
|||
assert response["Count"] == 2
|
||||
|
||||
# Test ReturnValues validation
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
table.delete_item(
|
||||
Key={"client": "client1", "app": "app1"}, ReturnValues="ALL_NEW"
|
||||
)
|
||||
|
|
@ -2085,7 +2085,7 @@ def test_describe_continuous_backups_errors():
|
|||
client = boto3.client("dynamodb", region_name="us-east-1")
|
||||
|
||||
# when
|
||||
with assert_raises(Exception) as e:
|
||||
with pytest.raises(Exception) as e:
|
||||
client.describe_continuous_backups(TableName="not-existing-table")
|
||||
|
||||
# then
|
||||
|
|
@ -2171,7 +2171,7 @@ def test_update_continuous_backups_errors():
|
|||
client = boto3.client("dynamodb", region_name="us-east-1")
|
||||
|
||||
# when
|
||||
with assert_raises(Exception) as e:
|
||||
with pytest.raises(Exception) as e:
|
||||
client.update_continuous_backups(
|
||||
TableName="not-existing-table",
|
||||
PointInTimeRecoverySpecification={"PointInTimeRecoveryEnabled": True},
|
||||
|
|
@ -2291,7 +2291,7 @@ def test_update_item_on_map():
|
|||
ExpressionAttributeValues={":tb": "new_value"},
|
||||
)
|
||||
# Running this against AWS DDB gives an exception so make sure it also fails.:
|
||||
with assert_raises(client.exceptions.ClientError):
|
||||
with pytest.raises(client.exceptions.ClientError):
|
||||
# botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the UpdateItem
|
||||
# operation: The document path provided in the update expression is invalid for update
|
||||
table.update_item(
|
||||
|
|
@ -2321,7 +2321,7 @@ def test_update_item_on_map():
|
|||
)
|
||||
|
||||
# Test nested value for a nonexistent attribute throws a ClientError.
|
||||
with assert_raises(client.exceptions.ClientError):
|
||||
with pytest.raises(client.exceptions.ClientError):
|
||||
table.update_item(
|
||||
Key={"forum_name": "the-key", "subject": "123"},
|
||||
UpdateExpression="SET nonexistent.#nested = :tb",
|
||||
|
|
@ -2409,7 +2409,7 @@ def test_update_return_attributes():
|
|||
r = update("col1", "val5", "NONE")
|
||||
assert r["Attributes"] == {}
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
r = update("col1", "val6", "WRONG")
|
||||
|
||||
|
||||
|
|
@ -2438,7 +2438,7 @@ def test_put_return_attributes():
|
|||
)
|
||||
assert r["Attributes"] == {"id": {"S": "foo"}, "col1": {"S": "val1"}}
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.put_item(
|
||||
TableName="moto-test",
|
||||
Item={"id": {"S": "foo"}, "col1": {"S": "val3"}},
|
||||
|
|
@ -2675,7 +2675,7 @@ def test_condition_expressions():
|
|||
},
|
||||
)
|
||||
|
||||
with assert_raises(client.exceptions.ConditionalCheckFailedException):
|
||||
with pytest.raises(client.exceptions.ConditionalCheckFailedException):
|
||||
client.put_item(
|
||||
TableName="test1",
|
||||
Item={
|
||||
|
|
@ -2691,7 +2691,7 @@ def test_condition_expressions():
|
|||
},
|
||||
)
|
||||
|
||||
with assert_raises(client.exceptions.ConditionalCheckFailedException):
|
||||
with pytest.raises(client.exceptions.ConditionalCheckFailedException):
|
||||
client.put_item(
|
||||
TableName="test1",
|
||||
Item={
|
||||
|
|
@ -2707,7 +2707,7 @@ def test_condition_expressions():
|
|||
},
|
||||
)
|
||||
|
||||
with assert_raises(client.exceptions.ConditionalCheckFailedException):
|
||||
with pytest.raises(client.exceptions.ConditionalCheckFailedException):
|
||||
client.put_item(
|
||||
TableName="test1",
|
||||
Item={
|
||||
|
|
@ -2735,7 +2735,7 @@ def test_condition_expressions():
|
|||
ExpressionAttributeValues={":match": {"S": "match"}},
|
||||
)
|
||||
|
||||
with assert_raises(client.exceptions.ConditionalCheckFailedException):
|
||||
with pytest.raises(client.exceptions.ConditionalCheckFailedException):
|
||||
client.update_item(
|
||||
TableName="test1",
|
||||
Key={"client": {"S": "client1"}, "app": {"S": "app1"}},
|
||||
|
|
@ -2745,7 +2745,7 @@ def test_condition_expressions():
|
|||
ExpressionAttributeNames={"#existing": "existing", "#match": "match"},
|
||||
)
|
||||
|
||||
with assert_raises(client.exceptions.ConditionalCheckFailedException):
|
||||
with pytest.raises(client.exceptions.ConditionalCheckFailedException):
|
||||
client.delete_item(
|
||||
TableName="test1",
|
||||
Key={"client": {"S": "client1"}, "app": {"S": "app1"}},
|
||||
|
|
@ -2830,7 +2830,7 @@ def test_condition_expression__attr_doesnt_exist():
|
|||
update_if_attr_doesnt_exist()
|
||||
|
||||
# Second time should fail
|
||||
with assert_raises(client.exceptions.ConditionalCheckFailedException):
|
||||
with pytest.raises(client.exceptions.ConditionalCheckFailedException):
|
||||
update_if_attr_doesnt_exist()
|
||||
|
||||
|
||||
|
|
@ -2870,7 +2870,7 @@ def test_condition_expression__and_order():
|
|||
|
||||
# ensure that the RHS of the AND expression is not evaluated if the LHS
|
||||
# returns true (as it would result an error)
|
||||
with assert_raises(client.exceptions.ConditionalCheckFailedException):
|
||||
with pytest.raises(client.exceptions.ConditionalCheckFailedException):
|
||||
client.update_item(
|
||||
TableName="test",
|
||||
Key={"forum_name": {"S": "the-key"}},
|
||||
|
|
@ -2966,7 +2966,7 @@ def test_scan_by_non_exists_index():
|
|||
],
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.scan(TableName="test", IndexName="non_exists_index")
|
||||
|
||||
ex.exception.response["Error"]["Code"].should.equal("ValidationException")
|
||||
|
|
@ -3001,7 +3001,7 @@ def test_query_by_non_exists_index():
|
|||
],
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.query(
|
||||
TableName="test",
|
||||
IndexName="non_exists_index",
|
||||
|
|
@ -3041,7 +3041,7 @@ def test_batch_items_returns_all():
|
|||
@mock_dynamodb2
|
||||
def test_batch_items_throws_exception_when_requesting_100_items_for_single_table():
|
||||
dynamodb = _create_user_table()
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.batch_get_item(
|
||||
RequestItems={
|
||||
"users": {
|
||||
|
|
@ -3063,7 +3063,7 @@ def test_batch_items_throws_exception_when_requesting_100_items_for_single_table
|
|||
@mock_dynamodb2
|
||||
def test_batch_items_throws_exception_when_requesting_100_items_across_all_tables():
|
||||
dynamodb = _create_user_table()
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.batch_get_item(
|
||||
RequestItems={
|
||||
"users": {
|
||||
|
|
@ -3160,7 +3160,7 @@ def test_batch_items_with_basic_projection_expression_and_attr_expression_names(
|
|||
@mock_dynamodb2
|
||||
def test_batch_items_should_throw_exception_for_duplicate_request():
|
||||
client = _create_user_table()
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.batch_get_item(
|
||||
RequestItems={
|
||||
"users": {
|
||||
|
|
@ -3186,7 +3186,7 @@ def test_index_with_unknown_attributes_should_fail():
|
|||
"Some index key attributes are not defined in AttributeDefinitions."
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.create_table(
|
||||
AttributeDefinitions=[
|
||||
{"AttributeName": "customer_nr", "AttributeType": "S"},
|
||||
|
|
@ -3366,7 +3366,7 @@ def test_update_list_index__set_index_of_a_string():
|
|||
client.put_item(
|
||||
TableName=table_name, Item={"id": {"S": "foo2"}, "itemstr": {"S": "somestring"}}
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.update_item(
|
||||
TableName=table_name,
|
||||
Key={"id": {"S": "foo2"}},
|
||||
|
|
@ -3615,7 +3615,7 @@ def test_item_size_is_under_400KB():
|
|||
|
||||
|
||||
def assert_failure_due_to_item_size(func, **kwargs):
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
func(**kwargs)
|
||||
ex.exception.response["Error"]["Code"].should.equal("ValidationException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
|
|
@ -3624,7 +3624,7 @@ def assert_failure_due_to_item_size(func, **kwargs):
|
|||
|
||||
|
||||
def assert_failure_due_to_item_size_to_update(func, **kwargs):
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
func(**kwargs)
|
||||
ex.exception.response["Error"]["Code"].should.equal("ValidationException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
|
|
@ -3654,7 +3654,7 @@ def test_hash_key_cannot_use_begins_with_operations():
|
|||
batch.put_item(Item=item)
|
||||
|
||||
table = dynamodb.Table("test-table")
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
table.query(KeyConditionExpression=Key("key").begins_with("prefix-"))
|
||||
ex.exception.response["Error"]["Code"].should.equal("ValidationException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
|
|
@ -4047,7 +4047,7 @@ def test_update_catches_invalid_list_append_operation():
|
|||
)
|
||||
|
||||
# Update item using invalid list_append expression
|
||||
with assert_raises(ParamValidationError) as ex:
|
||||
with pytest.raises(ParamValidationError) as ex:
|
||||
client.update_item(
|
||||
TableName="TestTable",
|
||||
Key={"SHA256": {"S": "sha-of-file"}},
|
||||
|
|
@ -4166,7 +4166,7 @@ def test_query_catches_when_no_filters():
|
|||
)
|
||||
table = dynamo.Table("origin-rbu-dev")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
table.query(TableName="original-rbu-dev")
|
||||
|
||||
ex.exception.response["Error"]["Code"].should.equal("ValidationException")
|
||||
|
|
@ -4197,7 +4197,7 @@ def test_invalid_transact_get_items():
|
|||
|
||||
client = boto3.client("dynamodb", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.transact_get_items(
|
||||
TransactItems=[
|
||||
{"Get": {"Key": {"id": {"S": "1"}}, "TableName": "test1"}}
|
||||
|
|
@ -4211,7 +4211,7 @@ def test_invalid_transact_get_items():
|
|||
re.I,
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.transact_get_items(
|
||||
TransactItems=[
|
||||
{"Get": {"Key": {"id": {"S": "1"},}, "TableName": "test1"}},
|
||||
|
|
@ -4491,7 +4491,7 @@ def test_transact_write_items_put_conditional_expressions():
|
|||
TableName="test-table", Item={"id": {"S": "foo2"},},
|
||||
)
|
||||
# Put multiple items
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.transact_write_items(
|
||||
TransactItems=[
|
||||
{
|
||||
|
|
@ -4581,7 +4581,7 @@ def test_transact_write_items_conditioncheck_fails():
|
|||
)
|
||||
# Try to put an email address, but verify whether it exists
|
||||
# ConditionCheck should fail
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.transact_write_items(
|
||||
TransactItems=[
|
||||
{
|
||||
|
|
@ -4687,7 +4687,7 @@ def test_transact_write_items_delete_with_failed_condition_expression():
|
|||
)
|
||||
# Try to delete an item that does not have an email address
|
||||
# ConditionCheck should fail
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.transact_write_items(
|
||||
TransactItems=[
|
||||
{
|
||||
|
|
@ -4758,7 +4758,7 @@ def test_transact_write_items_update_with_failed_condition_expression():
|
|||
)
|
||||
# Try to update an item that does not have an email address
|
||||
# ConditionCheck should fail
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.transact_write_items(
|
||||
TransactItems=[
|
||||
{
|
||||
|
|
@ -5318,7 +5318,7 @@ def test_transact_write_items_fails_with_transaction_canceled_exception():
|
|||
# Insert one item
|
||||
dynamodb.put_item(TableName="test-table", Item={"id": {"S": "foo"}})
|
||||
# Update two items, the one that exists and another that doesn't
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.transact_write_items(
|
||||
TransactItems=[
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from boto3.dynamodb.conditions import Key
|
|||
from botocore.exceptions import ClientError
|
||||
import sure # noqa
|
||||
from freezegun import freeze_time
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
from moto import mock_dynamodb2, mock_dynamodb2_deprecated
|
||||
from boto.exception import JSONResponseError
|
||||
|
|
@ -1353,7 +1353,7 @@ def test_update_item_with_expression():
|
|||
|
||||
|
||||
def assert_failure_due_to_key_not_in_schema(func, **kwargs):
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
func(**kwargs)
|
||||
ex.exception.response["Error"]["Code"].should.equal("ValidationException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue