Skip to content

Commit

Permalink
Merge pull request #54 from kuefmz/master
Browse files Browse the repository at this point in the history
Fix download endpoint and add testcases
  • Loading branch information
JJ-Author authored Aug 26, 2024
2 parents f298068 + 8c132ca commit e8ad81b
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 10 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Pylint

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- uses: Gr1N/setup-poetry@v8 #install poetry
- name: Install parts of toolchain
run: |
python -m pip install --upgrade pip
- name: Install requirements with poetry
run: poetry install
- name: Test with pytest
run: |
poetry run pytest
18 changes: 10 additions & 8 deletions archivo/querying/query_databus.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,16 @@ def find_closest_version(versions, target_file, target_version):
min_diff = float('inf')

for version_dict in versions:
if target_file in version_dict['file']['value']:
version_str = version_dict['version']['value']
version_datetime = datetime.strptime(version_str, '%Y.%m.%d-%H%M%S')
diff = abs((version_datetime - target_datetime).total_seconds())

if diff < min_diff:
min_diff = diff
closest_version = version_str
version_str = version_dict['version']['value']
version_datetime = datetime.strptime(version_str, '%Y.%m.%d-%H%M%S')
diff = abs((version_datetime - target_datetime).total_seconds())

if diff == 0.0:
return version_str

if diff <= min_diff:
min_diff = diff
closest_version = version_str

return closest_version

Expand Down
66 changes: 64 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ PyYAML = "^6.0"
pylode = "^3.0.4"
rdflib = "^6.2.0"
databusclient = "^0.12"
pytest = "^8.3.2"

[tool.poetry.group.dev.dependencies]
flake8 = "^5.0.4"
Expand Down
48 changes: 48 additions & 0 deletions tests/test_download_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import unittest
import subprocess
import time
import requests
import os
import hashlib


class TestServerResponses(unittest.TestCase):

@classmethod
def setUpClass(cls):
os.chdir("archivo")
# Start the server
cls.server_process = subprocess.Popen(["poetry", "run", "python", "archivo.py"])
# Give the server some time to start up
time.sleep(5)


@classmethod
def tearDownClass(cls):
# Shut down the server
cls.server_process.terminate()
cls.server_process.wait()


def test_response_second_url(self):
url = "http://localhost:5000/download?o=http%3A//comicmeta.org/cbo/&f=owl&v=2023.03.18-185709&vM=closest"
response = requests.get(url)

# Calculate the MD5 checksum of the content
md5_hash = hashlib.md5(response.content).hexdigest()
expected_md5 = "4176659915aaacc0b7960dd7428d5439"
self.assertEqual(md5_hash, expected_md5)


def test_response_first_url(self):
url = "http://localhost:5000/download?o=http%3A//comicmeta.org/cbo/&f=owl&v=2024.05.29-031359&vM=closest"
response = requests.get(url)

# Calculate the MD5 checksum of the content
md5_hash = hashlib.md5(response.content).hexdigest()
expected_md5 = "4196656da08e5b248dc1a9eaca3c888c"
self.assertEqual(md5_hash, expected_md5)


if __name__ == '__main__':
unittest.main()

0 comments on commit e8ad81b

Please sign in to comment.