Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQS: Support JSON format #6331

Merged
merged 1 commit into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/test_sqs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Run separate test cases to verify SQS works with multiple botocore versions (/multiple response-types, QUERY and JSON)
#
name: "SQS Tests"

on:
pull_request:
types: [ labeled ]

jobs:
test:
if: ${{ github.event.label.name == 'service-sqs' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ "3.11" ]
botocore-version: ["1.29.126", "1.29.127", "1.29.128"]

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Update pip
run: |
python -m pip install --upgrade pip

- name: Install project dependencies
run: |
pip install -r requirements-dev.txt
pip install botocore==${{ matrix.botocore-version }}

- name: Run tests
run: |
pytest -sv tests/test_sqs
5 changes: 5 additions & 0 deletions moto/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def get_body(
) -> str:
return self.description # type: ignore[return-value]

def to_json(self) -> "JsonRESTError":
err = JsonRESTError(error_type=self.error_type, message=self.message)
err.code = self.code
return err


class DryRunClientError(RESTError):
code = 412
Expand Down
6 changes: 5 additions & 1 deletion moto/sqs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ def utf8(value: Any) -> bytes: # type: ignore[misc]
def body(self) -> str:
return escape(self._body).replace('"', """).replace("\r", "
")

@property
def original_body(self) -> str:
return self._body

def mark_sent(self, delay_seconds: Optional[int] = None) -> None:
self.sent_timestamp = int(unix_time_millis()) # type: ignore
if delay_seconds:
Expand Down Expand Up @@ -1030,7 +1034,7 @@ def delete_message_batch(
errors.append(
{
"Id": receipt_and_id["msg_user_id"],
"SenderFault": "true",
"SenderFault": True,
"Code": "ReceiptHandleIsInvalid",
"Message": f'The input receipt handle "{receipt_and_id["receipt_handle"]}" is not a valid receipt handle.',
}
Expand Down
Loading