Added test files and completed(?) scripts

This commit is contained in:
Frisk 2021-12-30 15:46:18 +01:00
parent f4703e692c
commit 241e2844ee
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
10 changed files with 80 additions and 32 deletions

View file

@ -19,7 +19,7 @@
# WARNING! SHITTY CODE AHEAD. ENTER ONLY IF YOU ARE SURE YOU CAN TAKE IT # WARNING! SHITTY CODE AHEAD. ENTER ONLY IF YOU ARE SURE YOU CAN TAKE IT
# You have been warned # 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.misc
import src.configloader import src.configloader

View 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\">&#160;</td>\n <td class=\"diff-context\"><div>| grasscolor = {{color|#8EB971}}{{only|java|short=y}}&lt;br&gt;{{Check the code}}{{only|bedrock|short=y}}</div></td>\n <td class=\"diff-marker\">&#160;</td>\n <td class=\"diff-context\"><div>| grasscolor = {{color|#8EB971}}{{only|java|short=y}}&lt;br&gt;{{Check the code}}{{only|bedrock|short=y}}</div></td>\n</tr>\n<tr>\n <td class=\"diff-marker\">&#160;</td>\n <td class=\"diff-context\"><div>| foliagecolor = {{color|#71A74D}}{{only|java|short=y}}&lt;br&gt;{{Check the code}}{{only|bedrock|short=y}}</div></td>\n <td class=\"diff-marker\">&#160;</td>\n <td class=\"diff-context\"><div>| foliagecolor = {{color|#71A74D}}{{only|java|short=y}}&lt;br&gt;{{Check the code}}{{only|bedrock|short=y}}</div></td>\n</tr>\n<tr>\n <td colspan=\"2\" class=\"diff-empty\">&#160;</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}}&lt;br&gt;{{Check the code}}{{only|bedrock|short=y}}</div></td>\n <td colspan=\"2\" class=\"diff-empty\">&#160;</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>&lt;br&gt;{{<del class=\"diffchange diffchange-inline\">EnvLink</del>|<del class=\"diffchange diffchange-inline\">Mineshaft</del>}}<del class=\"diffchange diffchange-inline\">s</del>&lt;br&gt;{{<del class=\"diffchange diffchange-inline\">EnvLink</del>|<del class=\"diffchange diffchange-inline\">Stronghold</del>}}<del class=\"diffchange diffchange-inline\">s</del>&lt;br&gt;{{<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>}}&lt;br&gt;{{<ins class=\"diffchange diffchange-inline\">BlockLink</ins>|<ins class=\"diffchange diffchange-inline\">Cave Vines</ins>}}&lt;br&gt;{{<ins class=\"diffchange diffchange-inline\">BlockLink</ins>|<ins class=\"diffchange diffchange-inline\">Spore Blossom</ins>}}&lt;br&gt;{{<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}}&lt;br&gt;{{BlockLink|Azalea Leaves}}&lt;br&gt;{{BlockLink|Flowering Azalea Leaves}}&lt;br&gt;{{BlockLink|Azalea}}&lt;br&gt;{{BlockLink|Flowering Azalea}}&lt;br&gt;{{BlockLink|Rooted Dirt}}&lt;br&gt;{{BlockLink|Hanging Roots}}&lt;br&gt;{{BlockLink|Moss Block}}&lt;br&gt;{{BlockLink|Moss Carpet}}&lt;br&gt;{{BlockLink|Grass}}&lt;br&gt;{{BlockLink|Tall Grass}}&lt;br&gt;{{BlockLink|Vines}}&lt;br&gt;{{BlockLink|Water}}&lt;br&gt;{{BlockLink|Clay}}&lt;br&gt;{{BlockLink|Small Dripleaf}}&lt;br&gt;{{BlockLink|Big Dripleaf}}&lt;br&gt;{{BlockLink|Cave Vines}}&lt;br&gt;{{BlockLink|Spore Blossom}}&lt;br&gt;{{ItemLink|Glow Berries}}}}</div></td>\n <td colspan=\"2\" class=\"diff-empty\">&#160;</td>\n</tr>\n<tr>\n <td class=\"diff-marker\">&#160;</td>\n <td class=\"diff-context\"></td>\n <td class=\"diff-marker\">&#160;</td>\n <td class=\"diff-context\"></td>\n</tr>\n<tr>\n <td class=\"diff-marker\">&#160;</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\">&#160;</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"
}
}

