-
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.
test: start adding some tests along with workflow 👷 ✅
- Loading branch information
Showing
5 changed files
with
92 additions
and
3 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,18 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.9 | ||
- run: pip install tox | ||
- run: tox -e py |
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,14 @@ | ||
from typing import Any | ||
|
||
import attr | ||
|
||
|
||
@attr.s(auto_attribs=True) | ||
class MockModuleApi: | ||
"""Mock of a synapse.module_api.ModuleApi, only implementing the methods the | ||
WhiteList module will use. | ||
""" | ||
|
||
def register_spam_checker_callbacks(self, *args: Any, **kwargs: Any) -> None: | ||
"""Don't fail when the module tries to register its callbacks.""" | ||
pass |
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,52 @@ | ||
import aiounittest | ||
|
||
from tests import MockModuleApi | ||
from white_list_module import EimisWhiteList | ||
|
||
|
||
class EimisWhiteListTestClass(aiounittest.AsyncTestCase): | ||
def setUp(self): | ||
self.config = EimisWhiteList.parse_config( | ||
{ | ||
"idp_id": "idp_id", | ||
"room_id": "room_id", | ||
} | ||
) | ||
self.module = EimisWhiteList(self.config, MockModuleApi()) | ||
|
||
def test_get_last_content_no_content(self): | ||
|
||
result = self.module.get_last_content({}) | ||
|
||
self.assertEqual(result, "") | ||
|
||
def test_get_last_content_message(self): | ||
real_life_content = { | ||
"msgtype": "m.text", | ||
"body": "## test experiment\nyvonnière", | ||
"format": "org.matrix.custom.html", | ||
"formatted_body": "<h2>test experiment</h2>\n<p>yvonnière</p>\n", | ||
"m.mentions": {}, | ||
} | ||
result = self.module.get_last_content(real_life_content) | ||
|
||
self.assertEqual(result, "## test experiment\nyvonnière") | ||
|
||
def test_get_last_content_modified_message(self): | ||
real_life_content = { | ||
"msgtype": "m.text", | ||
"body": " * patapouf\npignolin\nroger\ntartanfion", | ||
"m.new_content": { | ||
"msgtype": "m.text", | ||
"body": "patapouf\npignolin\nroger\ntartanfion", | ||
"m.mentions": {}, | ||
}, | ||
"m.mentions": {}, | ||
"m.relates_to": { | ||
"rel_type": "m.replace", | ||
"event_id": "$ChWXbbIpW-NUPca17PXdsTSxVAXAKGZeKEae3mcTjdI", | ||
}, | ||
} | ||
result = self.module.get_last_content(real_life_content) | ||
|
||
self.assertEqual(result, "patapouf\npignolin\nroger\ntartanfion") |
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