mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-23 00:24:09 +00:00
Added test files and completed(?) scripts
This commit is contained in:
parent
f4703e692c
commit
241e2844ee
|
@ -19,7 +19,7 @@
|
|||
# WARNING! SHITTY CODE AHEAD. ENTER ONLY IF YOU ARE SURE YOU CAN TAKE IT
|
||||
# You have been warned
|
||||
|
||||
import time, logging.config, requests, datetime, math, os.path, schedule, sys, re, importlib, argparse
|
||||
import time, logging.config, requests, datetime, math, os.path, schedule, sys, re, importlib
|
||||
|
||||
import src.misc
|
||||
import src.configloader
|
||||
|
|
5
test/mockserver/data/response_diff20748742075224.json
Normal file
5
test/mockserver/data/response_diff20748742075224.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"compare": {
|
||||
"*": "<tr>\n <td colspan=\"2\" class=\"diff-lineno\">Line 8:</td>\n <td colspan=\"2\" class=\"diff-lineno\">Line 8:</td>\n</tr>\n<tr>\n <td class=\"diff-marker\"> </td>\n <td class=\"diff-context\"><div>| grasscolor = {{color|#8EB971}}{{only|java|short=y}}<br>{{Check the code}}{{only|bedrock|short=y}}</div></td>\n <td class=\"diff-marker\"> </td>\n <td class=\"diff-context\"><div>| grasscolor = {{color|#8EB971}}{{only|java|short=y}}<br>{{Check the code}}{{only|bedrock|short=y}}</div></td>\n</tr>\n<tr>\n <td class=\"diff-marker\"> </td>\n <td class=\"diff-context\"><div>| foliagecolor = {{color|#71A74D}}{{only|java|short=y}}<br>{{Check the code}}{{only|bedrock|short=y}}</div></td>\n <td class=\"diff-marker\"> </td>\n <td class=\"diff-context\"><div>| foliagecolor = {{color|#71A74D}}{{only|java|short=y}}<br>{{Check the code}}{{only|bedrock|short=y}}</div></td>\n</tr>\n<tr>\n <td colspan=\"2\" class=\"diff-empty\"> </td>\n <td class=\"diff-marker\">+</td>\n <td class=\"diff-addedline\"><div>| waterc</div></td>\n</tr>\n<tr>\n <td class=\"diff-marker\">−</td>\n <td class=\"diff-deletedline\"><div>| watercolor = {{color|#3F76E4}}{{only|java|short=y}}<br>{{Check the code}}{{only|bedrock|short=y}}</div></td>\n <td colspan=\"2\" class=\"diff-empty\"> </td>\n</tr>\n<tr>\n <td class=\"diff-marker\">−</td>\n <td class=\"diff-deletedline\"><div><del class=\"diffchange diffchange-inline\">| structures ={{EnvLink|Dungeon</del>}}<del class=\"diffchange diffchange-inline\">s</del><br>{{<del class=\"diffchange diffchange-inline\">EnvLink</del>|<del class=\"diffchange diffchange-inline\">Mineshaft</del>}}<del class=\"diffchange diffchange-inline\">s</del><br>{{<del class=\"diffchange diffchange-inline\">EnvLink</del>|<del class=\"diffchange diffchange-inline\">Stronghold</del>}}<del class=\"diffchange diffchange-inline\">s</del><br>{{<del class=\"diffchange diffchange-inline\">EnvLink</del>|<del class=\"diffchange diffchange-inline\">Amethyst</del> <del class=\"diffchange diffchange-inline\">Geode</del>}}<del class=\"diffchange diffchange-inline\">s</del></div></td>\n <td class=\"diff-marker\">+</td>\n <td class=\"diff-addedline\"><div><ins class=\"diffchange diffchange-inline\">Dripleaf</ins>}}<br>{{<ins class=\"diffchange diffchange-inline\">BlockLink</ins>|<ins class=\"diffchange diffchange-inline\">Cave Vines</ins>}}<br>{{<ins class=\"diffchange diffchange-inline\">BlockLink</ins>|<ins class=\"diffchange diffchange-inline\">Spore Blossom</ins>}}<br>{{<ins class=\"diffchange diffchange-inline\">ItemLink</ins>|<ins class=\"diffchange diffchange-inline\">Glow</ins> <ins class=\"diffchange diffchange-inline\">Berries}}</ins>}}</div></td>\n</tr>\n<tr>\n <td class=\"diff-marker\">−</td>\n <td class=\"diff-deletedline\"><div>| blocks = {{BlockLink|Oak Log}}<br>{{BlockLink|Azalea Leaves}}<br>{{BlockLink|Flowering Azalea Leaves}}<br>{{BlockLink|Azalea}}<br>{{BlockLink|Flowering Azalea}}<br>{{BlockLink|Rooted Dirt}}<br>{{BlockLink|Hanging Roots}}<br>{{BlockLink|Moss Block}}<br>{{BlockLink|Moss Carpet}}<br>{{BlockLink|Grass}}<br>{{BlockLink|Tall Grass}}<br>{{BlockLink|Vines}}<br>{{BlockLink|Water}}<br>{{BlockLink|Clay}}<br>{{BlockLink|Small Dripleaf}}<br>{{BlockLink|Big Dripleaf}}<br>{{BlockLink|Cave Vines}}<br>{{BlockLink|Spore Blossom}}<br>{{ItemLink|Glow Berries}}}}</div></td>\n <td colspan=\"2\" class=\"diff-empty\"> </td>\n</tr>\n<tr>\n <td class=\"diff-marker\"> </td>\n <td class=\"diff-context\"></td>\n <td class=\"diff-marker\"> </td>\n <td class=\"diff-context\"></td>\n</tr>\n<tr>\n <td class=\"diff-marker\"> </td>\n <td class=\"diff-context\"><div>A '''lush cave''' is a temperate [[Overworld]] [[cave]] [[biome]] that has a unique fauna and flora and is found underground below [[azalea tree]]s.</div></td>\n <td class=\"diff-marker\"> </td>\n <td class=\"diff-context\"><div>A '''lush cave''' is a temperate [[Overworld]] [[cave]] [[biome]] that has a unique fauna and flora and is found underground below [[azalea tree]]s.</div></td>\n</tr>\n\n<!-- diff cache key prod:minecraft_gamepedia:diff:wikidiff2:1.12:old-2075454:rev-2076789:1.11.0:0 -->\n"
|
||||
}
|
||||
}
|
5
test/mockserver/data/response_diff20752242075225.json
Normal file
5
test/mockserver/data/response_diff20752242075225.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"compare": {
|
||||
"*": "<tr>\n <td colspan=\"2\" class=\"diff-lineno\">Line 8:</td>\n <td colspan=\"2\" class=\"diff-lineno\">Line 8:</td>\n</tr>\n<tr>\n <td class=\"diff-marker\"> </td>\n <td class=\"diff-context\"><div>| grasscolor = {{color|#8EB971}}{{only|java|short=y}}<br>{{Check the code}}{{only|bedrock|short=y}}</div></td>\n <td class=\"diff-marker\"> </td>\n <td class=\"diff-context\"><div>| grasscolor = {{color|#8EB971}}{{only|java|short=y}}<br>{{Check the code}}{{only|bedrock|short=y}}</div></td>\n</tr>\n<tr>\n <td class=\"diff-marker\"> </td>\n <td class=\"diff-context\"><div>| foliagecolor = {{color|#71A74D}}{{only|java|short=y}}<br>{{Check the code}}{{only|bedrock|short=y}}</div></td>\n <td class=\"diff-marker\"> </td>\n <td class=\"diff-context\"><div>| foliagecolor = {{color|#71A74D}}{{only|java|short=y}}<br>{{Check the code}}{{only|bedrock|short=y}}</div></td>\n</tr>\n<tr>\n <td colspan=\"2\" class=\"diff-empty\"> </td>\n <td class=\"diff-marker\">+</td>\n <td class=\"diff-addedline\"><div>| watercolor = {{color|#3F76E4}}{{only|java|short=y}}<br>{{Check the code}}{{only|bedrock|short=y}}</div></td>\n</tr>\n<tr>\n <td class=\"diff-marker\">−</td>\n <td class=\"diff-deletedline\"><div>| waterc</div></td>\n <td colspan=\"2\" class=\"diff-empty\"> </td>\n</tr>\n<tr>\n <td class=\"diff-marker\">−</td>\n <td class=\"diff-deletedline\"><div><del class=\"diffchange diffchange-inline\">Dripleaf</del>}}<br>{{<del class=\"diffchange diffchange-inline\">BlockLink</del>|<del class=\"diffchange diffchange-inline\">Cave Vines</del>}}<br>{{<del class=\"diffchange diffchange-inline\">BlockLink</del>|<del class=\"diffchange diffchange-inline\">Spore Blossom</del>}}<br>{{<del class=\"diffchange diffchange-inline\">ItemLink</del>|<del class=\"diffchange diffchange-inline\">Glow</del> <del class=\"diffchange diffchange-inline\">Berries}}</del>}}</div></td>\n <td class=\"diff-marker\">+</td>\n <td class=\"diff-addedline\"><div><ins class=\"diffchange diffchange-inline\">| structures ={{EnvLink|Dungeon</ins>}}<ins class=\"diffchange diffchange-inline\">s</ins><br>{{<ins class=\"diffchange diffchange-inline\">EnvLink</ins>|<ins class=\"diffchange diffchange-inline\">Mineshaft</ins>}}<ins class=\"diffchange diffchange-inline\">s</ins><br>{{<ins class=\"diffchange diffchange-inline\">EnvLink</ins>|<ins class=\"diffchange diffchange-inline\">Stronghold</ins>}}<ins class=\"diffchange diffchange-inline\">s</ins><br>{{<ins class=\"diffchange diffchange-inline\">EnvLink</ins>|<ins class=\"diffchange diffchange-inline\">Amethyst</ins> <ins class=\"diffchange diffchange-inline\">Geode</ins>}}<ins class=\"diffchange diffchange-inline\">s</ins></div></td>\n</tr>\n<tr>\n <td colspan=\"2\" class=\"diff-empty\"> </td>\n <td class=\"diff-marker\">+</td>\n <td class=\"diff-addedline\"><div>| blocks = {{BlockLink|Oak Log}}<br>{{BlockLink|Azalea Leaves}}<br>{{BlockLink|Flowering Azalea Leaves}}<br>{{BlockLink|Azalea}}<br>{{BlockLink|Flowering Azalea}}<br>{{BlockLink|Rooted Dirt}}<br>{{BlockLink|Hanging Roots}}<br>{{BlockLink|Moss Block}}<br>{{BlockLink|Moss Carpet}}<br>{{BlockLink|Grass}}<br>{{BlockLink|Tall Grass}}<br>{{BlockLink|Vines}}<br>{{BlockLink|Water}}<br>{{BlockLink|Clay}}<br>{{BlockLink|Small Dripleaf}}<br>{{BlockLink|Big Dripleaf}}<br>{{BlockLink|Cave Vines}}<br>{{BlockLink|Spore Blossom}}<br>{{ItemLink|Glow Berries}}}}</div></td>\n</tr>\n<tr>\n <td class=\"diff-marker\"> </td>\n <td class=\"diff-context\"></td>\n <td class=\"diff-marker\"> </td>\n <td class=\"diff-context\"></td>\n</tr>\n<tr>\n <td class=\"diff-marker\"> </td>\n <td class=\"diff-context\"><div>A '''lush cave''' is a temperate [[Overworld]] [[cave]] [[biome]] that has a unique fauna and flora and is found underground below [[azalea tree]]s.</div></td>\n <td class=\"diff-marker\"> </td>\n <td class=\"diff-context\"><div>A '''lush cave''' is a temperate [[Overworld]] [[cave]] [[biome]] that has a unique fauna and flora and is found underground below [[azalea tree]]s.</div></td>\n</tr>\n\n<!-- diff cache key prod:minecraft_gamepedia:diff:wikidiff2:1.12:old-2076789:rev-2076791:1.11.0:0 -->\n"
|
||||
}
|
||||
}
|
5
test/mockserver/data/response_diff20752302075231.json
Normal file
5
test/mockserver/data/response_diff20752302075231.json
Normal file
File diff suppressed because one or more lines are too long
5
test/mockserver/data/response_diff2325552075232.json
Normal file
5
test/mockserver/data/response_diff2325552075232.json
Normal file
File diff suppressed because one or more lines are too long
5
test/mockserver/data/response_diff2325562075234.json
Normal file
5
test/mockserver/data/response_diff2325562075234.json
Normal file
File diff suppressed because one or more lines are too long
|
@ -139,10 +139,10 @@
|
|||
"rcid": 2793424,
|
||||
"user": "Good User",
|
||||
"anon": "",
|
||||
"oldlen": 811,
|
||||
"newlen": 771,
|
||||
"oldlen": 771,
|
||||
"newlen": 811,
|
||||
"timestamp": "2021-12-26T12:13:38Z",
|
||||
"parsedcomment": "Unfo revision by 192.168.1.1. Reason: Mad cats",
|
||||
"parsedcomment": "Undo revision by 192.168.1.1. Reason: Mad cats",
|
||||
"tags": [
|
||||
"visualeditor"
|
||||
]
|
||||
|
@ -157,8 +157,8 @@
|
|||
"rcid": 2793423,
|
||||
"user": "192.168.1.1",
|
||||
"anon": "",
|
||||
"oldlen": 771,
|
||||
"newlen": 811,
|
||||
"oldlen": 811,
|
||||
"newlen": 771,
|
||||
"timestamp": "2021-12-26T12:09:18Z",
|
||||
"parsedcomment": "Hahahahhaha, you will never understand my genius!",
|
||||
"tags": [
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -12,7 +12,6 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with RcGcDw. If not, see <http://www.gnu.org/licenses/>.
|
||||
import pprint
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
import json
|
||||
import urllib.parse
|
||||
|
@ -20,9 +19,11 @@ import requests
|
|||
|
||||
response_jsons: dict[str, dict] = {}
|
||||
|
||||
class EndOfContent(Exception):
|
||||
pass
|
||||
|
||||
def load_response(name: str):
|
||||
with open("data/{}.json".format(name), "r") as response_file:
|
||||
with open("data/response_{}.json".format(name), "r") as response_file:
|
||||
response_json: dict = json.loads(response_file.read())
|
||||
response_jsons[name] = response_json
|
||||
|
||||
|
@ -31,16 +32,16 @@ def get_response(name: str):
|
|||
return response_jsons.get(name)
|
||||
|
||||
|
||||
[load_response(x) for x in ["response_recentchanges", "response_recentchanges2", "response_init", "response_error", "response_siteinfo"
|
||||
"response_image", "response_userinfo"]]
|
||||
[load_response(x) for x in ["recentchanges", "recentchanges2", "init", "error", "siteinfo", "image", "userinfo"]]
|
||||
|
||||
|
||||
messages_collector = []
|
||||
|
||||
askedfor = False
|
||||
|
||||
# Return server response based on some output from Minecraft Wiki
|
||||
class MockServerRequestHandler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
global askedfor
|
||||
# We assume testing will be for API endpoint only since RcGcDw doesn't do requests to other URLs so no need to check main path
|
||||
# For simplicity, return a dictionary of query arguments, we assume duplicate keys will not appear
|
||||
query = {k: y for (k, y) in urllib.parse.parse_qsl(self.path.split("?")[1])}
|
||||
|
@ -48,51 +49,61 @@ class MockServerRequestHandler(BaseHTTPRequestHandler):
|
|||
# Regular pooled query for recentchanges
|
||||
if query.get("list") == "recentchanges":
|
||||
self.send_essentials_ok()
|
||||
if len(messages_collector) == 0:
|
||||
if askedfor is False:
|
||||
# Limit amount of events accordingly to required amount just in case
|
||||
response_jsons["response_recentchanges"]["query"]["recentchanges"] = get_response("response_recentchanges")["query"]["recentchanges"][0:int(query.get("rclimit", 20))]
|
||||
response_content = json.dumps(get_response("response_recentchanges"))
|
||||
response_jsons["recentchanges"]["query"]["recentchanges"] = get_response("recentchanges")["query"]["recentchanges"][0:int(query.get("rclimit", 20))]
|
||||
response_content = json.dumps(get_response("recentchanges"))
|
||||
askedfor = True
|
||||
else:
|
||||
response_jsons["response_recentchanges2"]["query"]["recentchanges"] = get_response("response_recentchanges2")["query"]["recentchanges"][0:int(query.get("rclimit", 20))]
|
||||
response_content = json.dumps(get_response("response_recentchanges2"))
|
||||
response_jsons["recentchanges2"]["query"]["recentchanges"] = get_response("recentchanges2")["query"]["recentchanges"][0:int(query.get("rclimit", 20))]
|
||||
response_content = json.dumps(get_response("recentchanges2"))
|
||||
self.wfile.write(response_content.encode('utf-8'))
|
||||
# Init info
|
||||
elif query.get("list") == "tags" and query.get("meta") == "allmessages|siteinfo":
|
||||
self.send_essentials_ok()
|
||||
response_content = json.dumps(get_response("response_init"))
|
||||
response_content = json.dumps(get_response("init"))
|
||||
self.wfile.write(response_content.encode('utf-8'))
|
||||
elif query.get("meta") == "siteinfo":
|
||||
self.send_essentials_ok()
|
||||
response_content = json.dumps(get_response("response_siteinfo"))
|
||||
response_content = json.dumps(get_response("siteinfo"))
|
||||
self.wfile.write(response_content.encode('utf-8'))
|
||||
elif query.get("prop") == "imageinfo|revisions":
|
||||
self.send_essentials_ok()
|
||||
response_content = json.dumps(get_response("response_image"))
|
||||
response_content = json.dumps(get_response("image"))
|
||||
self.wfile.write(response_content.encode('utf-8'))
|
||||
elif query.get("list") == "usercontribs":
|
||||
self.send_essentials_ok()
|
||||
response_content = json.dumps(get_response("response_userinfo"))
|
||||
response_content = json.dumps(get_response("userinfo"))
|
||||
self.wfile.write(response_content.encode('utf-8'))
|
||||
else:
|
||||
self.send_response(400)
|
||||
self.send_header('Content-Type', 'application/json; charset=utf-8')
|
||||
self.end_headers()
|
||||
response_content = json.dumps(get_response("response_error"))
|
||||
response_content = json.dumps(get_response("error"))
|
||||
self.wfile.write(response_content.encode('utf-8'))
|
||||
elif query.get("action") == "compare":
|
||||
self.send_essentials_ok()
|
||||
name = "diff{}{}".format(query.get("fromrev"), query.get("torev"))
|
||||
load_response(name)
|
||||
response_content = json.dumps(get_response(name))
|
||||
self.wfile.write(response_content.encode('utf-8'))
|
||||
|
||||
def do_POST(self):
|
||||
self.read_ok_collect()
|
||||
self.read_ok_collect(method="POST")
|
||||
|
||||
def do_PATCH(self):
|
||||
self.read_ok_collect()
|
||||
self.read_ok_collect(method="PATCH")
|
||||
|
||||
def do_DELETE(self):
|
||||
self.read_ok_collect()
|
||||
self.read_ok_collect(method="DELETE")
|
||||
|
||||
def read_ok_collect(self):
|
||||
def read_ok_collect(self, method: str):
|
||||
content_length = int(self.headers['Content-Length'])
|
||||
patch_data = self.rfile.read(content_length)
|
||||
messages_collector.append(patch_data.decode('utf-8'))
|
||||
if patch_data:
|
||||
messages_collector.append(json.loads(patch_data.decode('utf-8')))
|
||||
else:
|
||||
messages_collector.append(method + self.path)
|
||||
self.send_essentials_ok()
|
||||
self.wfile.write(json.dumps({"id": len(messages_collector)}).encode('utf-8'))
|
||||
|
||||
|
@ -102,12 +113,22 @@ class MockServerRequestHandler(BaseHTTPRequestHandler):
|
|||
self.end_headers()
|
||||
|
||||
|
||||
def start_mock_server(port):
|
||||
def start_mock_server(port, config):
|
||||
mock_server = HTTPServer(('localhost', port), MockServerRequestHandler)
|
||||
try:
|
||||
print("Server started successfully at http://localhost:{}".format(port))
|
||||
mock_server.serve_forever()
|
||||
while 1:
|
||||
if len(messages_collector) < 13:
|
||||
mock_server.handle_request()
|
||||
else:
|
||||
raise EndOfContent
|
||||
except KeyboardInterrupt:
|
||||
print("Shutting down...")
|
||||
print(pprint.pprint(messages_collector))
|
||||
pass
|
||||
except EndOfContent:
|
||||
with open("results/results{}.json".format(config.config), "r") as proper_results:
|
||||
if proper_results.read() == json.dumps(messages_collector):
|
||||
print("Results are correct!")
|
||||
else:
|
||||
print("Results are incorrect, saving failed results to resultsfailed{}.json".format(config.config))
|
||||
with open("results/resultsfailed{}.json".format(config.config), "w") as file_to_write:
|
||||
file_to_write.write(json.dumps(messages_collector))
|
||||
|
|
|
@ -42,13 +42,14 @@ if not command_args.no_client:
|
|||
shutil.move(old_config, backup_filename)
|
||||
shutil.copy(new_settings, old_config)
|
||||
# revert data file to some low number
|
||||
with open(pathlib.Path(__file__).parent.resolve().parent.resolve().parent.resolve().joinpath("data.json"), "r+") as data_file:
|
||||
with open(pathlib.Path(__file__).parent.resolve().parent.resolve().parent.resolve().joinpath("data.json"), "r") as data_file:
|
||||
data_file_data = json.loads(data_file.read())
|
||||
data_file_data["rcid"] = 5
|
||||
with open(pathlib.Path(__file__).parent.resolve().parent.resolve().parent.resolve().joinpath("data.json"), "w") as data_file:
|
||||
data_file.write(json.dumps(data_file_data, indent=4))
|
||||
|
||||
# Start mock server
|
||||
server.start_mock_server(8080)
|
||||
server.start_mock_server(8080, command_args)
|
||||
|
||||
# Revert file changes
|
||||
if not command_args.no_client:
|
||||
|
|
Loading…
Reference in a new issue