Changeset View
Changeset View
Standalone View
Standalone View
swh/scrubber/tests/test_cli.py
Show All 19 Lines | def invoke( | ||||
storage=None, | storage=None, | ||||
kafka_server=None, | kafka_server=None, | ||||
kafka_prefix=None, | kafka_prefix=None, | ||||
kafka_consumer_group=None, | kafka_consumer_group=None, | ||||
): | ): | ||||
runner = CliRunner() | runner = CliRunner() | ||||
config = { | config = { | ||||
"scrubber_db": {"cls": "local", "db": scrubber_db.conn.dsn}, | "scrubber_db": {"cls": "postgresql", "db": scrubber_db.conn.dsn}, | ||||
"graph": {"url": "http://graph.example.org:5009/"}, | "graph": {"url": "http://graph.example.org:5009/"}, | ||||
} | } | ||||
if storage: | if storage: | ||||
with storage_db(storage) as db: | with storage_db(storage) as db: | ||||
config["storage"] = { | config["storage"] = { | ||||
"cls": "postgresql", | "cls": "postgresql", | ||||
"db": db.conn.dsn, | "db": db.conn.dsn, | ||||
"objstorage": {"cls": "memory"}, | "objstorage": {"cls": "memory"}, | ||||
Show All 30 Lines | get_scrubber_db = mocker.patch( | ||||
"swh.scrubber.get_scrubber_db", return_value=scrubber_db | "swh.scrubber.get_scrubber_db", return_value=scrubber_db | ||||
) | ) | ||||
result = invoke( | result = invoke( | ||||
scrubber_db, ["check", "storage", "--object-type=snapshot"], storage=swh_storage | scrubber_db, ["check", "storage", "--object-type=snapshot"], storage=swh_storage | ||||
) | ) | ||||
assert result.exit_code == 0, result.output | assert result.exit_code == 0, result.output | ||||
assert result.output == "" | assert result.output == "" | ||||
get_scrubber_db.assert_called_once_with(cls="local", db=scrubber_db.conn.dsn) | get_scrubber_db.assert_called_once_with(cls="postgresql", db=scrubber_db.conn.dsn) | ||||
StorageChecker.assert_called_once_with( | StorageChecker.assert_called_once_with( | ||||
db=scrubber_db, | db=scrubber_db, | ||||
storage=StorageChecker.mock_calls[0][2]["storage"], | storage=StorageChecker.mock_calls[0][2]["storage"], | ||||
object_type="snapshot", | object_type="snapshot", | ||||
start_object="0" * 40, | start_object="0" * 40, | ||||
end_object="f" * 40, | end_object="f" * 40, | ||||
) | ) | ||||
assert storage_checker.method_calls == [call.run()] | assert storage_checker.method_calls == [call.run()] | ||||
Show All 14 Lines | result = invoke( | ||||
["check", "journal"], | ["check", "journal"], | ||||
kafka_server=kafka_server, | kafka_server=kafka_server, | ||||
kafka_prefix=kafka_prefix, | kafka_prefix=kafka_prefix, | ||||
kafka_consumer_group=kafka_consumer_group, | kafka_consumer_group=kafka_consumer_group, | ||||
) | ) | ||||
assert result.exit_code == 0, result.output | assert result.exit_code == 0, result.output | ||||
assert result.output == "" | assert result.output == "" | ||||
get_scrubber_db.assert_called_once_with(cls="local", db=scrubber_db.conn.dsn) | get_scrubber_db.assert_called_once_with(cls="postgresql", db=scrubber_db.conn.dsn) | ||||
JournalChecker.assert_called_once_with( | JournalChecker.assert_called_once_with( | ||||
db=scrubber_db, | db=scrubber_db, | ||||
journal_client={ | journal_client={ | ||||
"brokers": kafka_server, | "brokers": kafka_server, | ||||
"cls": "kafka", | "cls": "kafka", | ||||
"group_id": kafka_consumer_group, | "group_id": kafka_consumer_group, | ||||
"prefix": kafka_prefix, | "prefix": kafka_prefix, | ||||
"stop_on_eof": True, | "stop_on_eof": True, | ||||
Show All 9 Lines | def test_locate_origins(mocker, scrubber_db, swh_storage): | ||||
) | ) | ||||
get_scrubber_db = mocker.patch( | get_scrubber_db = mocker.patch( | ||||
"swh.scrubber.get_scrubber_db", return_value=scrubber_db | "swh.scrubber.get_scrubber_db", return_value=scrubber_db | ||||
) | ) | ||||
result = invoke(scrubber_db, ["locate"], storage=swh_storage) | result = invoke(scrubber_db, ["locate"], storage=swh_storage) | ||||
assert result.exit_code == 0, result.output | assert result.exit_code == 0, result.output | ||||
assert result.output == "" | assert result.output == "" | ||||
get_scrubber_db.assert_called_once_with(cls="local", db=scrubber_db.conn.dsn) | get_scrubber_db.assert_called_once_with(cls="postgresql", db=scrubber_db.conn.dsn) | ||||
OriginLocator.assert_called_once_with( | OriginLocator.assert_called_once_with( | ||||
db=scrubber_db, | db=scrubber_db, | ||||
storage=OriginLocator.mock_calls[0][2]["storage"], | storage=OriginLocator.mock_calls[0][2]["storage"], | ||||
graph=OriginLocator.mock_calls[0][2]["graph"], | graph=OriginLocator.mock_calls[0][2]["graph"], | ||||
start_object=CoreSWHID.from_string("swh:1:cnt:" + "00" * 20), | start_object=CoreSWHID.from_string("swh:1:cnt:" + "00" * 20), | ||||
end_object=CoreSWHID.from_string("swh:1:snp:" + "ff" * 20), | end_object=CoreSWHID.from_string("swh:1:snp:" + "ff" * 20), | ||||
) | ) | ||||
assert origin_locator.method_calls == [call.run()] | assert origin_locator.method_calls == [call.run()] | ||||
def test_fix_objects(mocker, scrubber_db): | def test_fix_objects(mocker, scrubber_db): | ||||
fixer = MagicMock() | fixer = MagicMock() | ||||
Fixer = mocker.patch("swh.scrubber.fixer.Fixer", return_value=fixer) | Fixer = mocker.patch("swh.scrubber.fixer.Fixer", return_value=fixer) | ||||
get_scrubber_db = mocker.patch( | get_scrubber_db = mocker.patch( | ||||
"swh.scrubber.get_scrubber_db", return_value=scrubber_db | "swh.scrubber.get_scrubber_db", return_value=scrubber_db | ||||
) | ) | ||||
result = invoke(scrubber_db, ["fix"]) | result = invoke(scrubber_db, ["fix"]) | ||||
assert result.exit_code == 0, result.output | assert result.exit_code == 0, result.output | ||||
assert result.output == "" | assert result.output == "" | ||||
get_scrubber_db.assert_called_once_with(cls="local", db=scrubber_db.conn.dsn) | get_scrubber_db.assert_called_once_with(cls="postgresql", db=scrubber_db.conn.dsn) | ||||
Fixer.assert_called_once_with( | Fixer.assert_called_once_with( | ||||
db=scrubber_db, | db=scrubber_db, | ||||
start_object=CoreSWHID.from_string("swh:1:cnt:" + "00" * 20), | start_object=CoreSWHID.from_string("swh:1:cnt:" + "00" * 20), | ||||
end_object=CoreSWHID.from_string("swh:1:snp:" + "ff" * 20), | end_object=CoreSWHID.from_string("swh:1:snp:" + "ff" * 20), | ||||
) | ) | ||||
assert fixer.method_calls == [call.run()] | assert fixer.method_calls == [call.run()] |