|
15 | 15 |
|
16 | 16 | from moto import mock_aws, settings |
17 | 17 | from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID |
| 18 | +from moto.core.utils import camelcase_to_underscores |
18 | 19 | from moto.sqs.models import ( |
19 | 20 | MAXIMUM_MESSAGE_LENGTH, |
20 | 21 | MAXIMUM_MESSAGE_SIZE_ATTR_LOWER_BOUND, |
21 | 22 | MAXIMUM_MESSAGE_SIZE_ATTR_UPPER_BOUND, |
22 | 23 | Queue, |
| 24 | + sqs_backends, |
23 | 25 | ) |
24 | 26 | from moto.utilities.distutils_version import LooseVersion |
25 | 27 | from tests import aws_verified |
@@ -320,6 +322,64 @@ def test_is_empty_redrive_policy_returns_false_for_valid_policy_format(): |
320 | 322 | assert not Queue._is_empty_redrive_policy(json.dumps({"maxReceiveCount": 5})) |
321 | 323 |
|
322 | 324 |
|
| 325 | +@mock_aws |
| 326 | +@pytest.mark.parametrize( |
| 327 | + "attribute_name,attribute_value", |
| 328 | + [ |
| 329 | + ("DelaySeconds", "5"), |
| 330 | + ("KmsDataKeyReusePeriodSeconds", "300"), |
| 331 | + ("MaximumMessageSize", "262144"), |
| 332 | + ("MessageRetentionPeriod", "345600"), |
| 333 | + ("ReceiveMessageWaitTimeSeconds", "10"), |
| 334 | + ("VisibilityTimeout", "30"), |
| 335 | + ], |
| 336 | +) |
| 337 | +def test_set_attributes_integer_fields_conversion(attribute_name, attribute_value): |
| 338 | + """Test that integer fields are properly converted from strings to integers.""" |
| 339 | + if settings.TEST_SERVER_MODE: |
| 340 | + raise SkipTest("Cannot access backend directly in server mode") |
| 341 | + |
| 342 | + client = boto3.client("sqs", region_name=REGION) |
| 343 | + queue_name = str(uuid4())[0:6] |
| 344 | + |
| 345 | + # KMS attributes require KmsMasterKeyId to be set |
| 346 | + attributes = {attribute_name: attribute_value} |
| 347 | + if attribute_name == "KmsDataKeyReusePeriodSeconds": |
| 348 | + attributes["KmsMasterKeyId"] = "alias/MyKey" |
| 349 | + |
| 350 | + q_resp = client.create_queue(QueueName=queue_name, Attributes=attributes) |
| 351 | + queue_url = q_resp["QueueUrl"] |
| 352 | + |
| 353 | + attrs = client.get_queue_attributes( |
| 354 | + QueueUrl=queue_url, AttributeNames=[attribute_name] |
| 355 | + ) |
| 356 | + assert attrs["Attributes"][attribute_name] == attribute_value |
| 357 | + |
| 358 | + # Verify internal value is stored as integer |
| 359 | + backend = sqs_backends[ACCOUNT_ID][REGION] |
| 360 | + queue = backend.get_queue(queue_name) |
| 361 | + internal_attr_name = camelcase_to_underscores(attribute_name) |
| 362 | + internal_value = getattr(queue, internal_attr_name) |
| 363 | + assert isinstance(internal_value, int) |
| 364 | + assert internal_value == int(attribute_value) |
| 365 | + |
| 366 | + # Update attribute |
| 367 | + new_value = str(int(attribute_value) + 1) |
| 368 | + client.set_queue_attributes( |
| 369 | + QueueUrl=queue_url, Attributes={attribute_name: new_value} |
| 370 | + ) |
| 371 | + |
| 372 | + attrs = client.get_queue_attributes( |
| 373 | + QueueUrl=queue_url, AttributeNames=[attribute_name] |
| 374 | + ) |
| 375 | + assert attrs["Attributes"][attribute_name] == new_value |
| 376 | + |
| 377 | + # Verify updated value is still integer internally |
| 378 | + internal_value = getattr(queue, internal_attr_name) |
| 379 | + assert isinstance(internal_value, int) |
| 380 | + assert internal_value == int(new_value) |
| 381 | + |
| 382 | + |
323 | 383 | @mock_aws |
324 | 384 | def test_set_queue_attribute_empty_redrive_removes_attr(): |
325 | 385 | client = boto3.client("sqs", region_name=REGION) |
|
0 commit comments