Consider remote DB old if there is no version file yet

This commit is contained in:
Marco Castelluccio 2019-07-27 01:45:06 +02:00
Родитель 785aeca537
Коммит 3747171716
2 изменённых файлов: 14 добавлений и 2 удалений

Просмотреть файл

@ -38,6 +38,8 @@ def is_old_version(path):
r = requests.get(
urljoin(DATABASES[path]["url"], f"{os.path.basename(path)}.version")
)
if r.status_code == 404:
return True
r.raise_for_status()
prev_version = int(r.text)

Просмотреть файл

@ -252,14 +252,24 @@ def test_is_old_version(tmp_path):
db_path = tmp_path / "prova.json"
db.register(db_path, url_zst, 1, support_files=[])
responses.add(responses.GET, url_version, status=200, body="42")
assert os.path.exists(db_path.with_suffix(db_path.suffix + ".version"))
responses.add(responses.GET, url_version, status=404)
responses.add(responses.GET, url_version, status=200, body="1")
responses.add(responses.GET, url_version, status=200, body="42")
# When the remote version file doesn't exist, we consider the db as being old.
assert db.is_old_version(db_path)
# When the remote version file exists and returns the same version as the current db, we consider the remote db as not being old.
assert not db.is_old_version(db_path)
# When the remote version file exists and returns a newer version than the current db, we consider the remote db as not being old.
assert not db.is_old_version(db_path)
db.register(db_path, url_zst, 43, support_files=[])
# When the remote version file exists and returns an older version than the current db, we consider the remote db as being old.
assert db.is_old_version(db_path)