Skip to content

Commit

Permalink
Fixup issues after package upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
wjdp committed Jul 28, 2023
1 parent 9dd70f8 commit 143ab67
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 42 deletions.
32 changes: 16 additions & 16 deletions src/lumina/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ class BaseDynamoModel(BaseModel):


class MemberConsent(BaseModel, DynamoExportMixin):
consent_news: datetime.datetime | None
consent_network: datetime.datetime | None
consent_members: datetime.datetime | None
consent_students: datetime.datetime | None
consent_news: datetime.datetime | None = None
consent_network: datetime.datetime | None = None
consent_members: datetime.datetime | None = None
consent_students: datetime.datetime | None = None


class MemberModel(BaseDynamoModel, DynamoExportMixin):
sk = table.SK_PROFILE
sk: str = table.SK_PROFILE
name: str
email: EmailStr
phone: str | None
year_of_graduation: int | None
created_at: datetime.datetime | None
email_verified_at: datetime.datetime | None
consent: MemberConsent | None
anonymous_ids: list[UUID] | None
phone: str | None = None
year_of_graduation: int | None = None
created_at: datetime.datetime | None = None
email_verified_at: datetime.datetime | None = None
consent: MemberConsent | None = None
anonymous_ids: list[UUID] | None = None

@property
def id(self) -> str:
Expand All @@ -61,8 +61,8 @@ class SubmitterModel(BaseModel, DynamoExportMixin):
id: str
verified: bool
name: str
year_of_graduation: int | None
email: EmailStr | None
year_of_graduation: int | None = None
email: EmailStr | None = None


class GitHubIssueState(Enum):
Expand All @@ -77,7 +77,7 @@ class GitHubIssueModel(BaseModel, DynamoExportMixin):
title: str
created_at: datetime.datetime
updated_at: datetime.datetime
closed_at: datetime.datetime | None
closed_at: datetime.datetime | None = None
comments: int


Expand All @@ -87,8 +87,8 @@ class SubmissionModel(BaseDynamoModel, DynamoExportMixin):
target_type: str
target_name: str
created_at: datetime.datetime
subject: str | None
message: str | None
subject: str | None = None
message: str | None = None
submitter: SubmitterModel
github_issue: GitHubIssueModel

Expand Down
1 change: 1 addition & 0 deletions src/lumina/database/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ def create_tables():
"Projection": {"ProjectionType": "ALL"},
},
],
BillingMode="PAY_PER_REQUEST",
)
4 changes: 2 additions & 2 deletions src/lumina/schema/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ class AuthCheckRequiredResponse(LuminaModel):


class AuthCheckOptionalResponse(LuminaModel):
id: str | None
expires_at: datetime.datetime | None
id: str | None = None
expires_at: datetime.datetime | None = None
6 changes: 2 additions & 4 deletions src/lumina/schema/base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import humps
from pydantic import BaseModel
from pydantic import BaseModel, ConfigDict


def to_camel(string):
return humps.camelize(string)


class LuminaModel(BaseModel):
class Config:
alias_generator = to_camel
allow_population_by_field_name = True
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
6 changes: 3 additions & 3 deletions src/lumina/schema/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
class GitHubIssue(BaseModel):
number: int
state: GitHubIssueState
state_reason: str | None
state_reason: str | None = None
title: str
created_at: datetime.datetime
updated_at: datetime.datetime
closed_at: datetime.datetime | None
closed_at: datetime.datetime | None = None
comments: int


Expand All @@ -26,5 +26,5 @@ class GitHubRepository(BaseModel):

class GitHubWebhook(BaseModel):
action: str
issue: GitHubIssue | None
issue: GitHubIssue | None = None
repository: GitHubRepository
2 changes: 1 addition & 1 deletion src/lumina/schema/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class HealthCheckCondition(LuminaModel):
ok: bool = Field(description="Whether the condition is ok")
timestamp: datetime.datetime = Field(description="When the last check ran")
message: str | None = Field(description="Details of fault if any")
message: str | None = Field(description="Details of fault if any", default=None)


class HealthCheckResponse(LuminaModel):
Expand Down
10 changes: 6 additions & 4 deletions src/lumina/schema/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
class SubmitterRequest(LuminaModel):
id: UUID = FIELD_SUBMITTER_ID
name: str = FIELD_SUBMITTER_NAME
year_of_graduation: int | None = Field(example=1999)
email: EmailStr | None = Field(example="[email protected]")
year_of_graduation: int | None = Field(example=1999, default=None)
email: EmailStr | None = Field(example="[email protected]", default=None)

