mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-24 12:13:33 +08:00
added more ISO8601 tests and removed manual parsing procedure
This commit is contained in:
@@ -787,17 +787,15 @@ class HistoriesContentsService(ServiceBase):
|
||||
# while polling, check to see if the history has changed
|
||||
# if it hasn't then we can short-circuit the poll request
|
||||
if since:
|
||||
# sqlalchemy DateTime columns are not timezone aware, so parse `since` into timezone-aware
|
||||
# datetime and then convert to naive datetime object representing UTC,
|
||||
# assuming history.update_time represents UTC time.
|
||||
# this is the right format, but changes the date itself resulting in logical errors
|
||||
# sqlalchemy DateTime columns are not timezone aware, but `since` may be a timezone aware
|
||||
# DateTime object if a timezone offset is provided (https://github.com/samuelcolvin/pydantic/blob/5ccbdcb5904f35834300b01432a665c75dc02296/pydantic/datetime_parse.py#L179).
|
||||
# To avoid having to manually process every IS08601 date format, simply convert
|
||||
# history.update_time to UTC/timezone aware before performing the inequality
|
||||
|
||||
# Although this creates a date with the right format for SQLAlchemy, it changes the date
|
||||
# data resulting in logical errors during testing. I fed back the history.update_time
|
||||
# into this conversion and it fails the inequality
|
||||
# since_date = since.astimezone(datetime.timezone.utc).replace(tzinfo=None)
|
||||
since = since if since.tzinfo is not None else since.replace(tzinfo=datetime.timezone.utc)
|
||||
history_update_time_tz = history.update_time.replace(tzinfo=datetime.timezone.utc)
|
||||
|
||||
if history.update_time <= since:
|
||||
if history_update_time_tz <= since:
|
||||
trans.response.status = 204
|
||||
return
|
||||
|
||||
@@ -1775,10 +1773,13 @@ class HistoryContentsController(BaseGalaxyAPIController, UsesLibraryMixinItems,
|
||||
* GET /api/histories/{history_id}/contents/near/{hid}/{limit}
|
||||
"""
|
||||
serialization_params = parse_serialization_params(default_view='betawebclient', **kwd)
|
||||
since = kwd.pop('since', None)
|
||||
if since:
|
||||
since = since.replace("Z", "")
|
||||
since = dateutil.parser.isoparse(since)
|
||||
|
||||
since_str = kwd.pop('since', None)
|
||||
if since_str:
|
||||
since = dateutil.parser.isoparse(since_str)
|
||||
else:
|
||||
since = None
|
||||
|
||||
filter_params = self._parse_rest_params(kwd)
|
||||
hid = int(hid)
|
||||
limit = int(limit)
|
||||
|
||||
@@ -639,16 +639,18 @@ class HistoryContentsApiTestCase(ApiTestCase):
|
||||
# this is the standard date format that javascript will emit using .toISOString(), it
|
||||
# should be the expected date format for any modern api
|
||||
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
|
||||
|
||||
# checking to make sure that the same exact history.update_time returns a "not changed"
|
||||
# result after date parsing
|
||||
valid_iso8601_date = original_history_stamp + 'Z'
|
||||
history_contents = self._get(f"/api/histories/{history_id}/contents/near/100/100?since={valid_iso8601_date}")
|
||||
status = history_contents.status_code
|
||||
assert status == 204
|
||||
assert history_contents.status_code == 204
|
||||
|
||||
# Javascript has less date precision than python, here's a common sample
|
||||
javascript_iso_date = '2021-08-25T21:46:49.091Z'
|
||||
history_contents = self._get(f"/api/histories/{history_id}/contents/near/100/100?since={javascript_iso_date}")
|
||||
status = history_contents.status_code
|
||||
assert status == 204 or status == 200
|
||||
# test parsing for other standard is08601 formats
|
||||
sample_formats = ['2021-08-26T15:53:02+00:00', '2021-08-26T15:53:02Z', '20210826T155302Z']
|
||||
for date_str in sample_formats:
|
||||
history_contents = self._get(f"/api/histories/{history_id}/contents/near/100/100?since={date_str}")
|
||||
assert history_contents.status_code != 400
|
||||
|
||||
@skip_without_tool('cat_data_and_sleep')
|
||||
def test_history_contents_near_with_update_time_implicit_collection(self):
|
||||
|
||||
Reference in New Issue
Block a user