mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-02 16:45:51 +00:00
Compare commits
4 Commits
09350e88ab
...
8d0d597473
Author | SHA1 | Date | |
---|---|---|---|
8d0d597473 | |||
995b396360 | |||
7f813cf0c3 | |||
d4eb55ef95 |
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
pkgbase='ahriman'
|
pkgbase='ahriman'
|
||||||
pkgname=('ahriman' 'ahriman-core' 'ahriman-triggers' 'ahriman-web')
|
pkgname=('ahriman' 'ahriman-core' 'ahriman-triggers' 'ahriman-web')
|
||||||
pkgver=2.18.0
|
pkgver=2.18.2
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc="ArcH linux ReposItory MANager"
|
pkgdesc="ArcH linux ReposItory MANager"
|
||||||
arch=('any')
|
arch=('any')
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
.TH AHRIMAN "1" "2025\-06\-13" "ahriman" "Generated Python Manual"
|
.TH AHRIMAN "1" "2025\-06\-16" "ahriman" "Generated Python Manual"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
ahriman
|
ahriman
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
|
@ -17,4 +17,4 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
__version__ = "2.18.0"
|
__version__ = "2.18.2"
|
||||||
|
@ -153,10 +153,13 @@ class LogsOperations(Operations):
|
|||||||
"""
|
"""
|
||||||
delete from logs
|
delete from logs
|
||||||
where (package_base, repository, process_id) in (
|
where (package_base, repository, process_id) in (
|
||||||
select package_base, repository, process_id from logs
|
select package_base, repository, process_id from (
|
||||||
where repository = :repository
|
select package_base, repository, process_id, row_number() over (partition by package_base order by max(created) desc) as rn
|
||||||
group by package_base, repository, process_id
|
from logs
|
||||||
order by min(created) desc limit -1 offset :offset
|
where repository = :repository
|
||||||
|
group by package_base, repository, process_id
|
||||||
|
)
|
||||||
|
where rn > :offset
|
||||||
)
|
)
|
||||||
""",
|
""",
|
||||||
{
|
{
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
import contextlib
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
@ -87,10 +88,12 @@ class Operations(LazyLogging):
|
|||||||
Returns:
|
Returns:
|
||||||
T: result of the ``query`` call
|
T: result of the ``query`` call
|
||||||
"""
|
"""
|
||||||
with sqlite3.connect(self.path, detect_types=sqlite3.PARSE_DECLTYPES) as connection:
|
with contextlib.closing(sqlite3.connect(self.path, detect_types=sqlite3.PARSE_DECLTYPES)) as connection:
|
||||||
connection.set_trace_callback(self.logger.debug)
|
connection.set_trace_callback(self.logger.debug)
|
||||||
connection.row_factory = self.factory
|
connection.row_factory = self.factory
|
||||||
|
|
||||||
result = query(connection)
|
result = query(connection)
|
||||||
if commit:
|
if commit:
|
||||||
connection.commit()
|
connection.commit()
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -93,6 +93,27 @@ def test_logs_insert_get_multi(database: SQLite, package_ahriman: Package) -> No
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_logs_rotate_remove_older(database: SQLite, package_ahriman: Package,
|
||||||
|
package_python_schedule: Package) -> None:
|
||||||
|
"""
|
||||||
|
must correctly remove old records
|
||||||
|
"""
|
||||||
|
database.logs_insert(LogRecord(LogRecordId(package_ahriman.base, "1", "p1"), 42.0, "message 1"))
|
||||||
|
database.logs_insert(LogRecord(LogRecordId(package_ahriman.base, "1", "p1"), 43.0, "message 2"))
|
||||||
|
database.logs_insert(LogRecord(LogRecordId(package_ahriman.base, "2", "p2"), 44.0, "message 3"))
|
||||||
|
database.logs_insert(LogRecord(LogRecordId(package_ahriman.base, "2", "p2"), 45.0, "message 4"))
|
||||||
|
database.logs_insert(LogRecord(LogRecordId(package_python_schedule.base, "3", "p1"), 40.0, "message 5"))
|
||||||
|
|
||||||
|
database.logs_rotate(1)
|
||||||
|
assert database.logs_get(package_ahriman.base) == [
|
||||||
|
LogRecord(LogRecordId(package_ahriman.base, "2", "p2"), 44.0, "message 3"),
|
||||||
|
LogRecord(LogRecordId(package_ahriman.base, "2", "p2"), 45.0, "message 4"),
|
||||||
|
]
|
||||||
|
assert database.logs_get(package_python_schedule.base) == [
|
||||||
|
LogRecord(LogRecordId(package_python_schedule.base, "3", "p1"), 40.0, "message 5"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_logs_rotate_remove_all(database: SQLite, package_ahriman: Package) -> None:
|
def test_logs_rotate_remove_all(database: SQLite, package_ahriman: Package) -> None:
|
||||||
"""
|
"""
|
||||||
must remove all records when rotating with keep_last_records is 0
|
must remove all records when rotating with keep_last_records is 0
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import pytest
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
from pytest_mock import MockerFixture
|
from pytest_mock import MockerFixture
|
||||||
@ -24,15 +25,29 @@ def test_factory(database: SQLite) -> None:
|
|||||||
|
|
||||||
def test_with_connection(database: SQLite, mocker: MockerFixture) -> None:
|
def test_with_connection(database: SQLite, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must run query inside connection
|
must run query inside connection and close it at the end
|
||||||
"""
|
"""
|
||||||
connection_mock = MagicMock()
|
connection_mock = MagicMock()
|
||||||
connect_mock = mocker.patch("sqlite3.connect", return_value=connection_mock)
|
connect_mock = mocker.patch("sqlite3.connect", return_value=connection_mock)
|
||||||
|
|
||||||
database.with_connection(lambda conn: conn.execute("select 1"))
|
database.with_connection(lambda conn: conn.execute("select 1"))
|
||||||
connect_mock.assert_called_once_with(database.path, detect_types=sqlite3.PARSE_DECLTYPES)
|
connect_mock.assert_called_once_with(database.path, detect_types=sqlite3.PARSE_DECLTYPES)
|
||||||
connection_mock.__enter__().set_trace_callback.assert_called_once_with(database.logger.debug)
|
connection_mock.set_trace_callback.assert_called_once_with(database.logger.debug)
|
||||||
connection_mock.__enter__().commit.assert_not_called()
|
connection_mock.commit.assert_not_called()
|
||||||
|
connection_mock.close.assert_called_once_with()
|
||||||
|
|
||||||
|
|
||||||
|
def test_with_connection_close(database: SQLite, mocker: MockerFixture) -> None:
|
||||||
|
"""
|
||||||
|
must close connection on errors
|
||||||
|
"""
|
||||||
|
connection_mock = MagicMock()
|
||||||
|
connection_mock.commit.side_effect = Exception
|
||||||
|
mocker.patch("sqlite3.connect", return_value=connection_mock)
|
||||||
|
|
||||||
|
with pytest.raises(Exception):
|
||||||
|
database.with_connection(lambda conn: conn.execute("select 1"), commit=True)
|
||||||
|
connection_mock.close.assert_called_once_with()
|
||||||
|
|
||||||
|
|
||||||
def test_with_connection_with_commit(database: SQLite, mocker: MockerFixture) -> None:
|
def test_with_connection_with_commit(database: SQLite, mocker: MockerFixture) -> None:
|
||||||
@ -44,4 +59,4 @@ def test_with_connection_with_commit(database: SQLite, mocker: MockerFixture) ->
|
|||||||
mocker.patch("sqlite3.connect", return_value=connection_mock)
|
mocker.patch("sqlite3.connect", return_value=connection_mock)
|
||||||
|
|
||||||
database.with_connection(lambda conn: conn.execute("select 1"), commit=True)
|
database.with_connection(lambda conn: conn.execute("select 1"), commit=True)
|
||||||
connection_mock.__enter__().commit.assert_called_once_with()
|
connection_mock.commit.assert_called_once_with()
|
||||||
|
Reference in New Issue
Block a user