mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
change(aurblup): converted to use aurweb.db ORM
Introduces: - aurweb.testing.alpm.AlpmDatabase - Used to mock up and manage a remote repository. - templates/testing/alpm_package.j2 - Used to generate a single ALPM package desc. - Removed aurblup sharness test Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
3efb9a57b5
commit
29989b7fdb
7 changed files with 246 additions and 72 deletions
|
@ -1,53 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
test_description='aurblup tests'
|
||||
|
||||
. "$(dirname "$0")/setup.sh"
|
||||
|
||||
test_expect_success 'Test official provider update script.' '
|
||||
mkdir -p remote/test/foobar-1.0-1 &&
|
||||
cat <<-EOD >remote/test/foobar-1.0-1/desc &&
|
||||
%FILENAME%
|
||||
foobar-1.0-any.pkg.tar.xz
|
||||
|
||||
%NAME%
|
||||
foobar
|
||||
|
||||
%VERSION%
|
||||
1.0-1
|
||||
|
||||
%ARCH%
|
||||
any
|
||||
EOD
|
||||
mkdir -p remote/test/foobar2-1.0-1 &&
|
||||
cat <<-EOD >remote/test/foobar2-1.0-1/desc &&
|
||||
%FILENAME%
|
||||
foobar2-1.0-any.pkg.tar.xz
|
||||
|
||||
%NAME%
|
||||
foobar2
|
||||
|
||||
%VERSION%
|
||||
1.0-1
|
||||
|
||||
%ARCH%
|
||||
any
|
||||
|
||||
%PROVIDES%
|
||||
foobar3
|
||||
foobar4
|
||||
EOD
|
||||
( cd remote/test && bsdtar -czf ../test.db * ) &&
|
||||
mkdir sync &&
|
||||
cover "$AURBLUP" &&
|
||||
cat <<-EOD >expected &&
|
||||
foobar|test|foobar
|
||||
foobar2|test|foobar2
|
||||
foobar2|test|foobar3
|
||||
foobar2|test|foobar4
|
||||
EOD
|
||||
echo "SELECT Name, Repo, Provides FROM OfficialProviders ORDER BY Provides;" | sqlite3 aur.db >actual &&
|
||||
test_cmp actual expected
|
||||
'
|
||||
|
||||
test_done
|
90
test/test_aurblup.py
Normal file
90
test/test_aurblup.py
Normal file
|
@ -0,0 +1,90 @@
|
|||
import tempfile
|
||||
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
from aurweb import config, db
|
||||
from aurweb.models import OfficialProvider
|
||||
from aurweb.scripts import aurblup
|
||||
from aurweb.testing.alpm import AlpmDatabase
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tempdir() -> str:
|
||||
with tempfile.TemporaryDirectory() as name:
|
||||
yield name
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def alpm_db(tempdir: str) -> AlpmDatabase:
|
||||
yield AlpmDatabase(tempdir)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup(db_test, alpm_db: AlpmDatabase, tempdir: str) -> None:
|
||||
config_get = config.get
|
||||
|
||||
def mock_config_get(section: str, key: str) -> str:
|
||||
value = config_get(section, key)
|
||||
if section == "aurblup":
|
||||
if key == "db-path":
|
||||
return alpm_db.local
|
||||
elif key == "server":
|
||||
return f'file://{alpm_db.remote}'
|
||||
elif key == "sync-dbs":
|
||||
return alpm_db.repo
|
||||
return value
|
||||
|
||||
with mock.patch("aurweb.config.get", side_effect=mock_config_get):
|
||||
config.rehash()
|
||||
yield
|
||||
config.rehash()
|
||||
|
||||
|
||||
def test_aurblup(alpm_db: AlpmDatabase):
|
||||
# Test that we can add a package.
|
||||
alpm_db.add("pkg", "1.0", "x86_64", provides=["pkg2", "pkg3"])
|
||||
alpm_db.add("pkg2", "2.0", "x86_64")
|
||||
aurblup.main()
|
||||
|
||||
# Test that the package got added to the database.
|
||||
for name in ("pkg", "pkg2"):
|
||||
pkg = db.query(OfficialProvider).filter(
|
||||
OfficialProvider.Name == name).first()
|
||||
assert pkg is not None
|
||||
|
||||
# Test that we can remove the package.
|
||||
alpm_db.remove("pkg")
|
||||
|
||||
# Run aurblup again with forced repository update.
|
||||
aurblup.main(True)
|
||||
|
||||
# Expect that the database got updated accordingly.
|
||||
pkg = db.query(OfficialProvider).filter(
|
||||
OfficialProvider.Name == "pkg").first()
|
||||
assert pkg is None
|
||||
pkg2 = db.query(OfficialProvider).filter(
|
||||
OfficialProvider.Name == "pkg2").first()
|
||||
assert pkg2 is not None
|
||||
|
||||
|
||||
def test_aurblup_cleanup(alpm_db: AlpmDatabase):
|
||||
# Add a package and sync up the database.
|
||||
alpm_db.add("pkg", "1.0", "x86_64", provides=["pkg2", "pkg3"])
|
||||
aurblup.main()
|
||||
|
||||
# Now, let's insert an OfficialPackage that doesn't exist,
|
||||
# then exercise the old provider deletion path.
|
||||
with db.begin():
|
||||
db.create(OfficialProvider, Name="fake package",
|
||||
Repo="test", Provides="package")
|
||||
|
||||
# Run aurblup again.
|
||||
aurblup.main()
|
||||
|
||||
# Expect that the fake package got deleted because it's
|
||||
# not in alpm_db anymore.
|
||||
providers = db.query(OfficialProvider).filter(
|
||||
OfficialProvider.Name == "fake package").all()
|
||||
assert len(providers) == 0
|
Loading…
Add table
Add a link
Reference in a new issue