Skip to content

Commit 047e14a

Browse files
author
Vishakh Pillai
committed
fixing nullable=False and default for unit tests
1 parent 0780b14 commit 047e14a

1 file changed

Lines changed: 62 additions & 15 deletions

File tree

src/webapp/database.py

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,28 @@ class InstTable(Base):
157157
# The emails for which self sign up will be allowed for this institution and will automatically be assigned to this institution.
158158
# The dict structure is {email: AccessType string}
159159
allowed_emails: Mapped[dict[str, str]] = mapped_column(
160-
MutableDict.as_mutable(JSON())
160+
MutableDict.as_mutable(JSON()),
161+
nullable=False,
162+
default=dict,
161163
)
162164
# Schemas that are allowed for validation.
163-
schemas: Mapped[list[str]] = mapped_column(MutableList.as_mutable(JSON()))
165+
schemas: Mapped[list[str]] = mapped_column(
166+
MutableList.as_mutable(JSON()), nullable=False, default=list
167+
)
164168
state: Mapped[str | None] = mapped_column(String(VAR_CHAR_LENGTH), nullable=True)
165169
# Only populated for PDP schools.
166170
pdp_id: Mapped[str | None] = mapped_column(String(VAR_CHAR_LENGTH), nullable=True)
167171
created_at: Mapped[datetime.datetime] = mapped_column(
168-
DateTime(timezone=True), server_default=func.now()
172+
DateTime(timezone=True),
173+
server_default=func.now(),
174+
nullable=False,
175+
default=func.now(),
169176
)
170177
updated_at: Mapped[datetime.datetime] = mapped_column(
171-
DateTime(timezone=True), onupdate=func.now()
178+
DateTime(timezone=True),
179+
onupdate=func.now(),
180+
nullable=False,
181+
default=func.now(),
172182
)
173183
created_by: Mapped[uuid.UUID] = mapped_column(Uuid(as_uuid=True), nullable=True)
174184

@@ -203,9 +213,17 @@ class ApiKeyTable(Base):
203213
allows_enduser: Mapped[bool] = mapped_column(nullable=True)
204214

205215
access_type: Mapped[str] = mapped_column(String(VAR_CHAR_LENGTH), nullable=False)
206-
created_at = mapped_column(DateTime(timezone=True), server_default=func.now())
216+
created_at = mapped_column(
217+
DateTime(timezone=True),
218+
server_default=func.now(),
219+
nullable=False,
220+
default=func.now(),
221+
)
207222
updated_at: Mapped[datetime.datetime] = mapped_column(
208-
DateTime(timezone=True), onupdate=func.now()
223+
DateTime(timezone=True),
224+
onupdate=func.now(),
225+
nullable=False,
226+
default=func.now(),
209227
)
210228
# API key must be valid and not deleted.
211229
deleted: Mapped[bool] = mapped_column(nullable=True)
@@ -274,9 +292,17 @@ class AccountTable(Base):
274292
String(VAR_CHAR_LENGTH), nullable=True
275293
)
276294
# profile_photo_path : Mapped[dict[str, str]] = mapped_column(String(VAR_CHAR_LENGTH), nullable=True)
277-
created_at = mapped_column(DateTime(timezone=True), server_default=func.now())
295+
created_at = mapped_column(
296+
DateTime(timezone=True),
297+
server_default=func.now(),
298+
nullable=False,
299+
default=func.now(),
300+
)
278301
updated_at: Mapped[datetime.datetime] = mapped_column(
279-
DateTime(timezone=True), onupdate=func.now()
302+
DateTime(timezone=True),
303+
onupdate=func.now(),
304+
nullable=False,
305+
default=func.now(),
280306
)
281307

282308

@@ -377,10 +403,16 @@ class FileTable(Base):
377403
# Whether the file was approved (in the case of output) or valid for input.
378404
valid: Mapped[bool] = mapped_column(nullable=False, default=False)
379405
created_at: Mapped[datetime.datetime] = mapped_column(
380-
DateTime(timezone=True), server_default=func.now()
406+
DateTime(timezone=True),
407+
server_default=func.now(),
408+
nullable=False,
409+
default=func.now(),
381410
)
382411
updated_at: Mapped[datetime.datetime] = mapped_column(
383-
DateTime(timezone=True), onupdate=func.now()
412+
DateTime(timezone=True),
413+
onupdate=func.now(),
414+
nullable=False,
415+
default=func.now(),
384416
)
385417

386418
# Within a given institution, there should be no duplicated file names.
@@ -418,10 +450,16 @@ class BatchTable(Base):
418450
DateTime(timezone=True), nullable=True
419451
)
420452
created_at: Mapped[datetime.datetime] = mapped_column(
421-
DateTime(timezone=True), server_default=func.now()
453+
DateTime(timezone=True),
454+
server_default=func.now(),
455+
nullable=False,
456+
default=func.now(),
422457
)
423458
updated_at: Mapped[datetime.datetime] = mapped_column(
424-
DateTime(timezone=True), onupdate=func.now()
459+
DateTime(timezone=True),
460+
onupdate=func.now(),
461+
nullable=False,
462+
default=func.now(),
425463
)
426464
# If a batch is deleted, the uuid of the user in the updated_by section is the deleter.
427465
updated_by: Mapped[uuid.UUID] = mapped_column(Uuid(as_uuid=True), nullable=True)
@@ -460,10 +498,16 @@ class ModelTable(Base):
460498
DateTime(timezone=True), nullable=True
461499
)
462500
created_at: Mapped[datetime.datetime] = mapped_column(
463-
DateTime(timezone=True), server_default=func.now()
501+
DateTime(timezone=True),
502+
server_default=func.now(),
503+
nullable=False,
504+
default=func.now(),
464505
)
465506
updated_at: Mapped[datetime.datetime] = mapped_column(
466-
DateTime(timezone=True), onupdate=func.now()
507+
DateTime(timezone=True),
508+
onupdate=func.now(),
509+
nullable=False,
510+
default=func.now(),
467511
)
468512
# version is unused. version is not currently supported. The webapp only knows about the name of the model and any usages of a model will only use the live version.
469513
version: Mapped[int] = mapped_column(Integer, default=0)
@@ -547,7 +591,10 @@ class SchemaRegistryTable(Base):
547591
)
548592
is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
549593
created_at: Mapped[datetime.datetime] = mapped_column(
550-
DateTime(timezone=True), server_default=func.now(), nullable=False
594+
DateTime(timezone=True),
595+
server_default=func.now(),
596+
nullable=False,
597+
default=func.now(),
551598
)
552599

553600
# ---------------- Relationships ----------------

0 commit comments

Comments
 (0)