mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
PackageRequest: add status_display()
A helper function which provides a textual string conversion of a particular Status column. In a PackageRequest, Status is split up into four different types: - PENDING : "Pending", PENDING_ID: 0 - CLOSED : "Closed", CLOSED_ID: 1 - ACCEPTED : "Accepted", ACCEPTED_ID: 2 - REJECTED : "Rejected", REJECTED_ID: 3 This commit adds constants for the textual strings and the IDs. It also adds a PackageRequest.status_display() function which grabs the proper display string for a particular Status ID. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
469c141f6b
commit
eb8ea53a44
2 changed files with 54 additions and 2 deletions
|
@ -8,6 +8,17 @@ import aurweb.models.user
|
||||||
|
|
||||||
from aurweb.models.declarative import Base
|
from aurweb.models.declarative import Base
|
||||||
|
|
||||||
|
PENDING = "Pending"
|
||||||
|
CLOSED = "Closed"
|
||||||
|
ACCEPTED = "Accepted"
|
||||||
|
REJECTED = "Rejected"
|
||||||
|
|
||||||
|
# Integer values used for the Status column of PackageRequest.
|
||||||
|
PENDING_ID = 0
|
||||||
|
CLOSED_ID = 1
|
||||||
|
ACCEPTED_ID = 2
|
||||||
|
REJECTED_ID = 3
|
||||||
|
|
||||||
|
|
||||||
class PackageRequest(Base):
|
class PackageRequest(Base):
|
||||||
__tablename__ = "PackageRequests"
|
__tablename__ = "PackageRequests"
|
||||||
|
@ -40,6 +51,13 @@ class PackageRequest(Base):
|
||||||
|
|
||||||
__mapper_args__ = {"primary_key": [ID]}
|
__mapper_args__ = {"primary_key": [ID]}
|
||||||
|
|
||||||
|
STATUS_DISPLAY = {
|
||||||
|
PENDING_ID: PENDING,
|
||||||
|
CLOSED_ID: CLOSED,
|
||||||
|
ACCEPTED_ID: ACCEPTED,
|
||||||
|
REJECTED_ID: REJECTED
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
RequestType: aurweb.models.request_type.RequestType = None,
|
RequestType: aurweb.models.request_type.RequestType = None,
|
||||||
PackageBase: aurweb.models.package_base.PackageBase = None,
|
PackageBase: aurweb.models.package_base.PackageBase = None,
|
||||||
|
@ -91,3 +109,7 @@ class PackageRequest(Base):
|
||||||
statement="Column ClosureComment cannot be null.",
|
statement="Column ClosureComment cannot be null.",
|
||||||
orig="PackageRequests.ClosureComment",
|
orig="PackageRequests.ClosureComment",
|
||||||
params=("NULL"))
|
params=("NULL"))
|
||||||
|
|
||||||
|
def status_display(self) -> str:
|
||||||
|
""" Return a display string for the Status column. """
|
||||||
|
return self.STATUS_DISPLAY[self.Status]
|
||||||
|
|
|
@ -4,9 +4,10 @@ import pytest
|
||||||
|
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
|
||||||
from aurweb.db import create, query, rollback
|
from aurweb.db import commit, create, query, rollback
|
||||||
from aurweb.models.package_base import PackageBase
|
from aurweb.models.package_base import PackageBase
|
||||||
from aurweb.models.package_request import PackageRequest
|
from aurweb.models.package_request import (ACCEPTED, ACCEPTED_ID, CLOSED, CLOSED_ID, PENDING, PENDING_ID, REJECTED,
|
||||||
|
REJECTED_ID, PackageRequest)
|
||||||
from aurweb.models.request_type import RequestType
|
from aurweb.models.request_type import RequestType
|
||||||
from aurweb.models.user import User
|
from aurweb.models.user import User
|
||||||
from aurweb.testing import setup_test_db
|
from aurweb.testing import setup_test_db
|
||||||
|
@ -117,3 +118,32 @@ def test_package_request_null_closure_comment_raises_exception():
|
||||||
User=user, PackageBase=pkgbase, PackageBaseName=pkgbase.Name,
|
User=user, PackageBase=pkgbase, PackageBaseName=pkgbase.Name,
|
||||||
Comments=str())
|
Comments=str())
|
||||||
rollback()
|
rollback()
|
||||||
|
|
||||||
|
|
||||||
|
def test_package_request_status_display():
|
||||||
|
""" Test status_display() based on the Status column value. """
|
||||||
|
request_type = query(RequestType, RequestType.Name == "merge").first()
|
||||||
|
|
||||||
|
pkgreq = create(PackageRequest, RequestType=request_type,
|
||||||
|
User=user, PackageBase=pkgbase,
|
||||||
|
PackageBaseName=pkgbase.Name,
|
||||||
|
Comments=str(), ClosureComment=str(),
|
||||||
|
Status=PENDING_ID)
|
||||||
|
assert pkgreq.status_display() == PENDING
|
||||||
|
|
||||||
|
pkgreq.Status = CLOSED_ID
|
||||||
|
commit()
|
||||||
|
assert pkgreq.status_display() == CLOSED
|
||||||
|
|
||||||
|
pkgreq.Status = ACCEPTED_ID
|
||||||
|
commit()
|
||||||
|
assert pkgreq.status_display() == ACCEPTED
|
||||||
|
|
||||||
|
pkgreq.Status = REJECTED_ID
|
||||||
|
commit()
|
||||||
|
assert pkgreq.status_display() == REJECTED
|
||||||
|
|
||||||
|
pkgreq.Status = 124
|
||||||
|
commit()
|
||||||
|
with pytest.raises(KeyError):
|
||||||
|
pkgreq.status_display()
|
||||||
|
|
Loading…
Add table
Reference in a new issue