mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
add Term SQLAlchemy ORM model
Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
fb21015811
commit
29db2ee513
2 changed files with 45 additions and 0 deletions
15
aurweb/models/term.py
Normal file
15
aurweb/models/term.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
from sqlalchemy.orm import mapper
|
||||
|
||||
from aurweb.schema import Terms
|
||||
|
||||
|
||||
class Term:
|
||||
def __init__(self,
|
||||
Description: str = None, URL: str = None,
|
||||
Revision: int = None):
|
||||
self.Description = Description
|
||||
self.URL = URL
|
||||
self.Revision = Revision
|
||||
|
||||
|
||||
mapper(Term, Terms)
|
30
test/test_term.py
Normal file
30
test/test_term.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
import pytest
|
||||
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from aurweb.db import create, delete
|
||||
from aurweb.models.term import Term
|
||||
|
||||
|
||||
def test_term_creation():
|
||||
term = create(Term, Description="Term description",
|
||||
URL="https://fake_url.io")
|
||||
assert bool(term.ID)
|
||||
assert term.Description == "Term description"
|
||||
assert term.URL == "https://fake_url.io"
|
||||
assert term.Revision == 1
|
||||
delete(Term, Term.ID == term.ID)
|
||||
|
||||
|
||||
def test_term_null_description_raises_exception():
|
||||
from aurweb.db import session
|
||||
with pytest.raises(IntegrityError):
|
||||
create(Term, URL="https://fake_url.io")
|
||||
session.rollback()
|
||||
|
||||
|
||||
def test_term_null_url_raises_exception():
|
||||
from aurweb.db import session
|
||||
with pytest.raises(IntegrityError):
|
||||
create(Term, Description="Term description")
|
||||
session.rollback()
|
Loading…
Add table
Reference in a new issue