mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
use mysql backend in config.dev
First off: This commit changes the default development database backend to mysql. sqlite, however, is still completely supported with the caveat that a user must now modify config.dev to use the sqlite backend. While looking into this, it was discovered that our SQLAlchemy backend for mysql (mysql-connector) completely broke model attributes when we switched to utf8mb4_bin (binary) -- it does not correct the correct conversion to and from binary utf8mb4. The new, replacement dependency mysqlclient does. mysqlclient is also recommended in SQLAlchemy documentation as the "best" one available. The mysqlclient backend uses a different exception flow then sqlite, and so tests expecting IntegrityError has to be modified to expect OperationalError from sqlalchemy.exc. So, for each model that we define, check keys that can't be NULL and raise sqlalchemy.exc.IntegrityError if we have to. This way we keep our exceptions uniform. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
d7481b9649
commit
aecb649473
25 changed files with 363 additions and 135 deletions
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.exc import IntegrityError, OperationalError
|
||||
|
||||
from aurweb.db import create, query
|
||||
from aurweb.models.account_type import AccountType
|
||||
|
@ -36,7 +36,7 @@ def setup():
|
|||
URL="https://test.package")
|
||||
|
||||
|
||||
def test_package_dependencies():
|
||||
def test_package_relation():
|
||||
conflicts = query(RelationType, RelationType.Name == "conflicts").first()
|
||||
pkgrel = create(PackageRelation, Package=package,
|
||||
RelationType=conflicts,
|
||||
|
@ -68,10 +68,12 @@ def test_package_dependencies():
|
|||
assert pkgrel in package.package_relations
|
||||
|
||||
|
||||
def test_package_dependencies_null_package_raises_exception():
|
||||
def test_package_relation_null_package_raises_exception():
|
||||
from aurweb.db import session
|
||||
|
||||
conflicts = query(RelationType, RelationType.Name == "conflicts").first()
|
||||
assert conflicts is not None
|
||||
|
||||
with pytest.raises(IntegrityError):
|
||||
create(PackageRelation,
|
||||
RelationType=conflicts,
|
||||
|
@ -79,7 +81,7 @@ def test_package_dependencies_null_package_raises_exception():
|
|||
session.rollback()
|
||||
|
||||
|
||||
def test_package_dependencies_null_dependency_type_raises_exception():
|
||||
def test_package_relation_null_relation_type_raises_exception():
|
||||
from aurweb.db import session
|
||||
|
||||
with pytest.raises(IntegrityError):
|
||||
|
@ -89,11 +91,13 @@ def test_package_dependencies_null_dependency_type_raises_exception():
|
|||
session.rollback()
|
||||
|
||||
|
||||
def test_package_dependencies_null_depname_raises_exception():
|
||||
def test_package_relation_null_relname_raises_exception():
|
||||
from aurweb.db import session
|
||||
|
||||
depends = query(RelationType, RelationType.Name == "depends").first()
|
||||
with pytest.raises(IntegrityError):
|
||||
depends = query(RelationType, RelationType.Name == "conflicts").first()
|
||||
assert depends is not None
|
||||
|
||||
with pytest.raises((OperationalError, IntegrityError)):
|
||||
create(PackageRelation,
|
||||
Package=package,
|
||||
RelationType=depends)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue