diff --git a/.circleci/config.yml b/.circleci/config.yml index d739004d1..a678ebded 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -56,6 +56,7 @@ workflows: - rust/lint-test-build: release: true - build-and-test + - python-tests-e2e jobs: lint-test-build: @@ -119,6 +120,27 @@ jobs: - ~/.cargo working_directory: <> + python-tests-e2e: + docker: + - image: cimg/python:3.8 + + steps: + - checkout + - python/install-packages: + pkg-manager: pip + app-dir: ~/project # If you're requirements.txt isn't in the root directory. + pip-dependency-file: requirements.txt # if you have a different name for your requirements file, maybe one that combines your runtime and test requirements. + + - run: + name: Install docker compose + command: | + curl -L https://github.com/docker/compose/releases/download/1.25.3/docker-compose-`uname -s`-`uname -m` > ~/docker-compose + chmod +x ~/docker-compose + sudo mv ~/docker-compose /usr/local/bin/docker-compose + cd ~/project + docker-compose build + docker-compose up + build-and-test: # This is the name of the job, feel free to change it to better match what you're trying to do! # These next lines defines a Docker executors: https://circleci.com/docs/2.0/executor-types/ # You can specify an image from Dockerhub or use one of the convenience images from CircleCI's Developer Hub @@ -148,4 +170,3 @@ jobs: python3 -m venv venv source venv/bin/activate maturin develop - pytest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..6f08e1fc4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +# syntax=docker/dockerfile:1 +FROM python:buster +# RUN apt install gcc musl-dev linux-headers software-properties-common && add-apt-repository ppa:deadsnakes/ppa +# RUN apt update && apt install python3.8 +# RUN apt update && apt install -y software-properties-common +# RUN add-apt-repository ppa:deadsnakes/ppa +# RUN apt -y install python3-9 +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y + +# Add .cargo/bin to PATH +ENV PATH="/root/.cargo/bin:${PATH}" + +# Check cargo is visible +RUN cargo --help +WORKDIR /code +COPY requirements.txt requirements.txt +RUN pip3 install -r requirements.txt +EXPOSE 5000 +COPY test_python . +CMD [ "python3", "base_routes.py" ] + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..9301355b7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: "3.7" +services: + web: + build: . + image: localhost:5000/webimage + ports: + - "127.0.0.1:5000:5000" + test: + expose: + - 5000 + depends_on: + - web + build: test_python/. + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..161e1730d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +requests==2.26.0 +pytest==6.2.5 +maturin +robyn==0.6.1 diff --git a/test_dir/build/index.html b/test_dir/build/index.html new file mode 100644 index 000000000..f7fa3647f --- /dev/null +++ b/test_dir/build/index.html @@ -0,0 +1,11 @@ + + + + + + Document + + + Hello world how are you? + + diff --git a/test_python/Dockerfile b/test_python/Dockerfile new file mode 100644 index 000000000..b7a4f68c8 --- /dev/null +++ b/test_python/Dockerfile @@ -0,0 +1,4 @@ +FROM python:buster +RUN pip3 install pytest requests +COPY . . +CMD [ "pytest", "test_routes.py" ] diff --git a/test_python/test.py b/test_python/base_routes.py similarity index 78% rename from test_python/test.py rename to test_python/base_routes.py index 248e10912..cfee58bb9 100644 --- a/test_python/test.py +++ b/test_python/base_routes.py @@ -1,8 +1,7 @@ -import sys -import os -robyn_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../robyn") -sys.path.insert(0, robyn_path) + +# robyn_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../robyn") +# sys.path.insert(0, robyn_path) from robyn import Robyn, static_file, jsonify import asyncio @@ -21,10 +20,13 @@ async def h(request): return message @app.get("/test") -async def test(): - import os - path = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "index.html")) - return static_file(path) +async def test(request): + return static_file("./index.html") + +@app.get("/jsonify") +async def json_get(request): + return jsonify({"hello": "world"}) + @app.post("/jsonify") async def json(request): @@ -63,4 +65,4 @@ def blocker(): if __name__ == "__main__": app.add_header("server", "robyn") app.add_directory(route="/test_dir",directory_path="./test_dir/build", index_file="index.html") - app.start(port=5000) + app.start(port=5000, url='0.0.0.0') diff --git a/test_python/test.sh b/test_python/test.sh new file mode 100755 index 000000000..d725d255c --- /dev/null +++ b/test_python/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +python3 ../base_routes.py +pytest test_routes diff --git a/test_python/test_routes.py b/test_python/test_routes.py new file mode 100644 index 000000000..664e3afb5 --- /dev/null +++ b/test_python/test_routes.py @@ -0,0 +1,12 @@ +import pytest +import requests + +def test_jsonify(): + r = requests.get("http://web:5000/jsonify") + assert r.json()=={"hello":"world"} + assert r.status_code==200 + +def test_html(): + r = requests.get("http://web:5000/test") + assert "Hello world. How are you?" in r.text +