Added new test

This commit is contained in:
Frisk 2022-01-12 16:45:07 +01:00
parent 4450d7e642
commit f06b782d9d
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
3 changed files with 78 additions and 0 deletions

17
test/data/rc_objects.json Normal file
View file

@ -0,0 +1,17 @@
{
"edit": {
"type": "edit",
"ns": 0,
"title": "Some page",
"pageid": 9327,
"revid": 2075232,
"old_revid": 232555,
"rcid": 2793437,
"user": "User3",
"oldlen": 32882,
"newlen": 328,
"timestamp": "2022-03-26T11:41:22Z",
"parsedcomment": "Work on new as",
"tags": ["VisualEdit"]
}
}

View file

@ -0,0 +1,3 @@
{
"edit": {"allowed_mentions": {"parse": []}, "avatar_url": "", "embeds": [{"color": 16711680, "url": "https://minecraft.fandom.com/index.php?title=Some_page&curid=9327&diff=2075232&oldid=232555", "title": "Some page (-32554)", "fields": [{"name": "Usuni\u0119to", "value": "__Tylko znaki niedrukowane__", "inline": true}, {"name": "Dodano", "value": "__Tylko znaki niedrukowane__", "inline": true}, {"name": "Tagi", "value": "VisualEdit", "inline": false}], "author": {"name": "User3", "url": "https://minecraft.fandom.com/wiki/User:User3", "icon_url": ""}, "timestamp": "2022-03-26T11:41:22Z", "description": "Work on new as"}]}
}

58
test/test_formatters.py Normal file
View file

@ -0,0 +1,58 @@
# This file is part of Recent changes Goat compatible Discord webhook (RcGcDw).
#
# RcGcDw is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RcGcDw is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with RcGcDw. If not, see <http://www.gnu.org/licenses/>.
import importlib
import json
from src.configloader import settings
from src.api.context import Context
from src.api.client import Client
from src.api.util import default_message
from src.api.hooks import formatter_hooks
from src.misc import WIKI_SCRIPT_PATH
from test.test_utilities import inject_settings
from unittest.mock import Mock, PropertyMock
import unittest
def no_formatter(ctx: Context, change: dict) -> None:
raise NameError
inject_settings("appearance.mode", "embed")
importlib.import_module(settings.get('extensions_dir', 'extensions'), 'extensions')
formatter_hooks["no_formatter"] = no_formatter
with open("test/data/rc_objects.json", "r") as ob:
jsons = json.loads(ob.read())
with open("test/data/rc_results.json", "r") as ob:
results = json.loads(ob.read())
def get_objects(name: str):
return jsons.get(name), json.dumps(results.get(name))
class TestMWFormatter(unittest.TestCase):
def test_edit_embed(self):
test = default_message("edit", formatter_hooks)
ctx = PropertyMock()
ctx.message_type = "embed"
ctx.event_type = "edit"
ctx.event = "edit"
ctx.parsedcomment = "Work on new as"
ctx.client.WIKI_SCRIPT_PATH = WIKI_SCRIPT_PATH
ctx.webhook_url = "https://example.com"
# ctx.client.return_value = Mock(spec=Client)
edit_c, results = get_objects("edit")
result = repr(test(ctx, edit_c))
self.assertEqual(results, result)