Skip to content

Commit be5501b

Browse files
authored
Feat: Various fixes across the application (#127)
* chore(pyproject): update install steps and change to using uv * chore: python version pinned to 3.11 * chore(format): ran the formatter over the entire project * fix(ci): split test and dev dependencies again, update action script * fix(ci): removed requirements.txt requirement * fix(uv): update uv.lock to current state * refactor(permissions): rewrote permissions to integrate admin types * fix: type errors in officers crud * refactor(permissions): restructured most endpoints to use Depends * tests: whole test suite can now be run * fix: missing awaits on permission check calls * fix: move `conftest.py` to only work on integrations tests * feat: add GET all registrations * feat(nominee): add create endpoint * feat: add GET all nominees * feat: add DELETE nominee_info * fix(Elections): duplicate operation id in nominees URLs * refactor: split election tests into multiple functions * fix(tests): split admin elections tests * fix(permissions): fixed some permission tests to be more efficient * refactor: update Nominee model names * fix(registrations): change return type to list * fix(registration): fix list being sent as a JSON response * refactor(officers): response for current officers changed to list * fix(officers): tests that expect a dict response for current officers * fix(Officers): merged the public and private models * chore(OfficerInfoDB): remove unused methods * fix(test): user client is now module scoped * fix(officers): model fields use OfficerPositionEnum * refactor: made a computed field * fix(officers): term_id added to Officer response, id is now an int * refactor: rename OfficerUpdate to OfficerInfoUpdate * refactor: change csss_email to a computed field * chore(officers): delete old dataclass types * fix: remove csss_email * fix: check that end_date is null for current officers * fix: tests failed after the check for current admin changed * fix: made all timestamps timezone aware, UTC stored now * chore(tables): rename the rest of the DB tables * refactor(nominee): update nominee models and PATCH request * refactor(candidates): renamed registrations to candidates * fix(alembic): registration renamed to candidates * fix(nominee): update POST to use create model * fix(candidates): missed some renames * fix(candidates): updating a candidate with the same position failed * tests(nominee): created base tests * fix(tests): databases now persist for an entire test module (file) * note: this has broken some tests
1 parent 43a943f commit be5501b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+3620
-2954
lines changed

.github/workflows/alembic.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
python3.11 -m pip install --upgrade pip
3939
python3.11 -m venv venv
4040
source ./venv/bin/activate
41-
pip install -r requirements.txt
41+
pip install .
4242
4343
# This will fail if there are divergent heads and alembic gets confused;
4444
# e.g., un-sanitarily merging main into a dev branch.

.github/workflows/pytest_unit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
python -m pip install --upgrade pip
2727
python -m venv venv
2828
source ./venv/bin/activate
29-
pip install -r requirements.txt
29+
pip install ".[test]"
3030
3131
- name: Run unit tests
3232
run: PYTHONPATH=src ./venv/bin/python -m pytest ./tests/unit -v

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ google_key.json
88
# Python - Byte-compiled / optimized / DLL files
99
__pycache__/
1010
*.py[cod]
11+
build/
12+
dist/
13+
wheels
14+
*.egg-info/
1115
*$py.class
1216

1317
.venv

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,35 @@ See [the csss-backend wiki](https://github.com/CSSS/csss-site-backend/wiki/1.-Lo
1212

1313
If you're planning to read through the source code, please check out this project's [naming conventions](https://github.com/CSSS/csss-site-backend/wiki/Style-Guide#naming-conventions).
1414

15+
### Quickstart
16+
17+
1. Install [Python 3.11](https://www.python.org/downloads/), [git](https://git-scm.com/install/), and (optionally) [Docker](https://www.docker.com/get-started/)
18+
Note: This may fail if you're using Python 3.12+
19+
2. Clone this repository
20+
3. Create and activate a virtual environment for this project. This has been tested with `pip` and `uv`
21+
4. Install developer dependencies
22+
```bash
23+
# Install main dependencies
24+
pip install . # or: uv pip install .
25+
26+
# Install with dev dependencies
27+
pip install ".[dev]" # or: uv pip install ".[dev]"
28+
29+
# Install with test dependencies
30+
pip install ".[test]" # or: uv pip install ".[test]"
31+
32+
# Install with all dependencies
33+
pip install ".[dev, test]" # or: uv pip install ".[dev, test]"
34+
```
35+
36+
5. Follow the database setup instructions on the [wiki](https://github.com/CSSS/csss-site-backend/wiki/1.-Local-Setup#database-setup). The recommended way is to do it through Docker, but both should work.
37+
6. You will need to set the following environment variables
38+
```bash
39+
export DB_PORT=5444 # The port your database is listening at
40+
export LOCAL=true # Should be true if you're running this locally
41+
```
42+
43+
1544
## Important Directories
1645

1746
- `config/` configuration files for the server machine
@@ -26,6 +55,7 @@ If you're planning to read through the source code, please check out this projec
2655
- `officers/` for officer contact information + photos
2756
- `test/` for html pages which interact with the backend's local api
2857

29-
## Linter
58+
## Developer Tools
3059

3160
We use `ruff 0.6.9` as our linter, which you can run with `ruff check --fix`. If you use a different version, it may be inconsistent with our CI checks.
61+
We use `pyright/basedpyright` for typechecking. Language services have been left enabled and will be changed if it becomes an issue.

pyproject.toml

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,58 @@
11
[project]
22
name = "csss-site-backend"
33
version = "0.1"
4-
requires-python = ">= 3.11" # older versions untested, but we use new features often
4+
requires-python = "~=3.11.0" # older versions untested, but we use new features often
5+
6+
dependencies = [
7+
# major
8+
"fastapi==0.115.6",
9+
"gunicorn==21.2.0",
10+
"uvicorn[standard]==0.27.1",
11+
"sqlalchemy[asyncio]==2.0.27",
12+
"asyncpg==0.29.0",
13+
"alembic==1.13.1",
14+
"google-api-python-client==2.143.0",
15+
16+
# minor
17+
"pyOpenSSL==24.0.0", # for generating cryptographically secure random numbers
18+
"xmltodict==0.13.0",
19+
"requests==2.31.0",
20+
]
21+
22+
[project.optional-dependencies]
23+
dev = [
24+
"ruff==0.6.9", # linting and formatter
25+
]
26+
27+
test = [
28+
"pytest", # test framework
29+
"pytest-asyncio",
30+
"httpx",
31+
]
532

633
[project.urls]
734
Homepage = "https://api.sfucsss.org/"
835

36+
# Pytest: Test framework
937
[tool.pytest.ini_options]
1038
pythonpath = ["src"]
1139
log_cli = true
1240
log_cli_level = "INFO"
1341
testpaths = [
1442
"tests",
15-
]
43+
]
1644
norecursedirs = "tests/wip"
1745
asyncio_mode = "auto"
1846
asyncio_default_fixture_loop_scope = "function"
1947

48+
# Ruff: Formatter and linter
2049
[tool.ruff]
2150
line-length = 120
2251
indent-width = 4
2352
target-version = "py311"
53+
exclude = [
54+
"src/alembic/*"
55+
]
2456

2557
[tool.ruff.format]
2658
quote-style = "double"
@@ -31,6 +63,12 @@ line-ending = "lf"
3163
select = ["E", "F", "B", "I", "N", "UP", "A", "PTH", "W", "RUF", "C4", "PIE", "Q", "FLY"] # "ANN"
3264
ignore = ["E501", "F401", "N806"]
3365

66+
# [Based]Pyright: Type checker/LSP
3467
[tool.pyright]
35-
executionEnvironments = [{ root = "src" }]
68+
executionEnvironments = [
69+
{ root = "src", pythonVersion = "3.11" },
70+
{ root = "tests", extraPaths=["src"], pythonVersion = "3.11" }
71+
]
3672
typeCheckingMode = "standard"
73+
reportAny = "none" # Allow the use of `Any` type
74+
reportExplicitAny = "none" # Allow the declaration of `Any` type

requirements.txt

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import dependencies

src/admin/email.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
GMAIL_ADDRESS = "csss-site@gmail.com"
77
GMAIL_USERNAME = ""
88

9+
910
# TODO: look into sending emails from an sfu maillist (this might be painful)
1011
def send_email(
1112
recipient_address: str,
@@ -22,4 +23,3 @@ def send_email(
2223

2324
mail.sendmail(GMAIL_ADDRESS, recipient_address, content)
2425
mail.quit()
25-

src/alembic/env.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import elections.tables
1212
import nominees.tables
1313
import officers.tables
14-
import registrations.tables
14+
import candidates.tables
1515
from alembic import context
1616

1717
# this is the Alembic Config object, which provides
@@ -62,6 +62,9 @@ async def run_async_migrations() -> None:
6262
and associate a connection with the context.
6363
"""
6464
configuration = config.get_section(config.config_ini_section)
65+
if not configuration:
66+
return
67+
6568
configuration["sqlalchemy.url"] = database.SQLALCHEMY_DATABASE_URL
6669
connectable = async_engine_from_config(
6770
configuration,

src/alembic/versions/0c717bd88d06_elections_timestamp_datetime.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)