add License SQLAlchemy ORM model

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-06-01 04:48:49 -07:00
parent 38dc2bb99d
commit 943d97efac
2 changed files with 36 additions and 0 deletions

11
aurweb/models/license.py Normal file
View file

@ -0,0 +1,11 @@
from sqlalchemy.orm import mapper
from aurweb.schema import Licenses
class License:
def __init__(self, Name: str = None):
self.Name = Name
mapper(License, Licenses)

25
test/test_license.py Normal file
View file

@ -0,0 +1,25 @@
import pytest
from sqlalchemy.exc import IntegrityError
from aurweb.db import create
from aurweb.models.license import License
from aurweb.testing import setup_test_db
@pytest.fixture(autouse=True)
def setup():
setup_test_db("Licenses")
def test_license_creation():
license = create(License, Name="Test License")
assert bool(license.ID)
assert license.Name == "Test License"
def test_license_null_name_raises_exception():
from aurweb.db import session
with pytest.raises(IntegrityError):
create(License)
session.rollback()