diff --git a/aurweb/models/official_provider.py b/aurweb/models/official_provider.py new file mode 100644 index 0000000000000000000000000000000000000000..073eb4354eaadf3c3d0d5ec7ca33511b40faa192 --- /dev/null +++ b/aurweb/models/official_provider.py @@ -0,0 +1,34 @@ +from sqlalchemy.exc import IntegrityError +from sqlalchemy.orm import mapper + +from aurweb.schema import OfficialProviders + + +class OfficialProvider: + def __init__(self, + Name: str = None, + Repo: str = None, + Provides: str = None): + self.Name = Name + if not self.Name: + raise IntegrityError( + statement="Column Name cannot be null.", + orig="OfficialProviders.Name", + params=("NULL")) + + self.Repo = Repo + if not self.Repo: + raise IntegrityError( + statement="Column Repo cannot be null.", + orig="OfficialProviders.Repo", + params=("NULL")) + + self.Provides = Provides + if not self.Provides: + raise IntegrityError( + statement="Column Provides cannot be null.", + orig="OfficialProviders.Provides", + params=("NULL")) + + +mapper(OfficialProvider, OfficialProviders) diff --git a/test/test_official_provider.py b/test/test_official_provider.py new file mode 100644 index 0000000000000000000000000000000000000000..a1d3d54a72b055b79596734c0d46811a601d0dec --- /dev/null +++ b/test/test_official_provider.py @@ -0,0 +1,75 @@ +import pytest + +from sqlalchemy.exc import IntegrityError + +from aurweb.db import create +from aurweb.models.official_provider import OfficialProvider +from aurweb.testing import setup_test_db + + +@pytest.fixture(autouse=True) +def setup(): + setup_test_db("OfficialProviders") + + +def test_official_provider_creation(): + oprovider = create(OfficialProvider, + Name="some-name", + Repo="some-repo", + Provides="some-provides") + assert bool(oprovider.ID) + assert oprovider.Name == "some-name" + assert oprovider.Repo == "some-repo" + assert oprovider.Provides == "some-provides" + + +def test_official_provider_cs(): + """ Test case sensitivity of the database table. """ + oprovider = create(OfficialProvider, + Name="some-name", + Repo="some-repo", + Provides="some-provides") + assert bool(oprovider.ID) + + oprovider_cs = create(OfficialProvider, + Name="SOME-NAME", + Repo="SOME-REPO", + Provides="SOME-PROVIDES") + assert bool(oprovider_cs.ID) + + assert oprovider.ID != oprovider_cs.ID + + assert oprovider.Name == "some-name" + assert oprovider.Repo == "some-repo" + assert oprovider.Provides == "some-provides" + + assert oprovider_cs.Name == "SOME-NAME" + assert oprovider_cs.Repo == "SOME-REPO" + assert oprovider_cs.Provides == "SOME-PROVIDES" + + +def test_official_provider_null_name_raises_exception(): + from aurweb.db import session + with pytest.raises(IntegrityError): + create(OfficialProvider, + Repo="some-repo", + Provides="some-provides") + session.rollback() + + +def test_official_provider_null_repo_raises_exception(): + from aurweb.db import session + with pytest.raises(IntegrityError): + create(OfficialProvider, + Name="some-name", + Provides="some-provides") + session.rollback() + + +def test_official_provider_null_provides_raises_exception(): + from aurweb.db import session + with pytest.raises(IntegrityError): + create(OfficialProvider, + Name="some-name", + Repo="some-repo") + session.rollback() diff --git a/test/test_package.py b/test/test_package.py index 66d557f34aebfd00ee44b9264e523911ccedf40e..a994f0968a811c56bb425f880f6bebb1a1f152d7 100644 --- a/test/test_package.py +++ b/test/test_package.py @@ -3,6 +3,8 @@ import pytest from sqlalchemy import and_ from sqlalchemy.exc import IntegrityError +import aurweb.config + from aurweb.db import create, query from aurweb.models.account_type import AccountType from aurweb.models.package import Package @@ -55,6 +57,20 @@ def test_package(): assert record is not None +def test_package_ci(): + """ Test case insensitivity of the database table. """ + if aurweb.config.get("database", "backend") == "sqlite": + return None # SQLite doesn't seem handle this. + + from aurweb.db import session + + with pytest.raises(IntegrityError): + create(Package, + PackageBase=pkgbase, + Name="Beautiful-Package") + session.rollback() + + def test_package_null_pkgbase_raises_exception(): from aurweb.db import session diff --git a/test/test_package_base.py b/test/test_package_base.py index e0359f4f3e99d3f371856c0f8ba73fc79da280ea..7f608c2c9027eb3e31b9131c36e1ff353f413c9a 100644 --- a/test/test_package_base.py +++ b/test/test_package_base.py @@ -2,6 +2,8 @@ import pytest from sqlalchemy.exc import IntegrityError +import aurweb.config + from aurweb.db import create, query from aurweb.models.account_type import AccountType from aurweb.models.package_base import PackageBase @@ -35,6 +37,25 @@ def test_package_base(): assert pkgbase.ModifiedTS > 0 +def test_package_base_ci(): + """ Test case insensitivity of the database table. """ + if aurweb.config.get("database", "backend") == "sqlite": + return None # SQLite doesn't seem handle this. + + from aurweb.db import session + + pkgbase = create(PackageBase, + Name="beautiful-package", + Maintainer=user) + assert bool(pkgbase.ID) + + with pytest.raises(IntegrityError): + create(PackageBase, + Name="Beautiful-Package", + Maintainer=user) + session.rollback() + + def test_package_base_relationships(): pkgbase = create(PackageBase, Name="beautiful-package", diff --git a/test/test_session.py b/test/test_session.py index c324a739c1f9babf63b8ad810339bf8f2e72b8aa..1dd82db1ff48f2882edd12f79224704918792d62 100644 --- a/test/test_session.py +++ b/test/test_session.py @@ -33,6 +33,15 @@ def test_session(): assert session.UsersID == user.ID +def test_session_cs(): + """ Test case sensitivity of the database table. """ + session_cs = create(Session, UsersID=user.ID, + SessionID="TESTSESSION", + LastUpdateTS=datetime.utcnow().timestamp()) + assert session_cs.SessionID == "TESTSESSION" + assert session.SessionID == "testSession" + + def test_session_user_association(): # Make sure that the Session user attribute is correct. assert session.User == user diff --git a/test/test_ssh_pub_key.py b/test/test_ssh_pub_key.py index 4072549e16d607af021fc8ddf8e69eee51c033ff..0793199a8d7edf04eb24a4a0ac93e4d4cdc5246c 100644 --- a/test/test_ssh_pub_key.py +++ b/test/test_ssh_pub_key.py @@ -41,6 +41,18 @@ def test_ssh_pub_key(): assert ssh_pub_key.PubKey == "testPubKey" +def test_ssh_pub_key_cs(): + """ Test case sensitivity of the database table. """ + ssh_pub_key_cs = create(SSHPubKey, UserID=user.ID, + Fingerprint="TESTFINGERPRINT", + PubKey="TESTPUBKEY") + + assert ssh_pub_key_cs.Fingerprint == "TESTFINGERPRINT" + assert ssh_pub_key_cs.PubKey == "TESTPUBKEY" + assert ssh_pub_key.Fingerprint == "testFingerprint" + assert ssh_pub_key.PubKey == "testPubKey" + + def test_ssh_pub_key_fingerprint(): assert get_fingerprint(TEST_SSH_PUBKEY) is not None