Skip to content

Commit

Permalink
feat: use Pipfile and pipenv to manage dependencies for backend (#32)
Browse files Browse the repository at this point in the history
* feat: use pipenv for dependencies

* fix: added required python-multipart package

* refactor: renamed TestUserType to UserType inorder to prevent pytest warnings

* chore: updated readme files

* feat: use pipenv in run-windows.cmd install command

* ci: updated test ci to use pipenv

* chore: use pipenv run instead of using .venv packages directly

* ci: removed cache from setup-python action

* ci: use pipenv as cache key in setup-python action

* chore: updated backend dependencies

* chore: updated render.yaml to use pipenv instead

* ci: run pytest via python
  • Loading branch information
FoHoOV authored Oct 5, 2024
1 parent e0e578e commit a9245d4
Show file tree
Hide file tree
Showing 25 changed files with 1,093 additions and 373 deletions.
19 changes: 13 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
python-version: 3.12
cache: "pipenv"

- name: Install pipenv
run: pip install pipenv --user

- name: Install dependencies
run: pip install -r requirements.txt
run: pipenv install --dev

- name: Run the backend tests
run: python3 -m pytest
run: pipenv run python -m pytest

test-frontend:
name: Test Frontend
Expand Down Expand Up @@ -76,16 +79,20 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: 3.12
cache: "pipenv"

- name: Install pipenv
run: pip install pipenv --user

- name: Install dependencies
run: |
cd ../backend
pip install -r requirements.txt
pipenv install
- name: Start backend service
run: |
cd ../backend
setsid python -m uvicorn main:app --port 8080 &
setsid pipenv run uvicorn main:app --port 8080 &
attempts=10
for i in $(seq 1 $attempts); do
if curl --silent --head --fail 127.0.0.1:8080/docs; then
Expand Down
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Project management app

A simple project management app.
A simple project management app.

# Features:

1. creating projects (with add/edit/delete)
2. each project can have many todo categores (with add/edit/delete)
3. each category can have many todo item (with add/edit/delete)
Expand All @@ -16,27 +17,29 @@ A simple project management app.
11. creating projects from a default template
12. adding rules to todo categories (currently we only support `MARK_AS_DONE` and `MARK_AS_UNDONE` action meaning when you move a todo item to a todo category, it will be automatically marked as `Done` or `Undone` depending on what you chose)
13. setting due dates for each todoitem (with add/edit/remove)
14. setting custom permissions per user
14. setting custom permissions per user
15. changing project permissions in project settings page (only owners can change permissions)

* You can use the backend project independently to create your own clients and interfaces
- You can use the backend project independently to create your own clients and interfaces

# Demo

You can find the demo at [this](https://project-management-fohoov.vercel.app) url (it might not work for the first few requests (because service will go down after inactivity), but after 1 or 2 minutes it will start working again).

# How to run

1. goto the backend project and follow the steps of its README.md
2. goto the frontend project and follow the steps of its README.md
1. goto the backend project and follow the steps of its [README.md](https://github.com/FoHoOV/project-management/blob/master/backend/README.md)
2. goto the frontend project and follow the steps of its [README.md](https://github.com/FoHoOV/project-management/blob/master/frontend/README.md)

# Known bugs
* nothing for now >_<

- nothing for now >_<

# Goals

The goal of this project is to have most of ASANA's features (step by step tho)
one day.

# IDK what the title should be

Please give this project a star if you liked it (●'◡'●). Oh, and also I would love any contributions or improvements to this hobby project ^\_^
Please give this project a star if you liked it (●'◡'●). Oh, and also I would love any contributions or improvements to this hobby project ^_^
2 changes: 2 additions & 0 deletions backend/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"autouse",
"DOESNT",
"fastapi",
"pipenv",
"Pipfile",
"pydantic",
"sessionmaker",
"sqlalchemy",
Expand Down
25 changes: 25 additions & 0 deletions backend/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
bcrypt = "~=4.1.3"
fastapi = "~=0.109.2"
pydantic-settings = "~=2.0.2"
greenlet = "~=3.0.1"
joserfc = "~=0.10.0"
sqlalchemy = "~=2.0.19"
psycopg = {extras = ["binary", "pool"], version = "*"}
uvicorn = "~=0.23.2"
httpx = "~=0.26.0"
python-multipart = "~=0.0.6"

[dev-packages]
black = "~=24.8.0"
isort = "~=5.13.2"
pylint = "~=3.3.1"
pytest = "~=8.3.3"

[requires]
python_version = "3.12"
768 changes: 768 additions & 0 deletions backend/Pipfile.lock

Large diffs are not rendered by default.

41 changes: 27 additions & 14 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,51 @@
This is the backend app for my project management app.

## Building the project
First you will need to install the packages from requirements.txt
for instance if you want to use venv then run:

First you will need to install the packages from the Pipfile:

```bash
pipenv install
```

If you don't have pipenv, please follow the [official pipenv instructions](https://pipenv.pypa.io/en/latest/installation.html#preferred-installation-of-pipenv) first inorder to install it.

- this project requires python 3.12 or greater
- if you want to install dev dependencies as well (which includes linters) run this command instead:

```bash
# create venv
python -m venv venv
# activate the venv
... depends on os
pip install -r requirements.txt
pipenv install --dev
```
* this project requires python 3.12 or greater

instead.

## Add env variables

All required env variables are in .env.raw file. Create a new .env file from that template and fill in your own variables
For instance the final .env file in DEV mode would look like this (last update 2023/12/13):

```bash
# .env contents
ALLOWED_ORIGINS = ["http://localhost", "http://localhost:4173", "http://localhost:5173", "http://localhost:5174"]
SQLALCHEMY_DATABASE_URL = "sqlite:///./todos.db"
SQLALCHEMY_DATABASE_URL = "sqlite:///./todos.db"
IS_SQLALCHEMY_LOG_ENABLED = True
```

## Running the project
If you are using vscode you can simply use the run&debug to run the backend app after doing the mentioned steps.

If you are using vscode you can simply use the run&debug to run the backend app after doing the mentioned steps.
You can also run the app manually with:

```bash
python -m uvicorn main:app --reload --port 8080
```
After running the project goto
http://127.0.0.1:8080/docs

After running the project goto
http://127.0.0.1:8080/docs
for a web based swagger docs.

## Tests

For tests to work you need to create a `.env.integration` file. In this file override the database connection string to a test database.
UI tests connect should connect to an instance running in port `8090` for instance which
connects to the test database instead.
UI tests connect should connect to an instance running in port `8090` for instance which
connects to the test database instead.
4 changes: 2 additions & 2 deletions backend/render.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ services:
runtime: python
plan: free
autoDeploy: false
buildCommand: pip install -r requirements.txt
startCommand: uvicorn main:app --host 0.0.0.0 --port 8080
buildCommand: pip install pipenv --user && pipenv install
startCommand: pipenv run uvicorn main:app --host 0.0.0.0 --port 8080
52 changes: 0 additions & 52 deletions backend/requirements.txt

This file was deleted.

10 changes: 5 additions & 5 deletions backend/tests/api/fixtures/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

from db.schemas.user import User

TestUserType = TypedDict("TestUserType", {"id": int, "username": str, "password": str})
UserType = TypedDict("UserType", {"id": int, "username": str, "password": str})

_TEST_USERS: list[TestUserType] = [
_TEST_USERS: list[UserType] = [
{"id": -1, "username": "test_username1", "password": "test_password1"},
{"id": -1, "username": "test_username2", "password": "test_password2"},
{"id": -1, "username": "test_username3", "password": "test_password3"},
Expand Down Expand Up @@ -41,7 +41,7 @@ def test_users(test_client: TestClient, test_app: FastAPI):
def access_token_factory(test_client: TestClient):

def _get_access_token(
user: TestUserType,
user: UserType,
) -> str:
response = test_client.post(
"/oauth/token",
Expand All @@ -63,9 +63,9 @@ def _get_access_token(

@pytest.fixture(scope="function")
def auth_header_factory(
access_token_factory: Callable[[TestUserType], str],
access_token_factory: Callable[[UserType], str],
):
def _get_auth_header(user: TestUserType):
def _get_auth_header(user: UserType):
"""Fixture to generate authorization header for a test user."""
return {"Authorization": f"Bearer {access_token_factory(user)}"}

Expand Down
12 changes: 6 additions & 6 deletions backend/tests/api/fixtures/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

from db.models.user_project_permission import Permission
from db.schemas.project import Project
from tests.api.conftest import TestUserType
from tests.api.conftest import UserType


@pytest.fixture(scope="function")
def update_user_permissions_request(
test_client: TestClient,
auth_header_factory: Callable[[TestUserType], dict[str, str]],
auth_header_factory: Callable[[UserType], dict[str, str]],
):

def _update_permissions(
owner: TestUserType,
target: TestUserType,
owner: UserType,
target: UserType,
project_id: int,
permissions: list[Permission],
):
Expand All @@ -34,9 +34,9 @@ def _update_permissions(


@pytest.fixture(scope="function")
def verify_user_permissions(search_project: Callable[[TestUserType, int], Project]):
def verify_user_permissions(search_project: Callable[[UserType, int], Project]):
def _verify_permissions(
user: TestUserType,
user: UserType,
project: Project,
expected_permissions: dict[int, list[Permission]],
):
Expand Down
Loading

0 comments on commit a9245d4

Please sign in to comment.