-
Notifications
You must be signed in to change notification settings - Fork 12
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 #19 from Jonatan-Chaverri/add_unittest
feat: mock tests and github workflow for them
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: LinkLiberate | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
workflow_dispatch: | ||
inputs: | ||
message: | ||
description: '' | ||
required: false | ||
default: '' | ||
|
||
jobs: | ||
|
||
build-pr: | ||
name: Build | ||
runs-on: [ubuntu-latest] | ||
timeout-minutes: 30 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.11.6 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: 3.11.6 | ||
|
||
- name: Set build start time | ||
run: echo "BUILD_START_TIME=$(date +'%s')" >> $GITHUB_ENV | ||
if: ${{ always() }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
set -o errexit | ||
sudo apt-get update -y | ||
sudo apt-get install -y bc | ||
python -m pip install pdm | ||
pdm install | ||
- name: Run unit tests | ||
run: | | ||
pdm run pytest tests |
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
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,36 @@ | ||
from unittest.mock import Mock | ||
|
||
from fastapi.testclient import TestClient | ||
|
||
from src.link_liberate.main import app | ||
|
||
|
||
def test_index_page(): | ||
client = TestClient(app) | ||
response = client.get("/") | ||
assert response.status_code == 200 | ||
assert "request" in response.context | ||
|
||
|
||
def test_web(): | ||
client = TestClient(app) | ||
response = client.get("/liberate") | ||
assert response.status_code == 200 | ||
assert "request" in response.context | ||
|
||
|
||
def test_web_post(mocker): | ||
# Patch the get_db function to return the db mock | ||
mocker.patch('src.link_liberate.database.Session_Local', return_value=Mock()) | ||
client_mock = TestClient(app) | ||
response = client_mock.post("/liberate", data={"content": "valid_content"}) | ||
assert response.status_code == 200 | ||
|
||
|
||
|
||
def test_get_link(mocker): | ||
# Patch the get_db function to return the db mock | ||
mocker.patch('src.link_liberate.database.Session_Local', return_value=Mock()) | ||
client_mock = TestClient(app) | ||
response = client_mock.get("/valid_uuid", follow_redirects=False) | ||
assert response.status_code == 301 |