RequestType: add name_display() and record constants

Just like some of the other tables, we have some constant
records that we use to denote types of things. This commit
adds constants which correlate with these record constants.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-08-07 15:43:44 -07:00
parent eb8ea53a44
commit 5bd3a7bbab
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
2 changed files with 28 additions and 2 deletions

View file

@ -1,7 +1,12 @@
from sqlalchemy import Column, Integer
from aurweb import db
from aurweb.models.declarative import Base
DELETION = "deletion"
ORPHAN = "orphan"
MERGE = "merge"
class RequestType(Base):
__tablename__ = "RequestTypes"
@ -9,3 +14,13 @@ class RequestType(Base):
ID = Column(Integer, primary_key=True)
__mapper_args__ = {"primary_key": [ID]}
def name_display(self) -> str:
""" Return the Name column with its first char capitalized. """
name = self.Name
return name[0].upper() + name[1:]
DELETION_ID = db.query(RequestType, RequestType.Name == DELETION).first().ID
ORPHAN_ID = db.query(RequestType, RequestType.Name == ORPHAN).first().ID
MERGE_ID = db.query(RequestType, RequestType.Name == MERGE).first().ID

View file

@ -1,7 +1,7 @@
import pytest
from aurweb.db import create, delete
from aurweb.models.request_type import RequestType
from aurweb.db import create, delete, query
from aurweb.models.request_type import DELETION_ID, MERGE_ID, ORPHAN_ID, RequestType
from aurweb.testing import setup_test_db
@ -22,3 +22,14 @@ def test_request_type_null_name_returns_empty_string():
assert bool(request_type.ID)
assert request_type.Name == str()
delete(RequestType, RequestType.ID == request_type.ID)
def test_request_type_name_display():
deletion = query(RequestType, RequestType.ID == DELETION_ID).first()
assert deletion.name_display() == "Deletion"
orphan = query(RequestType, RequestType.ID == ORPHAN_ID).first()
assert orphan.name_display() == "Orphan"
merge = query(RequestType, RequestType.ID == MERGE_ID).first()
assert merge.name_display() == "Merge"