Skip to content

Commit

Permalink
fixed testing to work with new date system #19
Browse files Browse the repository at this point in the history
  • Loading branch information
zachale committed Aug 9, 2024
1 parent f32c5fd commit ba43b2b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
5 changes: 5 additions & 0 deletions imaginate_api/schemas/date_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from enum import Enum

class DateInfo(Enum):
START_DATE = 1722484800 # timestamp for august 1st, 2024
SECONDS_PER_DAY = 86400
7 changes: 3 additions & 4 deletions imaginate_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
from werkzeug.datastructures import FileStorage
from io import BytesIO
from urllib.parse import urlparse
from imaginate_api.schemas.date_info import DateInfo

START_DATE = 1722484800 # timestamp for august 1st, 2024
SECONDS_PER_DAY = 86400


# Helper function to get boolean
Expand Down Expand Up @@ -103,6 +102,6 @@ def build_image_from_url(url):
)
# helper function that returns a timestamp date object
def calculate_date(day: int):
if day > START_DATE:
if day > DateInfo.START_DATE.value:
return day
return START_DATE + day * SECONDS_PER_DAY
return DateInfo.START_DATE.value + day * DateInfo.SECONDS_PER_DAY.value
16 changes: 15 additions & 1 deletion tests/unit/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ def test_build_result():
pass


@pytest.mark.parametrize(
"data, expected",
[
(0, 1722484800),
(3, 1722744000),
(1722684800, 1722684800)
],
)
def test_calculate_date(data, expected):
assert calculate_date(data) == expected



# Not testing as this endpoint will likely be removed in future
def test_get_root_endpoint():
pass
Expand All @@ -157,7 +170,7 @@ def test_post_image_create_endpoint_success(client, mock_data):
assert res.json == build_result(
res.json["url"].split("/")[-1],
entry["real"],
entry["date"],
calculate_date(entry["date"]),
entry["theme"],
entry["status"],
entry["filename"],
Expand Down Expand Up @@ -237,6 +250,7 @@ def test_get_image_read_properties_endpoint(mock_fs, mock_data, client):

def test_get_date_images_endpoint_success(mock_fs, mock_data, client):
for entry in mock_data:
entry['date'] = calculate_date(entry['date'])
_id = mock_fs.put(**entry)
res = client.get(f"/date/{entry['date']}/images")
assert res.status_code == HTTPStatus.OK
Expand Down

0 comments on commit ba43b2b

Please sign in to comment.