diff --git a/backend/src/mirrors_qa_backend/db/__init__.py b/backend/src/mirrors_qa_backend/db/__init__.py index 688f3ae..e84bfec 100644 --- a/backend/src/mirrors_qa_backend/db/__init__.py +++ b/backend/src/mirrors_qa_backend/db/__init__.py @@ -45,12 +45,12 @@ def initialize_mirrors() -> None: if nb_mirrors == 0: logger.info("No mirrors exist in database.") if not current_mirrors: - logger.info(f"No mirrors were found on {Settings.MIRRORS_URL!r}") + logger.info(f"No mirrors were found on {Settings.MIRRORS_URL}") return result = create_or_update_mirror_status(session, current_mirrors) logger.info( f"Registered {result.nb_mirrors_added} mirrors " - f"from {Settings.MIRRORS_URL!r}" + f"from {Settings.MIRRORS_URL}" ) else: logger.info(f"Found {nb_mirrors} mirrors in database.") diff --git a/backend/src/mirrors_qa_backend/db/mirrors.py b/backend/src/mirrors_qa_backend/db/mirrors.py index c38e2c3..904672d 100644 --- a/backend/src/mirrors_qa_backend/db/mirrors.py +++ b/backend/src/mirrors_qa_backend/db/mirrors.py @@ -50,7 +50,7 @@ def create_mirrors(session: OrmSession, mirrors: list[schemas.Mirror]) -> int: db_mirror.country = country session.add(db_mirror) logger.debug( - f"Registered new mirror: {db_mirror.id!r} for country: {country.name!r}" + f"Registered new mirror: {db_mirror.id} for country: {country.name}" ) nb_created += 1 return nb_created @@ -96,16 +96,16 @@ def create_or_update_mirror_status( for db_mirror_id, db_mirror in db_mirrors.items(): if db_mirror_id not in current_mirrors: logger.debug( - f"Disabling mirror: {db_mirror.id!r} for " - f"country: {db_mirror.country.name!r}" + f"Disabling mirror: {db_mirror.id} for " + f"country: {db_mirror.country.name}" ) db_mirror.enabled = False session.add(db_mirror) result.nb_mirrors_disabled += 1 elif not db_mirror.enabled: # re-enable mirror if it was disabled logger.debug( - f"Re-enabling mirror: {db_mirror.id!r} for " - f"country: {db_mirror.country.name!r}" + f"Re-enabling mirror: {db_mirror.id} for " + f"country: {db_mirror.country.name}" ) db_mirror.enabled = True session.add(db_mirror) diff --git a/backend/src/mirrors_qa_backend/db/worker.py b/backend/src/mirrors_qa_backend/db/worker.py index acc0f37..6c88425 100644 --- a/backend/src/mirrors_qa_backend/db/worker.py +++ b/backend/src/mirrors_qa_backend/db/worker.py @@ -28,9 +28,7 @@ def create_worker( ) -> Worker: """Creates a worker using RSA private key.""" if get_worker(session, worker_id) is not None: - raise DuplicatePrimaryKeyError( - f"A worker with id {worker_id!r} already exists." - ) + raise DuplicatePrimaryKeyError(f"A worker with id {worker_id} already exists.") try: private_key = load_private_key_from_path(private_key_fpath) except Exception as exc: diff --git a/backend/src/mirrors_qa_backend/extract.py b/backend/src/mirrors_qa_backend/extract.py index f5ab4bf..ee8dc63 100644 --- a/backend/src/mirrors_qa_backend/extract.py +++ b/backend/src/mirrors_qa_backend/extract.py @@ -42,7 +42,7 @@ def is_country_row(tag: Tag) -> bool: if body is None or isinstance(body, NavigableString | int): raise MirrorsExtractError( - f"unable to parse mirrors information from {Settings.MIRRORS_URL!r}" + f"unable to parse mirrors information from {Settings.MIRRORS_URL}" ) mirrors: list[schemas.Mirror] = [] @@ -58,7 +58,7 @@ def is_country_row(tag: Tag) -> bool: try: country: Any = pycountry.countries.search_fuzzy(country_name)[0] except LookupError: - logger.error(f"Could not get information for country: {country_name!r}") + logger.error(f"Could not get information for country: {country_name}") continue else: mirrors.append( diff --git a/backend/src/mirrors_qa_backend/scheduler.py b/backend/src/mirrors_qa_backend/scheduler.py index bc741a7..da008bf 100644 --- a/backend/src/mirrors_qa_backend/scheduler.py +++ b/backend/src/mirrors_qa_backend/scheduler.py @@ -21,7 +21,7 @@ def main(): logger.info( f"Expired test {expired_test.id}, " f"country: {expired_test.country_code}, " - f"worker: {expired_test.worker_id!r}" + f"worker: {expired_test.worker_id}" ) idle_workers = get_idle_workers( @@ -35,7 +35,7 @@ def main(): for idle_worker in idle_workers: if not idle_worker.countries: logger.info( - f"No countries registered for idle worker {idle_worker.id!r}" + f"No countries registered for idle worker {idle_worker.id}" ) continue for country in idle_worker.countries: @@ -53,7 +53,7 @@ def main(): if pending_tests.nb_tests: logger.info( "Skipping creation of new test entries for " - f"{idle_worker.id!r} as {pending_tests.nb_tests} " + f"{idle_worker.id} as {pending_tests.nb_tests} " f"tests are still pending for country {country.name}" ) continue diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index d9d2296..2ca6a5d 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -109,7 +109,7 @@ def public_key(private_key: RSAPrivateKey) -> RSAPublicKey: @pytest.fixture(scope="session") -def private_key_bytes(private_key: RSAPrivateKey) -> bytes: +def private_key_data(private_key: RSAPrivateKey) -> bytes: return private_key.private_bytes( encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.PKCS8, diff --git a/backend/tests/db/test_worker.py b/backend/tests/db/test_worker.py index 6fe99b7..19f5e18 100644 --- a/backend/tests/db/test_worker.py +++ b/backend/tests/db/test_worker.py @@ -6,7 +6,7 @@ from mirrors_qa_backend.db.worker import create_worker -def test_create_worker(dbsession: OrmSession, tmp_path: Path, private_key_bytes: bytes): +def test_create_worker(dbsession: OrmSession, tmp_path: Path, private_key_data: bytes): worker_id = "test" countries = [ Country(code="ng", name="Nigeria"), @@ -15,8 +15,7 @@ def test_create_worker(dbsession: OrmSession, tmp_path: Path, private_key_bytes: dbsession.add_all(countries) private_key_fpath = tmp_path / "key.pem" - with private_key_fpath.open("wb") as key_file: - key_file.write(private_key_bytes) + private_key_fpath.write_bytes(private_key_data) new_worker = create_worker( dbsession,