From 726ff63ec6d084f2ef4d65b084ef204d5fcc5eb0 Mon Sep 17 00:00:00 2001 From: Artyom Shalkhakov Date: Sat, 12 Jan 2019 16:50:26 +0200 Subject: Test case for -endpoints switch --- tests/endpoints.py | 30 ++++++++++++++++++++++++++++++ tests/endpoints.sh | 15 +++++++++++++++ tests/endpoints.ur | 40 ++++++++++++++++++++++++++++++++++++++++ tests/endpoints.urp | 4 ++++ tests/endpoints.urs | 3 +++ 5 files changed, 92 insertions(+) create mode 100755 tests/endpoints.py create mode 100755 tests/endpoints.sh create mode 100644 tests/endpoints.ur create mode 100644 tests/endpoints.urp create mode 100644 tests/endpoints.urs (limited to 'tests') 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 + +
+ + + + + + +
+ +and formbased_handler (r : {Nam : string, Msg : string, Sameday : bool}) : transaction page = + return + +

Oh hello {[r.Nam]}! Great to see you here again!

+

Your message was:

+

{[r.Msg]}

+

Sameday delivery was:

+

{[if r.Sameday then "set" else "unset"]}

+ +
+ +fun say_hi_to (s : string) : transaction page = +return + +

It's {[s]} birthday!

+ +
+ +fun optimized_out (): transaction page = + return this one is optimized away since it's not referenced in the declarations + +fun main (): transaction page = + return + +

hello

+

Say hi to JC

+ +
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 -- cgit v1.2.3