View 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\">&#160;</td>\n <td class=\"diff-context\"><div>| grasscolor = {{color|#8EB971}}{{only|java|short=y}}&lt;br&gt;{{Check the code}}{{only|bedrock|short=y}}</div></td>\n <td class=\"diff-marker\">&#160;</td>\n <td class=\"diff-context\"><div>| grasscolor = {{color|#8EB971}}{{only|java|short=y}}&lt;br&gt;{{Check the code}}{{only|bedrock|short=y}}</div></td>\n</tr>\n<tr>\n <td class=\"diff-marker\">&#160;</td>\n <td class=\"diff-context\"><div>| foliagecolor = {{color|#71A74D}}{{only|java|short=y}}&lt;br&gt;{{Check the code}}{{only|bedrock|short=y}}</div></td>\n <td class=\"diff-marker\">&#160;</td>\n <td class=\"diff-context\"><div>| foliagecolor = {{color|#71A74D}}{{only|java|short=y}}&lt;br&gt;{{Check the code}}{{only|bedrock|short=y}}</div></td>\n</tr>\n<tr>\n <td colspan=\"2\" class=\"diff-empty\">&#160;</td>\n <td class=\"diff-marker\">+</td>\n <td class=\"diff-addedline\"><div>| watercolor = {{color|#3F76E4}}{{only|java|short=y}}&lt;br&gt;{{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\">&#160;</td>\n</tr>\n<tr>\n <td class=\"diff-marker\"></td>\n <td class=\"diff-deletedline\"><div><del class=\"diffchange diffchange-inline\">Dripleaf</del>}}&lt;br&gt;{{<del class=\"diffchange diffchange-inline\">BlockLink</del>|<del class=\"diffchange diffchange-inline\">Cave Vines</del>}}&lt;br&gt;{{<del class=\"diffchange diffchange-inline\">BlockLink</del>|<del class=\"diffchange diffchange-inline\">Spore Blossom</del>}}&lt;br&gt;{{<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>&lt;br&gt;{{<ins class=\"diffchange diffchange-inline\">EnvLink</ins>|<ins class=\"diffchange diffchange-inline\">Mineshaft</ins>}}<ins class=\"diffchange diffchange-inline\">s</ins>&lt;br&gt;{{<ins class=\"diffchange diffchange-inline\">EnvLink</ins>|<ins class=\"diffchange diffchange-inline\">Stronghold</ins>}}<ins class=\"diffchange diffchange-inline\">s</ins>&lt;br&gt;{{<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\">&#160;</td>\n <td class=\"diff-marker\">+</td>\n <td class=\"diff-addedline\"><div>| blocks = {{BlockLink|Oak Log}}&lt;br&gt;{{BlockLink|Azalea Leaves}}&lt;br&gt;{{BlockLink|Flowering Azalea Leaves}}&lt;br&gt;{{BlockLink|Azalea}}&lt;br&gt;{{BlockLink|Flowering Azalea}}&lt;br&gt;{{BlockLink|Rooted Dirt}}&lt;br&gt;{{BlockLink|Hanging Roots}}&lt;br&gt;{{BlockLink|Moss Block}}&lt;br&gt;{{BlockLink|Moss Carpet}}&lt;br&gt;{{BlockLink|Grass}}&lt;br&gt;{{BlockLink|Tall Grass}}&lt;br&gt;{{BlockLink|Vines}}&lt;br&gt;{{BlockLink|Water}}&lt;br&gt;{{BlockLink|Clay}}&lt;br&gt;{{BlockLink|Small Dripleaf}}&lt;br&gt;{{BlockLink|Big Dripleaf}}&lt;br&gt;{{BlockLink|Cave Vines}}&lt;br&gt;{{BlockLink|Spore Blossom}}&lt;br&gt;{{ItemLink|Glow Berries}}}}</div></td>\n</tr>\n<tr>\n <td class=\"diff-marker\">&#160;</td>\n <td class=\"diff-context\"></td>\n <td class=\"diff-marker\">&#160;</td>\n <td class=\"diff-context\"></td>\n</tr>\n<tr>\n <td class=\"diff-marker\">&#160;</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\">&#160;</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"
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -139,10 +139,10 @@
"rcid": 2793424, "rcid": 2793424,
"user": "Good User", "user": "Good User",
"anon": "", "anon": "",
"oldlen": 811, "oldlen": 771,
"newlen": 771, "newlen": 811,
"timestamp": "2021-12-26T12:13:38Z", "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": [ "tags": [
"visualeditor" "visualeditor"
] ]
@ -157,8 +157,8 @@
"rcid": 2793423, "rcid": 2793423,
"user": "192.168.1.1", "user": "192.168.1.1",
"anon": "", "anon": "",
"oldlen": 771, "oldlen": 811,
"newlen": 811, "newlen": 771,
"timestamp": "2021-12-26T12:09:18Z", "timestamp": "2021-12-26T12:09:18Z",
"parsedcomment": "Hahahahhaha, you will never understand my genius!", "parsedcomment": "Hahahahhaha, you will never understand my genius!",
"tags": [ "tags": [

File diff suppressed because one or more lines are too long

View file

@ -12,7 +12,6 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with RcGcDw. If not, see <http://www.gnu.org/licenses/>. # along with RcGcDw. If not, see <http://www.gnu.org/licenses/>.
import pprint
from http.server import BaseHTTPRequestHandler, HTTPServer from http.server import BaseHTTPRequestHandler, HTTPServer
import json import json
import urllib.parse import urllib.parse
@ -20,9 +19,11 @@ import requests
response_jsons: dict[str, dict] = {} response_jsons: dict[str, dict] = {}
class EndOfContent(Exception):
pass
def load_response(name: str): 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_json: dict = json.loads(response_file.read())
response_jsons[name] = response_json response_jsons[name] = response_json
@ -31,16 +32,16 @@ def get_response(name: str):
return response_jsons.get(name) return response_jsons.get(name)
[load_response(x) for x in ["response_recentchanges", "response_recentchanges2", "response_init", "response_error", "response_siteinfo" [load_response(x) for x in ["recentchanges", "recentchanges2", "init", "error", "siteinfo", "image", "userinfo"]]
"response_image", "response_userinfo"]]
messages_collector = [] messages_collector = []
askedfor = False
# Return server response based on some output from Minecraft Wiki # Return server response based on some output from Minecraft Wiki
class MockServerRequestHandler(BaseHTTPRequestHandler): class MockServerRequestHandler(BaseHTTPRequestHandler):
def do_GET(self): 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 # 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 # 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])} 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 # Regular pooled query for recentchanges
if query.get("list") == "recentchanges": if query.get("list") == "recentchanges":
self.send_essentials_ok() self.send_essentials_ok()
if len(messages_collector) == 0: if askedfor is False:
# Limit amount of events accordingly to required amount just in case # 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_jsons["recentchanges"]["query"]["recentchanges"] = get_response("recentchanges")["query"]["recentchanges"][0:int(query.get("rclimit", 20))]
response_content = json.dumps(get_response("response_recentchanges")) response_content = json.dumps(get_response("recentchanges"))
askedfor = True
else: else:
response_jsons["response_recentchanges2"]["query"]["recentchanges"] = get_response("response_recentchanges2")["query"]["recentchanges"][0:int(query.get("rclimit", 20))] response_jsons["recentchanges2"]["query"]["recentchanges"] = get_response("recentchanges2")["query"]["recentchanges"][0:int(query.get("rclimit", 20))]
response_content = json.dumps(get_response("response_recentchanges2")) response_content = json.dumps(get_response("recentchanges2"))
self.wfile.write(response_content.encode('utf-8')) self.wfile.write(response_content.encode('utf-8'))
# Init info # Init info
elif query.get("list") == "tags" and query.get("meta") == "allmessages|siteinfo": elif query.get("list") == "tags" and query.get("meta") == "allmessages|siteinfo":
self.send_essentials_ok() 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')) self.wfile.write(response_content.encode('utf-8'))
elif query.get("meta") == "siteinfo": elif query.get("meta") == "siteinfo":
self.send_essentials_ok() 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')) self.wfile.write(response_content.encode('utf-8'))
elif query.get("prop") == "imageinfo|revisions": elif query.get("prop") == "imageinfo|revisions":
self.send_essentials_ok() 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')) self.wfile.write(response_content.encode('utf-8'))
elif query.get("list") == "usercontribs": elif query.get("list") == "usercontribs":
self.send_essentials_ok() 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')) self.wfile.write(response_content.encode('utf-8'))
else: else:
self.send_response(400) self.send_response(400)
self.send_header('Content-Type', 'application/json; charset=utf-8') self.send_header('Content-Type', 'application/json; charset=utf-8')
self.end_headers() 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')) self.wfile.write(response_content.encode('utf-8'))
def do_POST(self): def do_POST(self):
self.read_ok_collect() self.read_ok_collect(method="POST")
def do_PATCH(self): def do_PATCH(self):
self.read_ok_collect() self.read_ok_collect(method="PATCH")
def do_DELETE(self): 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']) content_length = int(self.headers['Content-Length'])
patch_data = self.rfile.read(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.send_essentials_ok()
self.wfile.write(json.dumps({"id": len(messages_collector)}).encode('utf-8')) self.wfile.write(json.dumps({"id": len(messages_collector)}).encode('utf-8'))
@ -102,12 +113,22 @@ class MockServerRequestHandler(BaseHTTPRequestHandler):
self.end_headers() self.end_headers()
def start_mock_server(port): def start_mock_server(port, config):
mock_server = HTTPServer(('localhost', port), MockServerRequestHandler) mock_server = HTTPServer(('localhost', port), MockServerRequestHandler)
try: try:
print("Server started successfully at http://localhost:{}".format(port)) 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: except KeyboardInterrupt:
print("Shutting down...") print("Shutting down...")
print(pprint.pprint(messages_collector)) except EndOfContent:
pass 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))

View file

@ -42,13 +42,14 @@ if not command_args.no_client:
shutil.move(old_config, backup_filename) shutil.move(old_config, backup_filename)
shutil.copy(new_settings, old_config) shutil.copy(new_settings, old_config)
# revert data file to some low number # 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 = json.loads(data_file.read())
data_file_data["rcid"] = 5 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)) data_file.write(json.dumps(data_file_data, indent=4))
# Start mock server # Start mock server
server.start_mock_server(8080) server.start_mock_server(8080, command_args)
# Revert file changes # Revert file changes
if not command_args.no_client: if not command_args.no_client: