Added new tests (speedy)

This commit is contained in:
Frisk 2022-01-13 17:17:33 +01:00
parent f06b782d9d
commit f2b468d6e1
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
9 changed files with 339 additions and 10 deletions

View file

@ -1,5 +1,5 @@
{
"edit": {
"edit": {
"type": "edit",
"ns": 0,
"title": "Some page",
@ -13,5 +13,81 @@
"timestamp": "2022-03-26T11:41:22Z",
"parsedcomment": "Work on new as",
"tags": ["VisualEdit"]
},
"abuselog": {
"id": 4690092,
"filter": "Prevent vandalism",
"filter_id": "3",
"user": "User4",
"ns": 0,
"title": "Survival",
"action": "edit",
"result": "tag",
"revid": "398328478",
"timestamp": "2022-01-13T06:20:58Z"
},
"cargo/createtable": {
"type": "log",
"ns": 0,
"title": "",
"pageid": 0,
"revid": 0,
"old_revid": 0,
"rcid": 13325,
"user": "User 10",
"oldlen": 0,
"newlen": 0,
"timestamp": "2022-01-13T15:25:09Z",
"parsedcomment": "",
"logid": 1865,
"logtype": "cargo",
"logaction": "createtable",
"logparams": {
"0": "<a href=\"https://somewiki.somefarm.com/wiki/Special:CargoTables/TableTest\">TableTest</a>"
},
"tags": []
},
"datadump/generate": {
"type": "log",
"ns": 0,
"title": "Datadump",
"pageid": 0,
"revid": 0,
"old_revid": 0,
"rcid": 13325,
"user": "User 10",
"timestamp": "2022-01-13T15:25:09Z",
"parsedcomment": "",
"logid": 18,
"logtype": "datadump",
"logaction": "generate",
"logparams": {
"filename": "Somefilenoidea.tar.gz"
},
"tags": []
},
"interwiki/iw_add": {
"type": "log",
"ns": -1,
"title": "Special:Interwiki",
"pageid": 0,
"revid": 0,
"old_revid": 0,
"rcid": 13326,
"user": "Not An User",
"oldlen": 0,
"newlen": 0,
"timestamp": "2022-01-13T15:31:25Z",
"parsedcomment": "Just a test",
"logid": 1866,
"logtype": "interwiki",
"logaction": "iw_add",
"logparams": {
"0": "testonlypleaseignore",
"1": "https://notawiki.notaplatform.com/wiki/$1",
"2": "0",
"3": "0"
},
"tags": []
}
}

View file

@ -1,3 +1,7 @@
{
"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"}]}
"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"}]},
"datadump/generate": {"allowed_mentions": {"parse": []}, "avatar_url": "", "embeds": [{"color": null, "author": {"name": "User 10", "url": "https://minecraft.fandom.com/wiki/User:User_10", "icon_url": ""}, "timestamp": "2022-01-13T15:25:09Z", "description": "", "title": "Generated Somefilenoidea.tar.gz dump", "url": "https://minecraft.fandom.com/wiki/Datadump"}]},
"cargo/createtable":{"allowed_mentions": {"parse": []}, "avatar_url": "", "embeds": [{"color": null, "author": {"name": "User 10", "url": "https://minecraft.fandom.com/wiki/User:User_10", "icon_url": ""}, "timestamp": "2022-01-13T15:25:09Z", "description": "", "url": "https://somewiki.somefarm.com/wiki/Special:CargoTables/TableTest", "title": "Utworzono tabel\u0119 Cargo \u201eTableTest\u201d"}]},
"abuselog": {"allowed_mentions": {"parse": []}, "avatar_url": "", "embeds": [{"color": null, "title": "User4 wywo\u0142a\u0142(a) \"Prevent vandalism\"", "fields": [{"name": "Wykonano", "value": "Edycja", "inline": false}, {"name": "Podj\u0119te dzia\u0142ania", "value": "Otagowano edycj\u0119", "inline": false}, {"name": "Tytu\u0142", "value": "Survival", "inline": false}]}]},
"interwiki/iw_add": {"allowed_mentions": {"parse": []}, "avatar_url": "", "embeds": [{"color": null, "author": {"name": "Not An User", "url": "https://minecraft.fandom.com/wiki/User:Not_An_User", "icon_url": ""}, "timestamp": "2022-01-13T15:31:25Z", "url": "https://minecraft.fandom.com/wiki/Special:Interwiki", "title": "Dodano wpis do tabeli interwiki", "description": "Prefix: testonlypleaseignore, strona: https://notawiki.notaplatform.com/wiki/$1 | "}]}
}

59
test/test_abusefilter.py Normal file
View file

@ -0,0 +1,59 @@
# 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.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 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_abusefilter_embed(self):
test = default_message("abuselog", formatter_hooks)
ctx = PropertyMock()
ctx.message_type = "embed"
ctx.event_type = "abuselog"
ctx.event = "abuselog"
ctx.parsedcomment = ""
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("abuselog")
result = repr(test(ctx, edit_c))
print(result)
self.assertEqual(results, result)

66
test/test_cargo.py Normal file
View file

@ -0,0 +1,66 @@
# 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.util import default_message
from src.api.hooks import formatter_hooks
from src.misc import WIKI_SCRIPT_PATH, LinkParser
from test.test_utilities import inject_settings
from unittest.mock import 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))
def parse_links(summary: str):
link_parser = LinkParser()
link_parser.feed(summary)
return link_parser.new_string
class TestMWFormatter(unittest.TestCase):
def test_cargo_embed(self):
test = default_message("cargo/createtable", formatter_hooks)
ctx = PropertyMock()
ctx.message_type = "embed"
ctx.event_type = "cargo/createtable"
ctx.event = "cargo/createtable"
ctx.client.parse_links = parse_links
ctx.parsedcomment = ""
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("cargo/createtable")
result = repr(test(ctx, edit_c))
print(result)
self.assertEqual(results, result)

59
test/test_datadump.py Normal file
View file

@ -0,0 +1,59 @@
# 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.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 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_datadump_embed(self):
test = default_message("datadump/generate", formatter_hooks)
ctx = PropertyMock()
ctx.message_type = "embed"
ctx.event_type = "datadump/generate"
ctx.event = "datadump/generate"
ctx.parsedcomment = ""
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("datadump/generate")
result = repr(test(ctx, edit_c))
print(result)
self.assertEqual(results, result)

View file

@ -23,6 +23,12 @@ from src.api.hooks import formatter_hooks, pre_hooks, post_hooks
class ApiTesting(unittest.TestCase):
def setUp(self) -> None:
self.temp = formatter_hooks.copy()
def tearDown(self) -> None:
formatter_hooks.update(self.temp)
def test_embed_formatter_registration(self):
formatter_hooks.clear()

59
test/test_interwiki.py Normal file
View file

@ -0,0 +1,59 @@
# 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.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 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_interwiki_embed(self):
test = default_message("interwiki/iw_add", formatter_hooks)
ctx = PropertyMock()
ctx.message_type = "embed"
ctx.event_type = "interwiki/iw_add"
ctx.event = "interwiki/iw_add"
ctx.parsedcomment = ""
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("interwiki/iw_add")
result = repr(test(ctx, edit_c))
print(result)
self.assertEqual(results, result)

View file

@ -17,12 +17,11 @@ 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
from unittest.mock import PropertyMock
import unittest
@ -42,6 +41,7 @@ with open("test/data/rc_results.json", "r") as ob:
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)

View file

@ -47,12 +47,12 @@ class TestDataFile(TestCase):
def test_load_datafile(self):
self.assertEqual(datafile.load_datafile(), data_template)
def test_save_datafile(self):
datafile["discussion_id"] = 321388838283
datafile.save_datafile()
with open(datafile.data_filename, "r") as df:
contents = json.loads(df.read())
self.assertEqual(contents["discussion_id"], 321388838283)
# def test_save_datafile(self):
# datafile["discussion_id"] = 321388838283
# datafile.save_datafile()
# with open(datafile.data_filename, "r") as df:
# contents = json.loads(df.read())
# self.assertEqual(contents["discussion_id"], 321388838283)
class Test(TestCase):