Skip to content

Commit

Permalink
chore: fix mypy errs
Browse files Browse the repository at this point in the history
  • Loading branch information
abyrne committed Nov 2, 2023
1 parent 5923617 commit 3f083c5
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 1,176 deletions.
5 changes: 3 additions & 2 deletions src/dioptra/restapi/group/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
from typing import List, Optional

import structlog
from flask import request
from flask_accepts import accepts, responds
from flask_restx import Namespace, Resource
from injector import inject
from structlog.stdlib import BoundLogger

from dioptra.restapi.utils import as_api_parser, slugify
from dioptra.restapi.utils import slugify

from .errors import GroupDoesNotExistError, GroupSubmissionError
from .errors import GroupDoesNotExistError
from .model import Group
from .schema import GroupSchema
from .service import GroupService
Expand Down
13 changes: 0 additions & 13 deletions src/dioptra/restapi/group/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,9 @@
"""The data models for the job endpoint objects."""
from __future__ import annotations

import datetime
from typing import Optional

from flask_wtf import FlaskForm
from flask_wtf.file import FileAllowed, FileField, FileRequired
from typing_extensions import TypedDict
from werkzeug.datastructures import FileStorage
from wtforms.fields import StringField
from wtforms.validators import UUID, InputRequired
from wtforms.validators import Optional as OptionalField
from wtforms.validators import Regexp, ValidationError

from dioptra.restapi.app import db
from dioptra.restapi.group_membership.model import GroupMembership
from dioptra.restapi.user.model import User
from dioptra.restapi.utils import slugify


class Group(db.Model):
Expand Down
5 changes: 1 addition & 4 deletions src/dioptra/restapi/group/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@

from typing import Any, Dict

from marshmallow import Schema, fields, post_dump, post_load, pre_dump, validate
from werkzeug.datastructures import FileStorage

from dioptra.restapi.utils import slugify
from marshmallow import Schema, fields, post_load

from .model import Group

Expand Down
8 changes: 2 additions & 6 deletions src/dioptra/restapi/group/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@
from __future__ import annotations

import datetime
import uuid
from pathlib import Path
from typing import List, Optional
from typing import List

import structlog
from injector import inject
from sqlalchemy.exc import IntegrityError
from structlog.stdlib import BoundLogger
from werkzeug.utils import secure_filename

from dioptra.restapi.app import db

Expand Down Expand Up @@ -85,6 +81,6 @@ def delete(self, id: int, **kwargs) -> bool:
db.session.commit()

return True
except IntegrityError as e:
except IntegrityError:
db.session.rollback()
return False
11 changes: 4 additions & 7 deletions src/dioptra/restapi/group_membership/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@
from __future__ import annotations

import uuid
from typing import List, Optional

import structlog
from flask import request
from flask_accepts import accepts, responds
from flask_restx import Namespace, Resource
from injector import inject
from structlog.stdlib import BoundLogger

from dioptra.restapi.utils import as_api_parser

