~fkfd/sophon

cad8c31d53c49e88395dda4b9b978f4b17392802 — Frederick Yin 3 years ago 5af6bfa
Test script: restore original page
2 files changed, 48 insertions(+), 1 deletions(-)

A test/demo_client.py
M test/test_edit.py
A test/demo_client.py => test/demo_client.py +43 -0
@@ 0,0 1,43 @@
import subprocess
from diff_match_patch import diff_match_patch
from gcat import gemini_request


def generate_unidiff(old: str, new: str) -> str:
    differ = diff_match_patch()
    diff_list = differ.diff_main(old, new)
    patch_list = differ.patch_make(old, diff_list)
    unidiff = differ.patch_toText(patch_list)
    return unidiff


def req(path: str):
    return gemini_request(path)


def print_page(path: str):
    resp = req(path)
    header = f"<<==== {resp.status} {resp.meta} ====>>"
    footer = "<<" + "=" * (len(header) - 4) + ">>"
    path_indent = " " * ((len(header) - len(path)) // 2 - 1)
    print(f"{path_indent}[{path}]\n{header}\n{resp.body}\n{footer}\n")
    return resp


print("Welcome to the demo client for Sophon")
print_page("/")
print_page("/pages")
found_page = False
while not found_page:
    page = input("Select page to read: ")
    resp = print_page(f"/wiki/{page}")
    if resp.status == 20:
        found_page = True
selected_part = False
session = ""
while not selected_part:
    part = input("Select part to edit ('meta' or 'section=1.1.' etc): ")
    resp = print_page(f"/wiki/{page}/edit?{part}")
    if resp.status == 30:
        selected_part = True
        session = resp.meta

M test/test_edit.py => test/test_edit.py +5 -1
@@ 2,7 2,7 @@ from gcat import gemini_request
from diff_match_patch import diff_match_patch
import re
import urllib

import shutil

def _is_success(resp):
    return resp.status == 20 and resp.meta == "text/gemini"


@@ 71,9 71,13 @@ Here's a new line."""
    print("Preview page: pass")

    if commit:
        # make backup of original test page
        shutil.copy("../server/wiki/test.gmi", "/tmp/test.gmi")
        resp = gemini_request(url_base + "commit?Improve page")
        assert resp.status == 30 and resp.meta == "/wiki/test"
        print("Commit sesison: pass")
        shutil.copy("/tmp/test.gmi", "../server/wiki/test.gmi")
        print("Clean up: finished")
    else:
        # abort session
        resp = gemini_request(url_base + "abort")