Skip to content

Commit

Permalink
feat(app/event-groups): enhance responses
Browse files Browse the repository at this point in the history
  • Loading branch information
dantetemplar committed Sep 3, 2023
1 parent 06d2494 commit 309276e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
10 changes: 5 additions & 5 deletions src/app/event_groups/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
EventGroupNotFoundException,
OperationIsNotAllowed,
EventGroupWithMissingPath,
IcsFileIsNotModified,
IncorrectCredentialsException,
NoCredentialsException,
)
Expand Down Expand Up @@ -165,6 +164,7 @@ async def list_event_groups(
@router.put(
"/{event_group_id}/schedule.ics",
responses={
200: {"description": ".ics file is not modified"},
201: {"description": ".ics file updated successfully"},
# 304: {"description": ".ics file already exists and content is the same"},
**EventGroupWithMissingPath.responses,
Expand All @@ -186,7 +186,7 @@ async def set_event_group_ics(
if ics_file.content_type != "text/calendar":
return JSONResponse(
status_code=400,
content={"message": f"File content type is {ics_file.content_type}, but should be 'text/calendar'"},
content={"detail": f"File content type is {ics_file.content_type}, but should be 'text/calendar'"},
)

event_group = await event_group_repository.read(event_group_id)
Expand All @@ -208,7 +208,7 @@ async def set_event_group_ics(
calendar = icalendar.Calendar.from_ical(await ics_file.read())
validate_calendar(calendar)
except ValueError as e:
return JSONResponse(status_code=400, content={"message": f"File is not valid:\n{e}"})
return JSONResponse(status_code=400, content={"detail": f"File is not valid:\n{e}"})

content = calendar.to_ical()

Expand All @@ -217,12 +217,12 @@ async def set_event_group_ics(
async with aiofiles.open(ics_path, "rb") as f:
old_content = await f.read()
if old_content == content:
return IcsFileIsNotModified()
return JSONResponse(status_code=200, content={"detail": "File already exists and content is the same"})

async with aiofiles.open(ics_path, "wb") as f:
await f.write(content)

return JSONResponse(status_code=201, content={"message": "File uploaded successfully"})
return JSONResponse(status_code=201, content={"detail": "File uploaded successfully"})


# ^^^^^^^^^^^^^ ICS-related ^^^^^^^^^^^^^^^^^^^^^^^^ #
14 changes: 0 additions & 14 deletions src/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,6 @@ def __init__(self):
responses = {400: {"description": "Path is not defined for this event group"}}


class IcsFileIsNotModified(HTTPException):
"""
HTTP_304_NOT_MODIFIED
"""

def __init__(self):
super().__init__(
status_code=status.HTTP_304_NOT_MODIFIED,
detail=self.responses[304]["description"],
)

responses = {304: {"description": "Event group already connected to the same .ics file"}}


class OperationIsNotAllowed(HTTPException):
"""
HTTP_403_FORBIDDEN
Expand Down

1 comment on commit 309276e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src
   exceptions.py35683%11, 28, 42, 56, 84, 98
   main.py884549%82–151, 156–157, 162–165, 175
src/app
   dependencies.py47296%29, 37
src/app/auth
   common.py281739%12–21, 25–32, 36–44, 49–50
   dependencies.py16662%33–38, 42
   jwt.py513433%26–28, 32–36, 40–44, 48–53, 57–70, 74–81
src/app/event_groups
   routes.py724143%39–45, 65–76, 116–120, 140, 157–158, 186–225
src/app/ics
   routes.py594229%34–43, 49–75, 95–118
src/app/users
   routes.py251348%32–34, 54–59, 78–80, 102–107
src/app/workshops
   __init__.py550%1–9
   routes.py16160%1–63
src/repositories
   crud.py941287%89, 105, 108, 125, 142, 156–157, 171–180
src/repositories/event_groups
   repository.py58591%57–58, 65–68
src/repositories/predefined
   repository.py1517054%26, 34, 56, 64, 73, 76–84, 97–99, 103–108, 119–123, 127–130, 133, 136, 139, 147–158, 162–171, 175–205
src/repositories/workshops
   __init__.py330%1–4
   abc.py440%1–10
   repository.py34340%1–68
src/schemas
   events.py71692%48, 56, 79, 98–100
   tags.py40198%36
   workshops.py58580%1–85
TOTAL159642074% 

Tests Skipped Failures Errors Time
53 0 💤 2 ❌ 1 🔥 16.672s ⏱️

Please sign in to comment.