Skip to content

Commit

Permalink
SQS: Support JSON format (#6331)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers committed May 24, 2023
1 parent a28dd1a commit 42b03d3
Show file tree
Hide file tree
Showing 6 changed files with 455 additions and 122 deletions.
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

0 comments on commit 42b03d3

Please sign in to comment.