summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@iem.at>2019-09-18 13:29:41 +0200
committerIOhannes m zmölnig <zmoelnig@iem.at>2019-09-18 13:29:41 +0200
commit74e03e89410e213f0b51724ba6264ba71c9119b9 (patch)
treeceeda835fddf104e5d299abe8957e1d58dba805d
parent775265563d51f27f16b06507757af7b4d85d6647 (diff)
Provide a functional test for autopkgtest
-rw-r--r--debian/control1
-rwxr-xr-xdebian/tests/authorized3
-rw-r--r--debian/tests/control3
-rwxr-xr-xdebian/tests/testclient49
-rwxr-xr-xdebian/tests/testclient.py73
5 files changed, 128 insertions, 1 deletions
diff --git a/debian/control b/debian/control
index 957ae21..7bfd31f 100644
--- a/debian/control
+++ b/debian/control
@@ -11,7 +11,6 @@ Build-Depends:
python3-all,
python3-setuptools,
python3-requests,
-Testsuite: autopkgtest-pkg-python
Rules-Requires-Root: no
Homepage: https://github.com/amnong/easywebdav
Vcs-Git: https://salsa.debian.org/python-team/modules/python-easywebdav.git
diff --git a/debian/tests/authorized b/debian/tests/authorized
new file mode 100755
index 0000000..7bce6c6
--- /dev/null
+++ b/debian/tests/authorized
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+${0%/*}/testclient foo
diff --git a/debian/tests/control b/debian/tests/control
new file mode 100644
index 0000000..62e649b
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1,3 @@
+Tests: testclient, authorized
+Depends: @, python3-webdav, openssl
+Restrictions: skippable
diff --git a/debian/tests/testclient b/debian/tests/testclient
new file mode 100755
index 0000000..9534692
--- /dev/null
+++ b/debian/tests/testclient
@@ -0,0 +1,49 @@
+#!/bin/bash
+
+DATAFILE=$(mktemp)
+DAVDIR=$(mktemp -d)
+testclient=${0%/*}/testclient.py
+numbytes=512
+
+U=$1
+P=$2
+
+if [ "x${P}" = "x" ]; then
+ P=$(openssl rand -base64 8)
+fi
+
+openssl rand -out "${DATAFILE}" ${numbytes}
+ls -l "${DATAFILE}"
+
+if [ "x${U}" = "x" ]; then
+ python3 -m pywebdav -l ERROR -P 0 -D "${DAVDIR}" -n 2>&1 &
+ SERVER_PID=$!
+else
+ python3 -m pywebdav -l ERROR -P 0 -D "${DAVDIR}" -u "${U}" -p "${P}" 2>&1 &
+ SERVER_PID=$!
+fi
+
+#echo "server running as PID ${SERVER_PID}"
+sleep 1
+
+port=$(lsof -p ${SERVER_PID} 2>/dev/null | egrep "TCP localhost:.*LISTEN" | sed -e 's|.*TCP localhost:||' -e 's| .*||')
+echo "connecting to port:${port}"
+
+if [ "x${U}" = "x" ]; then
+ ${testclient} -P "${port}" "${DATAFILE}"
+else
+ ${testclient} -P "${port}" -u "${U}" -p "${P}" "${DATAFILE}"
+fi
+RETVAL=$?
+
+kill $SERVER_PID
+RETKILL=$?
+
+rm -vrf "${DATAFILE}" "${DAVDIR}"
+
+if [ "x${RETKILL}" != "x0" ]; then
+ echo "server killing failed with ${RETKILL}, skipping test"
+ exit 77
+fi
+
+exit $RETVAL
diff --git a/debian/tests/testclient.py b/debian/tests/testclient.py
new file mode 100755
index 0000000..1d95753
--- /dev/null
+++ b/debian/tests/testclient.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env python3
+import sys
+import tempfile
+import filecmp
+
+import easywebdav
+host="localhost"
+port=8008
+
+
+def config():
+ import argparse
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--port", "-P",
+ type=int, default=port,
+ help="port the WebDAV-server listens on")
+ parser.add_argument(
+ "--user", "-u",
+ type=str, default=None,
+ help="user to authenticate as (if any)")
+ parser.add_argument(
+ "--password", "-p",
+ type=str, default=None,
+ help="password to authenticate with (if any)")
+ parser.add_argument(
+ "file",
+ nargs='?', default=__file__,
+ help="file to up/download")
+
+ return parser.parse_args()
+
+
+def runtest(port, localfile, user=None, password=None):
+ c = easywebdav.connect(host, port, username=user, password=password)
+ print("connect")
+ dirnum=0
+ dirname="tmp"
+ while c.exists(dirname):
+ dirnum += 1
+ dirname = "tmp.%s" % dirnum
+ print("exists")
+ c.mkdir(dirname)
+ print("mkdir '%s'" % (dirname,))
+ filename = "file"
+ tmpfile = tempfile.NamedTemporaryFile()
+
+ # create a directory, upload <localfile> to it, download it
+ c.upload(localfile, dirname + "/" + filename)
+ print("upload '%s'" % (localfile,))
+ c.cd(dirname)
+ print("cd")
+ c.download(filename, tmpfile)
+ print("download '%s'" % (tmpfile.name,))
+ # and remove all traces on the webserver
+ c.delete(filename)
+ print("delete '%s'" % (filename,))
+ c.cd("..")
+ print("cd")
+ c.rmdir(dirname)
+ print("rmdir")
+
+ # then compare the two files
+ tmpfile.flush()
+ x = filecmp.cmp(localfile, tmpfile.name, shallow=False)
+ if not x:
+ raise Exception("'%s' and '%s' do not match" % (localfile, tmpfile.name))
+
+
+if __name__ == "__main__":
+ cfg = config()
+ #print(cfg) or sys.exit()
+ runtest(cfg.port, cfg.file, cfg.user, cfg.password)