Commit 1874e821 authored by Kevin Morris's avatar Kevin Morris
Browse files

add case [in]sensitivity tests + add OfficialProvider model



`ci` in this context means "Case Insensitive".
`cs` in this context means "Case Sensitive".

New models created:
    - OfficialProvider
      This was required to write a test for checking that
      OfficialProviders behaves as we expect, which was the starter
      for the original aurblup bug.

New tests created:
    - test_official_provider

Modified tests:
    - test_package_base: add ci test
    - test_package: add ci test
    - test_session: add cs test
    - test_ssh_pub_key: add cs test
Signed-off-by: Kevin Morris's avatarKevin Morris <kevr@0cost.org>
parent e865a634
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)
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()
...@@ -3,6 +3,8 @@ import pytest ...@@ -3,6 +3,8 @@ import pytest
from sqlalchemy import and_ from sqlalchemy import and_
from sqlalchemy.exc import IntegrityError from sqlalchemy.exc import IntegrityError
import aurweb.config
from aurweb.db import create, query from aurweb.db import create, query
from aurweb.models.account_type import AccountType from aurweb.models.account_type import AccountType
from aurweb.models.package import Package from aurweb.models.package import Package
...@@ -55,6 +57,20 @@ def test_package(): ...@@ -55,6 +57,20 @@ def test_package():
assert record is not None 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(): def test_package_null_pkgbase_raises_exception():
from aurweb.db import session from aurweb.db import session
......
...@@ -2,6 +2,8 @@ import pytest ...@@ -2,6 +2,8 @@ import pytest
from sqlalchemy.exc import IntegrityError from sqlalchemy.exc import IntegrityError
import aurweb.config
from aurweb.db import create, query from aurweb.db import create, query
from aurweb.models.account_type import AccountType from aurweb.models.account_type import AccountType
from aurweb.models.package_base import PackageBase from aurweb.models.package_base import PackageBase
...@@ -35,6 +37,25 @@ def test_package_base(): ...@@ -35,6 +37,25 @@ def test_package_base():
assert pkgbase.ModifiedTS > 0 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(): def test_package_base_relationships():
pkgbase = create(PackageBase, pkgbase = create(PackageBase,
Name="beautiful-package", Name="beautiful-package",
......
...@@ -33,6 +33,15 @@ def test_session(): ...@@ -33,6 +33,15 @@ def test_session():
assert session.UsersID == user.ID 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(): def test_session_user_association():
# Make sure that the Session user attribute is correct. # Make sure that the Session user attribute is correct.
assert session.User == user assert session.User == user
......
...@@ -41,6 +41,18 @@ def test_ssh_pub_key(): ...@@ -41,6 +41,18 @@ def test_ssh_pub_key():
assert ssh_pub_key.PubKey == "testPubKey" 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(): def test_ssh_pub_key_fingerprint():
assert get_fingerprint(TEST_SSH_PUBKEY) is not None assert get_fingerprint(TEST_SSH_PUBKEY) is not None
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment