Skip to content

Commit

Permalink
Merge pull request #213 from SmartAPI/fix-updated-date
Browse files Browse the repository at this point in the history
Fix last_updated date issue#167
  • Loading branch information
newgene authored Feb 9, 2024
2 parents 728a42e + ec8525f commit 814fc65
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/controller/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,4 @@ def update(self, content):
self._status = self.STATUS.NOT_MODIFIED.value
else: # raw field changed
self._status = self.STATUS.UPDATED.value
self._entity.raw = content.raw
self._entity.raw = content.raw
18 changes: 17 additions & 1 deletion src/tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
import os
import time
from datetime import datetime, timezone
from datetime import datetime, timedelta, timezone

import elasticsearch
import pytest
Expand Down Expand Up @@ -380,6 +380,10 @@ def test_refresh_status():
assert mygene.webdoc.timestamp > datetime(2020, 1, 1)
_ts0 = mygene.webdoc.timestamp

original_last_updated = mygene.last_updated.replace(microsecond=0, tzinfo=None)
one_hour_before = (datetime.now() - timedelta(hours=1)).replace(microsecond=0)
assert original_last_updated > one_hour_before

mygene.save()
refresh()

Expand All @@ -393,9 +397,15 @@ def test_refresh_status():
assert "components" in mygene
assert mygene.webdoc.timestamp > _ts0

current_last_updated = mygene.last_updated.replace(microsecond=0, tzinfo=None)
assert current_last_updated == original_last_updated

mygene.save()
refresh()

# confirm last_updated is not changed after refresh
assert mygene.last_updated.replace(microsecond=0, tzinfo=None) == current_last_updated

mygene_doc = SmartAPIDoc.get(MYGENE_ID)
assert mygene_doc._status.refresh_status == 200
assert "components" in mygene_doc
Expand All @@ -408,6 +418,9 @@ def test_refresh_status():
mygene.save()
refresh()

# confirm last_updated is not changed after refresh
assert mygene.last_updated.replace(microsecond=0, tzinfo=None) == current_last_updated

mygene_doc = SmartAPIDoc.get(MYGENE_ID)
assert mygene_doc._status.refresh_status == 404
assert "components" in mygene_doc
Expand All @@ -432,6 +445,9 @@ def test_refresh_status():
mygene.save()
refresh()

# confirm last_updated is not changed after refresh
assert mygene.last_updated.replace(microsecond=0, tzinfo=None) == current_last_updated

mygene_doc = SmartAPIDoc.get(MYGENE_ID)
assert mygene_doc._status.refresh_status == 499
assert "components" in mygene_doc
Expand Down

0 comments on commit 814fc65

Please sign in to comment.