~fkfd/sophon

638ad1c6092967e4381f505f02760e7468323cf6 — Frederick Yin 3 years ago 38bfc53
Test: commit session

Automated build-and-run script
2 files changed, 19 insertions(+), 10 deletions(-)

A server/build_and_run
M test/test_edit.py
A server/build_and_run => server/build_and_run +4 -0
@@ 0,0 1,4 @@
cd ..
go build -o server/sophon
cd server
./sophon

M test/test_edit.py => test/test_edit.py +15 -10
@@ 8,7 8,7 @@ def _is_success(resp):
    return resp.status == 20 and resp.meta == "text/gemini"


def test_edit():
def test_edit(commit=False):
    # blank request
    resp = gemini_request("/wiki/test/edit")
    assert resp.status == 10


@@ 35,10 35,10 @@ def test_edit():
    print(f"Preview stage: \n<<====\n" + resp.body + "\n====>>")

    # send diff
#     diff = """@@ -132,16 +132,36 @@
#  ion 1.1.
# + have been improved.
#  %0AAgain, """
    #     diff = """@@ -132,16 +132,36 @@
    #  ion 1.1.
    # + have been improved.
    #  %0AAgain, """

    old_string = """Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Contents of subsection 1.1.


@@ 70,11 70,16 @@ Here's a new line."""
    print(f"Preview page: \n<<====\n" + resp.body + "\n====>>")
    print("Preview page: pass")

    # abort session
    resp = gemini_request(url_base + "abort")
    assert resp.status == 30 and resp.meta == "/wiki/test"
    print(f"Abort session: pass")
    if commit:
        resp = gemini_request(url_base + "commit?Improve page")
        assert resp.status == 30 and resp.meta == "/wiki/test"
        print("Commit sesison: pass")
    else:
        # abort session
        resp = gemini_request(url_base + "abort")
        assert resp.status == 30 and resp.meta == "/wiki/test"
        print("Abort session: pass")


if __name__ == "__main__":
    test_edit()
    test_edit(commit=True)