diff options
author | Artyom Shalkhakov <artyom.shalkhakov@gmail.com> | 2019-01-12 16:50:26 +0200 |
---|---|---|
committer | Artyom Shalkhakov <artyom.shalkhakov@gmail.com> | 2019-01-12 16:50:26 +0200 |
commit | 726ff63ec6d084f2ef4d65b084ef204d5fcc5eb0 (patch) | |
tree | 5c17ac4244c4324525884dfa4f7cee50aedc326d /tests | |
parent | ba1871b3b9cc669c43420f993719690b45326e2f (diff) |
Test case for -endpoints switch
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/endpoints.py | 30 | ||||
-rwxr-xr-x | tests/endpoints.sh | 15 | ||||
-rw-r--r-- | tests/endpoints.ur | 40 | ||||
-rw-r--r-- | tests/endpoints.urp | 4 | ||||
-rw-r--r-- | tests/endpoints.urs | 3 |
5 files changed, 92 insertions, 0 deletions
diff --git a/tests/endpoints.py b/tests/endpoints.py new file mode 100755 index 00000000..8dc5abef --- /dev/null +++ b/tests/endpoints.py @@ -0,0 +1,30 @@ +#!/usr/bin/python3 + +import sys +import json +import time +import subprocess +import urllib.request +import urllib.parse +import os + +def main(): + prefix = 'http://localhost:8080/' + + with open('/tmp/endpoints.json') as json_data: + data = json.load(json_data) + endpoints = data['endpoints'] + for ep in endpoints: + path = ep['url'] + src = urllib.parse.urljoin(prefix, path) + if ep['method'] == 'GET': + contents = urllib.request.urlopen(src).read() + # it's okay that we can retrieve it, enough for us right now + else: + # TODO: add support for parameters? + post_fields = {'Nam': 'X', 'Msg': 'message', 'Sameday': 'on'} # Set POST fields here + request = urllib.request.Request(src, urllib.parse.urlencode(post_fields).encode()) + contents = urllib.request.urlopen(request).read().decode() + +if __name__ == '__main__': + main() diff --git a/tests/endpoints.sh b/tests/endpoints.sh new file mode 100755 index 00000000..1d3289a5 --- /dev/null +++ b/tests/endpoints.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +TEST=endpoints +TESTPID=/tmp/$TEST.pid +TESTENDPOINTS=/tmp/$TEST.json +TESTSRV=./$TEST.exe + +rm -f $TESTENDPOINTS $TESTPID $TESTSRV +../bin/urweb -debug -boot -noEmacs -endpoints $TESTENDPOINTS "$TEST" || exit 1 + +$TESTSRV -q -a 127.0.0.1 & +echo $! >> $TESTPID +sleep 1 +python3 $TEST.py +kill `cat $TESTPID` diff --git a/tests/endpoints.ur b/tests/endpoints.ur new file mode 100644 index 00000000..ddb91faa --- /dev/null +++ b/tests/endpoints.ur @@ -0,0 +1,40 @@ +fun formbased (): transaction page = + return <xml> + <body> + <form> + <label>Your name: <textbox{#Nam}/></label> + <label>Your message: <textarea{#Msg}/></label> + <label>Delivered on the same day <checkbox{#Sameday}/></label> + <submit value="Send" action={formbased_handler}/> + </form> + </body> + </xml> + +and formbased_handler (r : {Nam : string, Msg : string, Sameday : bool}) : transaction page = + return <xml> + <body> + <p>Oh hello {[r.Nam]}! Great to see you here again!</p> + <p>Your message was:</p> + <p>{[r.Msg]}</p> + <p>Sameday delivery was:</p> + <p>{[if r.Sameday then "set" else "unset"]}</p> + </body> + </xml> + +fun say_hi_to (s : string) : transaction page = +return <xml> + <body> + <p>It's {[s]} birthday!</p> + </body> +</xml> + +fun optimized_out (): transaction page = + return <xml>this one is optimized away since it's not referenced in the declarations</xml> + +fun main (): transaction page = + return <xml> + <body> + <p>hello</p> + <p>Say hi to <a link={say_hi_to "JC"}>JC</a></p> + </body> +</xml> diff --git a/tests/endpoints.urp b/tests/endpoints.urp new file mode 100644 index 00000000..faf855bd --- /dev/null +++ b/tests/endpoints.urp @@ -0,0 +1,4 @@ +rewrite url Endpoints/main index.html +rewrite url Endpoints/formbased greet.html + +endpoints diff --git a/tests/endpoints.urs b/tests/endpoints.urs new file mode 100644 index 00000000..fba42a2b --- /dev/null +++ b/tests/endpoints.urs @@ -0,0 +1,3 @@ +val main : unit -> transaction page +val say_hi_to : string -> transaction page +val formbased : unit -> transaction page |