Skip to content

Commit

Permalink
feat : Added get all Invitations endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
marveldo committed Aug 13, 2024
1 parent 7c28790 commit 2761b09
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
15 changes: 14 additions & 1 deletion api/v1/routes/organisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from fastapi.encoders import jsonable_encoder
from fastapi.responses import StreamingResponse
from sqlalchemy.orm import Session

from api.v1.services import invite
from api.utils.success_response import success_response
from api.v1.models.user import User
from api.v1.schemas.organisation import (
Expand Down Expand Up @@ -127,3 +127,16 @@ async def delete_organisation(
status_code=status.HTTP_200_OK,
message="Organisation with ID {org_id} deleted successfully",
)

@organisation.get("/invites", status_code=200)
def get_organization_invites(
db : Session = Depends(get_db),
current_user : User = Depends(user_service.get_current_super_admin),
) :
invitations = invite.InviteService.fetch_all(db)

return success_response(
status_code=status.HTTP_200_OK,
message='Invites fetched succesfully',
data=[jsonable_encoder(invitation) for invitation in invitations]
)
7 changes: 4 additions & 3 deletions api/v1/services/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,10 @@ def delete_all(session: Session):
def fetch(self):
pass

def fetch_all(self):
pass

@staticmethod
def fetch_all(session : Session):
all_invites = session.query(Invitation).all()
return all_invites
def update(self):
pass

Expand Down
42 changes: 42 additions & 0 deletions tests/v1/invitation/test_get_all_invitations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from unittest.mock import patch, MagicMock
import pytest
from fastapi.testclient import TestClient
from datetime import datetime, timedelta, timezone
from uuid_extensions import uuid7
from api.v1.models.invitation import Invitation
from api.v1.services.user import user_service, UserService
from main import app
from api.db.database import get_db
from api.v1.models.user import User

client = TestClient(app)
@pytest.fixture
def mock_db_session():
with patch("api.db.database.get_db", autospec=True) as mock_get_db:
mock_db = MagicMock()
app.dependency_overrides[get_db] = lambda: mock_db
yield mock_db
app.dependency_overrides = {}

def test_get_all_invitations(mock_db_session):

invitations = [Invitation(user_id=str(uuid7()), is_valid = True , organisation_id = str(uuid7()), id=str(uuid7()))]

mock_db_session.query().all.return_value = invitations

app.dependency_overrides[user_service.get_current_super_admin] = lambda : User(
id=str(uuid7()),
email="[email protected]",
password="hashed_password",
first_name='Test',
last_name='User',
is_active=True,
created_at=datetime.now(timezone.utc),
updated_at=datetime.now(timezone.utc),
is_superadmin = True
)

res = client.get('/api/v1/organisations/invites')

assert res.status_code == 200

0 comments on commit 2761b09

Please sign in to comment.