-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from TheBeetles/create_tests
Creating unit tests
- Loading branch information
Showing
13 changed files
with
389 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Unit Tests | ||
on: | ||
push: | ||
branches: [ main, master ] | ||
pull_request: | ||
branches: [ main, master ] | ||
jobs: | ||
unit: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./api | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
cache: 'pipenv' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pipenv | ||
pipenv install --system | ||
- name: Start docker containers tests and run unit tests | ||
run: docker compose -f ../docker-compose.test.yml up -d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[[source]] | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
name = "pypi" | ||
|
||
[packages] | ||
|
||
[dev-packages] | ||
|
||
[requires] | ||
python_version = "3.11" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM python:3.11.9-bookworm | ||
|
||
WORKDIR /app | ||
|
||
COPY Pipfile Pipfile.lock . | ||
|
||
RUN pip install pipenv | ||
|
||
COPY . . | ||
|
||
RUN pipenv install --ignore-pipfile --system --dev | ||
|
||
CMD python setup.py && python wsgi.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM python:3.11.9-bookworm | ||
|
||
WORKDIR /app | ||
|
||
COPY Pipfile Pipfile.lock . | ||
|
||
RUN pip install pipenv | ||
|
||
COPY . . | ||
|
||
RUN pipenv install --ignore-pipfile --system --dev | ||
|
||
CMD python setup.py && pytest |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import pytest | ||
from pollination import app | ||
|
||
|
||
@pytest.fixture | ||
def client(): | ||
app.config["TESTING"] = True | ||
client = app.test_client() | ||
yield client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from test_unit import client | ||
from pollination import db, File, User | ||
|
||
|
||
def test_delete(client): | ||
response = client.post("/api/login", json={ | ||
"username": "moo", | ||
"password": "moo" | ||
}) | ||
|
||
assert response.status_code == 200 | ||
|
||
user: User = db.session.scalars(db.select(User).filter_by(username="moo")).first() | ||
|
||
assert user is not None | ||
|
||
file: File = db.session.scalars(db.select(File).filter_by(user_id=user.id)).first() | ||
|
||
assert file is not None | ||
|
||
response = client.post("/api/image/delete", json={ | ||
"id": file.alt_id | ||
}) | ||
|
||
assert response.status_code == 200 | ||
|
||
response = client.get("/api/logout") | ||
|
||
assert response.status_code == 200 | ||
|
||
|
||
def test_get_image(client): | ||
response = client.post("/api/login", json={ | ||
"username": "frog", | ||
"password": "frog" | ||
}) | ||
|
||
assert response.status_code == 200 | ||
|
||
user: User = db.session.scalars(db.select(User).filter_by(username="frog")).first() | ||
|
||
assert user is not None | ||
|
||
file: File = db.session.scalars(db.select(File).filter_by(user_id=user.id)).first() | ||
|
||
assert file is not None | ||
|
||
response = client.get(f"/api/image/get/{file.alt_id}") | ||
|
||
assert response.status_code == 200 | ||
|
||
response = client.get("/api/logout") | ||
|
||
assert response.status_code == 200 | ||
|
||
|
||
def test_get_all(client): | ||
response = client.post("/api/login", json={ | ||
"username": "frog", | ||
"password": "frog" | ||
}) | ||
|
||
assert response.status_code == 200 | ||
|
||
user: User = db.session.scalars(db.select(User).filter_by(username="frog")).first() | ||
|
||
assert user is not None | ||
|
||
file: File = db.session.scalars(db.select(File).filter_by(user_id=user.id)).all() | ||
|
||
assert file is not None | ||
|
||
response = client.get("/api/image/all") | ||
|
||
assert response.status_code == 200 | ||
|
||
assert len(response.json["insect"]) == len(file) | ||
|
||
for i in range(len(file)): | ||
assert file[i].alt_id in response.json["insect"][i] | ||
|
||
response = client.get("/api/logout") | ||
|
||
assert response.status_code == 200 | ||
|
||
|
||
|
||
|
Oops, something went wrong.