summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meson.build2
-rw-r--r--tests/meson.build3
-rwxr-xr-xtests/test_server.py78
3 files changed, 83 insertions, 0 deletions
diff --git a/meson.build b/meson.build
index bdb645f..c752009 100644
--- a/meson.build
+++ b/meson.build
@@ -45,6 +45,8 @@ install_data(
install_dir: get_option('datadir') / 'dict',
)
+subdir('tests')
+
# Local Variables:
# eval: (remove-hook 'before-save-hook 'fmt-current-buffer t)
# End:
diff --git a/tests/meson.build b/tests/meson.build
new file mode 100644
index 0000000..6787668
--- /dev/null
+++ b/tests/meson.build
@@ -0,0 +1,3 @@
+test_server = find_program('test_server.py')
+
+test('test_server', test_server)
diff --git a/tests/test_server.py b/tests/test_server.py
new file mode 100755
index 0000000..2761b0c
--- /dev/null
+++ b/tests/test_server.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python3
+
+import sys
+import asyncio
+import tempfile
+import string
+import random
+import aiohttp
+from pathlib import Path
+
+
+def truncate(file: Path) -> None:
+ with open(file, "w") as f:
+ f.truncate(0)
+
+
+def generate_name() -> str:
+ characters = string.ascii_letters
+
+ return "".join(random.choice(characters) for _ in range(10))
+
+
+async def main() -> int:
+ with tempfile.TemporaryDirectory() as tmpdir:
+ socket = Path(tmpdir) / (generate_name() + ".sock")
+ database = Path(tmpdir) / generate_name()
+
+ truncate(database)
+
+ proc = await asyncio.create_subprocess_exec(
+ "python",
+ "-m",
+ "pypaste.server",
+ "--socket",
+ socket,
+ "--site",
+ "http://dummy",
+ "--content-length-max-bytes",
+ "200000",
+ "--key-length",
+ "3",
+ "--dictionary",
+ "/usr/share/dict/web2",
+ "--database",
+ database,
+ "--storage-max-bytes",
+ "500000000",
+ "sqlite",
+ stdout=asyncio.subprocess.PIPE,
+ stderr=asyncio.subprocess.STDOUT,
+ )
+
+ assert proc.stdout is not None
+
+ line = await proc.stdout.readline()
+
+ if b"starting" not in line:
+ print(line, file=sys.stderr)
+ return 1
+
+ connection = aiohttp.UnixConnector(path=str(socket))
+
+ async with aiohttp.ClientSession(connector=connection) as client:
+ async with client.post("http://dummy/paste", data="hello pypaste") as post:
+ assert post.status == 200
+ data = await post.read()
+
+ url = data.decode()
+
+ async with client.get(url) as get:
+ assert get.status == 200
+ assert b"hello pypaste" in await get.read()
+
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(asyncio.run(main()))