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

Refactor user-facing API models #433

Merged
merged 5 commits into from
Jan 10, 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
39 changes: 27 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,40 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements-dev.txt

- name: Export environment variables
run: |
echo "SECRET_KEY=b6451545d2e4635148d768f07877aade3ad8e7e160d52962badd7587a4b9a150" > .env
echo "SMTP_HOST=smtp.gmail.com" >> .env
echo "SMTP_PORT=465" >> .env
echo "[email protected]" >> .env
echo "EMAIL_PASSWORD=random" >> .env

- name: Build docker images
run: docker-compose -f test-docker-compose.yaml build

r-c-n marked this conversation as resolved.
Show resolved Hide resolved
- name: Run pycodestyle
run: |
pycodestyle api/*.py

- name: Run API containers
run: |
docker-compose -f test-docker-compose.yaml up -d test

- name: Run pylint
run: |
pylint api.auth
pylint api.db
pylint api.main
pylint api.models
pylint api.pubsub
pylint api.user_manager
pylint api.user_models
pylint tests/unit_tests
pylint tests/e2e_tests

- name: Run pytest
docker-compose -f test-docker-compose.yaml exec -T test pylint api.auth
docker-compose -f test-docker-compose.yaml exec -T test pylint api.db
docker-compose -f test-docker-compose.yaml exec -T test pylint api.main
docker-compose -f test-docker-compose.yaml exec -T test pylint api.models
docker-compose -f test-docker-compose.yaml exec -T test pylint api.pubsub
docker-compose -f test-docker-compose.yaml exec -T test pylint api.user_manager
docker-compose -f test-docker-compose.yaml exec -T test pylint tests/unit_tests
docker-compose -f test-docker-compose.yaml exec -T test pylint tests/e2e_tests

- name: Stop docker containers
if: always()
run: |
SECRET_KEY=b6451545d2e4635148d768f07877aade3ad8e7e160d52962badd7587a4b9a150 SMTP_HOST=smtp.gmail.com SMTP_PORT=465 EMAIL_SENDER=test@kernelci.org EMAIL_PASSWORD=random pytest -vs tests/unit_tests/
docker-compose -f test-docker-compose.yaml down

lint:
runs-on: ubuntu-22.04
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ jobs:

- name: Run API containers
run: |
docker-compose -f test-docker-compose.yaml up -d api db redis storage ssh
docker-compose -f test-docker-compose.yaml up -d api db redis storage ssh test

- name: Run test container
- name: Run unit tests
run: |
docker-compose -f test-docker-compose.yaml up --exit-code-from test test
docker-compose -f test-docker-compose.yaml exec -T test pytest -vs tests/unit_tests

- name: Run e2e tests
run: |
docker-compose -f test-docker-compose.yaml exec -T test pytest -v tests/e2e_tests

- name: Stop docker containers
if: always()
Expand Down
2 changes: 1 addition & 1 deletion api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

from .auth import Authentication
from .db import Database
from .user_models import User
from .models import User


async def setup_admin_user(db, username, email):

Check warning on line 23 in api/admin.py

View workflow job for this annotation

GitHub Actions / Lint

Argument name "db" doesn't conform to snake_case naming style
"""Create an admin user"""
user_obj = await db.find_one_by_attributes(User,
{'username': username})
Expand All @@ -46,8 +46,8 @@

async def main(args):
db = Database(args.mongo, args.database)
await db.initialize_beanie()

Check warning on line 49 in api/admin.py

View workflow job for this annotation

GitHub Actions / Lint

Missing function or method docstring

Check warning on line 49 in api/admin.py

View workflow job for this annotation

GitHub Actions / Lint

Redefining name 'args' from outer scope (line 67)
await setup_admin_user(db, args.username, args.email)

Check warning on line 50 in api/admin.py

View workflow job for this annotation

GitHub Actions / Lint

Variable name "db" doesn't conform to snake_case naming style
return True


Expand Down
4 changes: 2 additions & 2 deletions api/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from beanie import init_beanie
from fastapi_pagination.ext.motor import paginate
from motor import motor_asyncio
from .models import Hierarchy, Node, Regression, UserGroup
from .user_models import User
from kernelci.api.models import Hierarchy, Node, Regression

Check failure on line 13 in api/db.py

View workflow job for this annotation

GitHub Actions / Lint

Unable to import 'kernelci.api.models'
from .models import User, UserGroup


class Database:
Expand Down
16 changes: 9 additions & 7 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,26 @@
from pymongo.errors import DuplicateKeyError
from fastapi_users import FastAPIUsers
from beanie import PydanticObjectId
from .auth import Authentication
from .db import Database
from .models import (
from kernelci.api.models import (

Check failure on line 30 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

Unable to import 'kernelci.api.models'
Node,
Hierarchy,
Regression,
UserGroup,
PublishEvent,
get_model_from_kind
)
from .paginator_models import PageModel
from .pubsub import PubSub, Subscription, SubscriptionStats
from .auth import Authentication
from .db import Database
from .pubsub import PubSub
from .user_manager import get_user_manager, create_user_manager
from .user_models import (
from .models import (
PageModel,
Subscription,
SubscriptionStats,
User,
UserRead,
UserCreate,
UserUpdate,
UserGroup,
)


Expand Down
Loading
Loading