from .errors import GroupMembershipDoesNotExistError, GroupMembershipSubmissionError
from .model import GroupMembership
from .schema import GroupMembershipSchema
from .service import GroupMembershipService
Expand Down Expand Up @@ -56,7 +53,7 @@ def __init__(
super().__init__(*args, **kwargs)

@responds(schema=GroupMembershipSchema(many=True), api=api)
def get(self) -> List[GroupMembership]:
def get(self) -> list[GroupMembership]:
"""Get a list of all group memberships."""
log: BoundLogger = LOGGER.new(
request_id=str(uuid.uuid4()),
Expand All @@ -71,7 +68,7 @@ def get(self) -> List[GroupMembership]:
def post(self) -> GroupMembership:
"""Create a new group membership using a group membership submission form."""
log: BoundLogger = LOGGER.new(
request_id=str(uuid.uuid.uuid4()),
request_id=str(uuid.uuid4()),
resource="group_membership",
request_type="POST",
)
Expand All @@ -94,7 +91,7 @@ def post(self) -> GroupMembership:
def delete(self) -> bool:
"""Delete a group membership."""
log: BoundLogger = LOGGER.new(
request_id=str(uuid.uuid.uuid4()),
request_id=str(uuid.uuid4()),
resource="group_membership",
request_type="DELETE",
)
Expand Down
2 changes: 1 addition & 1 deletion src/dioptra/restapi/group_membership/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def handle_job_does_not_exist_error(error):
def handle_job_submission_error(error):
return (
{
"message": "Bad Request - The group membership submission form contains "
"message": "Bad Request - The group membership submission form contains"
"invalid parameters. Please verify and resubmit."
},
400,
Expand Down
19 changes: 4 additions & 15 deletions src/dioptra/restapi/group_membership/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,7 @@
"""The data models for the job endpoint objects."""
from __future__ import annotations

import datetime
from typing import Optional

from flask_wtf import FlaskForm
from flask_wtf.file import FileAllowed, FileField, FileRequired
from typing_extensions import TypedDict
from werkzeug.datastructures import FileStorage
from wtforms.fields import BooleanField, IntegerField, StringField
from wtforms.validators import UUID, InputRequired
from wtforms.validators import Optional as OptionalField
from wtforms.validators import Regexp, ValidationError

from dioptra.restapi.app import db
from dioptra.restapi.utils import slugify


class GroupMembership(db.Model):
Expand All @@ -41,8 +28,10 @@ class GroupMembership(db.Model):
group_id (str): The ID of the group to which the user belongs.
read (bool): Indicates whether the user has read permissions in the group.
write (bool): Indicates whether the user has write permissions in the group.
share_read (bool): Indicates whether the user can share read permissions with others in the group.
share_write (bool): Indicates whether the user can share write permissions with others in the group.
share_read (bool): Indicates whether the user can share read permissions with
others in the group.
share_write (bool): Indicates whether the user can share write permissions
with others in the group.
"""

__tablename__ = "group_memberships"
Expand Down
3 changes: 2 additions & 1 deletion src/dioptra/restapi/group_membership/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#
# ACCESS THE FULL CC BY 4.0 LICENSE HERE:
# https://creativecommons.org/licenses/by/4.0/legalcode
"""Methods for registering the group membership endpoint routes with the main application.
"""Methods for registering the group membership endpoint routes with the main
application.
.. |Api| replace:: :py:class:`flask_restx.Api`
.. |Flask| replace:: :py:class:`flask.Flask`
Expand Down
17 changes: 9 additions & 8 deletions src/dioptra/restapi/group_membership/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@

from typing import Any, Dict

from marshmallow import Schema, fields, post_dump, post_load, pre_dump, validate
from werkzeug.datastructures import FileStorage

from dioptra.restapi.utils import ParametersSchema, slugify
from marshmallow import Schema, fields, post_load

from .model import GroupMembership

Expand All @@ -40,8 +37,10 @@ class GroupMembershipSchema(Schema):
group_id: The ID of the group to which the user belongs.
read: Indicates whether the user has read permissions in the group.
write: Indicates whether the user has write permissions in the group.
share_read: Indicates whether the user can share read permissions with others in the group.
share_write: Indicates whether the user can share write permissions with others in the group.
share_read: Indicates whether the user can share read permissions with others
in the group.
share_write: Indicates whether the user can share write permissions with
others in the group.
"""

__model__ = GroupMembership
Expand Down Expand Up @@ -69,13 +68,15 @@ class GroupMembershipSchema(Schema):
share_read = fields.Boolean(
attribute="share_read",
metadata=dict(
description="Indicates whether the user can share read permissions with others in the group."
description="Indicates whether the user can share read permissions with \
others in the group."
),
)
share_write = fields.Boolean(
attribute="share_write",
metadata=dict(
description="Indicates whether the user can share write permissions with others in the group."
description="Indicates whether the user can share write permissions with \
others in the group."
),
)

Expand Down
15 changes: 5 additions & 10 deletions src/dioptra/restapi/group_membership/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@
"""The server-side functions that perform group membership endpoint operations."""
from __future__ import annotations

import datetime
import uuid
from pathlib import Path
from typing import List, Optional
from typing import List

import structlog
from injector import inject
from sqlalchemy.exc import IntegrityError
from structlog.stdlib import BoundLogger
from werkzeug.utils import secure_filename

from dioptra.restapi.app import db

Expand Down Expand Up @@ -64,12 +59,12 @@ def get_all(**kwargs) -> List[GroupMembership]:
return GroupMembership.query.all() # type: ignore

@staticmethod
def get_by_id(group_id: int, user_id: int, **kwargs) -> GroupMembership:
def get_by_id(group_id: int, user_id: int, **kwargs) -> GroupMembership | None:
log: BoundLogger = kwargs.get("log", LOGGER.new()) # noqa: F841

return GroupMembership.query.filter(
return GroupMembership.query.filter( # type: ignore
GroupMembership.user_id == user_id, GroupMembership.group_id == group_id
).first() # type: ignore
).first()

def submit(
self,
Expand Down Expand Up @@ -106,6 +101,6 @@ def delete(self, group_id, user_id, **kwargs) -> bool:
db.session.commit()

return True
except IntegrityError as e:
except IntegrityError:
db.session.rollback()
return False
28 changes: 0 additions & 28 deletions src/dioptra/restapi/resource copy/__init__.py

This file was deleted.

Loading

0 comments on commit 3f083c5

Please sign in to comment.