-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ryan Lerch <[email protected]>
- Loading branch information
Showing
10 changed files
with
1,761 additions
and
224 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# SPDX-FileCopyrightText: 2024 Contributors to the Fedora Project | ||
# | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
||
"""Unit tests for the message schema.""" | ||
|
||
import pytest | ||
from jsonschema import ValidationError | ||
|
||
from tahrir_messages import BadgeAwardV1, PersonLoginFirstV1, PersonRankAdvanceV1 | ||
|
||
from .utils import DUMMY_BADGE, DUMMY_PERSON, DUMMY_USER | ||
|
||
|
||
def test_person_login_first(): | ||
body = { | ||
"user": DUMMY_USER, | ||
} | ||
message = PersonLoginFirstV1(body=body) | ||
message.validate() | ||
|
||
expected_summary = "dudemcpants logged into badges for the first time" | ||
assert message.summary == expected_summary | ||
assert str(message) == expected_summary | ||
assert message.agent_name == "dudemcpants" | ||
assert message.usernames == ["dudemcpants"] | ||
assert message.app_name == "tahrir" | ||
assert message.url is None | ||
assert message.app_icon == "https://apps.fedoraproject.org/img/icons/badges.png" | ||
|
||
|
||
def test_person_login_first_missing_fields(): | ||
message = PersonLoginFirstV1(body={}) | ||
with pytest.raises(ValidationError): | ||
message.validate() | ||
|
||
|
||
def test_badge_award(): | ||
body = {"user": DUMMY_USER, "badge": DUMMY_BADGE} | ||
message = BadgeAwardV1(body=body) | ||
message.validate() | ||
|
||
expected_summary = "dudemcpants was awarded the badge `White Hat`" | ||
assert message.summary == expected_summary | ||
assert str(message) == expected_summary | ||
assert message.agent_name == "dudemcpants" | ||
assert message.usernames == ["dudemcpants"] | ||
assert message.app_name == "tahrir" | ||
assert message.url is None | ||
assert message.app_icon == "https://apps.fedoraproject.org/img/icons/badges.png" | ||
|
||
|
||
def test_badge_award_missing_fields(): | ||
message = BadgeAwardV1(body={}) | ||
with pytest.raises(ValidationError): | ||
message.validate() | ||
|
||
body = {"badge": DUMMY_BADGE} | ||
message = BadgeAwardV1(body=body) | ||
with pytest.raises(ValidationError): | ||
message.validate() | ||
|
||
body = {"user": DUMMY_BADGE} | ||
message = BadgeAwardV1(body=body) | ||
with pytest.raises(ValidationError): | ||
message.validate() | ||
|
||
|
||
def test_person_rank_advance(): | ||
body = {"old_rank": 2, "person": DUMMY_PERSON} | ||
message = PersonRankAdvanceV1(body=body) | ||
message.validate() | ||
|
||
expected_summary = "aaronhale's Badges rank changed from 2 to 1" | ||
assert message.summary == expected_summary | ||
assert str(message) == expected_summary | ||
assert message.agent_name == "aaronhale" | ||
assert message.usernames == ["aaronhale"] | ||
assert message.app_name == "tahrir" | ||
assert message.url is None | ||
assert message.app_icon == "https://apps.fedoraproject.org/img/icons/badges.png" | ||
|
||
|
||
def test_person_rank_advance_missing_fields(): | ||
"""Assert an exception is actually raised on validation failure.""" | ||
message = BadgeAwardV1(body={}) | ||
with pytest.raises(ValidationError): | ||
message.validate() |
Oops, something went wrong.