-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge pull request #1 from capcom6/hotfix/backward-compatible-parsing
[domain] backward compatibility parsing
Showing
6 changed files
with
149 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Python CI | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-20.04 | ||
strategy: | ||
matrix: | ||
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
cache: pipenv | ||
|
||
- name: Install pipenv | ||
run: | | ||
python -m pip install --upgrade pipenv | ||
- name: Install dependencies | ||
run: | | ||
pipenv install --dev | ||
- name: Lint with flake8 | ||
run: pipenv run flake8 android_sms_gateway tests | ||
|
||
- name: Test with pytest | ||
run: pipenv run pytest tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import pytest | ||
|
||
from android_sms_gateway.domain import MessageState, RecipientState | ||
|
||
|
||
# Test for successful instantiation from a dictionary | ||
def test_message_state_from_dict(): | ||
payload = { | ||
"id": "123", | ||
"state": "Pending", | ||
"recipients": [ | ||
{"phoneNumber": "123", "state": "Pending"}, | ||
{"phoneNumber": "456", "state": "Pending"}, | ||
], | ||
"isHashed": True, | ||
"isEncrypted": False, | ||
} | ||
|
||
message_state = MessageState.from_dict(payload) | ||
assert message_state.id == payload["id"] | ||
assert message_state.state.name == payload["state"] | ||
assert all( | ||
isinstance(recipient, RecipientState) for recipient in message_state.recipients | ||
) | ||
assert len(message_state.recipients) == len(payload["recipients"]) | ||
assert message_state.is_hashed == payload["isHashed"] | ||
assert message_state.is_encrypted == payload["isEncrypted"] | ||
|
||
|
||
# Test for backward compatibility | ||
def test_message_state_from_dict_backwards_compatibility(): | ||
payload = { | ||
"id": "123", | ||
"state": "Pending", | ||
"recipients": [ | ||
{"phoneNumber": "123", "state": "Pending"}, | ||
{"phoneNumber": "456", "state": "Pending"}, | ||
], | ||
} | ||
|
||
message_state = MessageState.from_dict(payload) | ||
assert message_state.id == payload["id"] | ||
assert message_state.state.name == payload["state"] | ||
assert all( | ||
isinstance(recipient, RecipientState) for recipient in message_state.recipients | ||
) | ||
assert len(message_state.recipients) == len(payload["recipients"]) | ||
assert message_state.is_hashed is False | ||
assert message_state.is_encrypted is False | ||
|
||
|
||
# Test for handling missing fields | ||
def test_message_state_from_dict_missing_fields(): | ||
incomplete_payload = { | ||
"id": "123", | ||
# 'state' is missing | ||
"recipients": [ | ||
{"phoneNumber": "123", "state": "Pending"} | ||
], # Assume one recipient is enough to test | ||
"isHashed": True, | ||
"isEncrypted": False, | ||
} | ||
|
||
with pytest.raises(KeyError): | ||
MessageState.from_dict(incomplete_payload) | ||
|
||
|
||
# Test for handling incorrect types | ||
def test_message_state_from_dict_incorrect_types(): | ||
incorrect_payload = { | ||
"id": 123, # Should be a string | ||
"state": 42, # Should be a string that can be converted to a ProcessState | ||
"recipients": "Alice, Bob", # Should be a list of dictionaries | ||
"isHashed": "yes", # Should be a boolean | ||
"isEncrypted": "no", # Should be a boolean | ||
} | ||
|
||
with pytest.raises( | ||
Exception | ||
): # Replace Exception with the specific exception you expect | ||
MessageState.from_dict(incorrect_payload) |