Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unittest #19

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/build.yml
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ package-type = "application"
[tool.pdm.dev-dependencies]
tests = [
"pytest>=7.4.3",
"pytest-mock==3.6.1",
"requests>=2.31.0",
]

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pydantic-settings==2.1.0
pydantic_core==2.14.6
Pygments==2.17.2
pytest==7.4.4
pytest-mock==3.6.1
python-dotenv==1.0.0
python-multipart==0.0.6
PyYAML==6.0.1
Expand Down
36 changes: 36 additions & 0 deletions tests/test_main.py
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
Loading