def to_model(self) -> SubmitterModel:
return SubmitterModel(
Expand All @@ -49,6 +49,7 @@ class BaseSubmissionRequest(LuminaModel):
submitter: SubmitterRequest | None = Field(
description="The submitter of the submission if, and only if, the submission "
"is anonymous. If the user is logged in this field should be omitted.",
default=None,
)


Expand All @@ -59,6 +60,7 @@ class BaseSubmissionRequest(LuminaModel):
title="Target ID",
description="The ID of the target",
example="00_01/romeo_and_juliet",
default=None,
)
FIELD_TARGET_NAME = Field(
title="Target Name",
Expand All @@ -71,7 +73,7 @@ class BaseSubmissionRequest(LuminaModel):
example="https://history.newtheatre.org.uk/00_01/romeo_and_juliet",
)
FIELD_SUBJECT = Field(
description="The subject of the submission", example="The lighting"
description="The subject of the submission", example="The lighting", default=None
)
FIELD_MESSAGE = Field(
title="Message",
Expand Down Expand Up @@ -135,7 +137,7 @@ class GitHubIssueResponse(LuminaModel):
title: str
created_at: datetime.datetime
updated_at: datetime.datetime
closed_at: datetime.datetime | None
closed_at: datetime.datetime | None = None
comments: int


Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lumina/database/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

@pytest.fixture(scope="function", autouse=True)
def create_tables():
with moto.mock_dynamodb2():
with moto.mock_dynamodb():
table.create_tables()
yield

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lumina/database/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from lumina.database import connection, table


@moto.mock_dynamodb2
@moto.mock_dynamodb
def test_create_tables():
table.create_tables()
tables = list(connection.get_dynamo_db().tables.all())
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/lumina/endpoints/test_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,12 @@ def test_invalid_email(self):
assert response.json() == {
"detail": [
{
"ctx": {"reason": "There must be something after the @-sign."},
"input": "test@",
"loc": ["body", "email"],
"msg": "value is not a valid email address",
"type": "value_error.email",
"msg": "value is not a valid email address: There must be "
"something after the @-sign.",
"type": "value_error",
}
]
}
Expand Down
25 changes: 17 additions & 8 deletions tests/unit/lumina/endpoints/test_submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ def test_with_submissions(self):
"githubIssue": {
"closedAt": None,
"comments": 1,
"createdAt": "2020-01-01T00:00:00+00:00",
"createdAt": "2020-01-01T00:00:00Z",
"number": 1,
"state": "open",
"title": "A title",
"updatedAt": "2020-01-01T00:00:00+00:00",
"updatedAt": "2020-01-01T00:00:00Z",
"url": "https://github.com/newtheatre/lumina-test/issues/2",
},
}
Expand Down Expand Up @@ -182,9 +182,18 @@ def test_require_uuid_submitter_id_if_not_authed(self):
assert response.json() == {
"detail": [
{
"ctx": {
"error": "invalid character: expected an optional prefix "
"of `urn:uuid:` followed by [0-9a-fA-F-], found "
"`r` at 2"
},
"input": "fred_bloggs",
"loc": ["body", "submitter", "id"],
"msg": "value is not a valid uuid",
"type": "type_error.uuid",
"msg": "Input should be a valid UUID, invalid character: expected "
"an optional prefix of `urn:uuid:` followed by "
"[0-9a-fA-F-], found `r` at 2",
"type": "uuid_parsing",
"url": "https://errors.pydantic.dev/2.1/v/uuid_parsing",
}
]
}
Expand Down Expand Up @@ -267,11 +276,11 @@ def test_success_not_authed(self):
"githubIssue": {
"closedAt": None,
"comments": 0,
"createdAt": "2020-01-01T00:00:00+00:00",
"createdAt": "2020-01-01T00:00:00Z",
"number": 123,
"state": "open",
"title": "Test issue",
"updatedAt": "2020-01-01T00:00:00+00:00",
"updatedAt": "2020-01-01T00:00:00Z",
"url": "https://github.com/newtheatre/lumina-test/issues/123",
},
}
Expand Down Expand Up @@ -317,11 +326,11 @@ def test_success_authed(self, auth_fred_bloggs):
"githubIssue": {
"closedAt": None,
"comments": 0,
"createdAt": "2020-01-01T00:00:00+00:00",
"createdAt": "2020-01-01T00:00:00Z",
"number": 123,
"state": "open",
"title": "Test issue",
"updatedAt": "2020-01-01T00:00:00+00:00",
"updatedAt": "2020-01-01T00:00:00Z",
"url": "https://github.com/newtheatre/lumina-test/issues/123",
},
}

0 comments on commit 143ab67

Please sign in to comment.