mirror of
https://github.com/sartography/uva-covid19-testing-communicator.git
synced 2025-02-24 04:48:05 +00:00
Dates, when read in from IVY are coming across as EST, and they must be ingested as such.
This commit is contained in:
parent
6a43e6f5eb
commit
4c4ecfe245
@ -3,6 +3,7 @@ from datetime import datetime
|
|||||||
from parser import ParserError
|
from parser import ParserError
|
||||||
|
|
||||||
import globus_sdk
|
import globus_sdk
|
||||||
|
import pytz
|
||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
from dateutil import parser
|
from dateutil import parser
|
||||||
|
|
||||||
@ -70,6 +71,8 @@ class IvyService(object):
|
|||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
sample.date = parser.parse(dictionary["Test Date Time"])
|
sample.date = parser.parse(dictionary["Test Date Time"])
|
||||||
|
tz = pytz.timezone("America/New_York")
|
||||||
|
sample.date = tz.localize(sample.date)
|
||||||
except Exception as pe:
|
except Exception as pe:
|
||||||
sentry_sdk.capture_message(f"Failed to parse date for barcode '{dictionary['Test Bar Code']}', '{pe}'")
|
sentry_sdk.capture_message(f"Failed to parse date for barcode '{dictionary['Test Bar Code']}', '{pe}'")
|
||||||
sample.date = datetime.now()
|
sample.date = datetime.now()
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
import datetime
|
||||||
|
|
||||||
|
import pytz
|
||||||
|
|
||||||
from tests.base_test import BaseTest
|
from tests.base_test import BaseTest
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
@ -31,6 +35,22 @@ class IvyServiceTest(BaseTest):
|
|||||||
self.assertEquals(4, len(records))
|
self.assertEquals(4, len(records))
|
||||||
self.assertEquals('987655321-TN-20212719-4321', records[2].barcode)
|
self.assertEquals('987655321-TN-20212719-4321', records[2].barcode)
|
||||||
|
|
||||||
|
def test_timezone_offset(self):
|
||||||
|
"""The date and time returned from the lab / Globus is in EST, be sure to save it as such to
|
||||||
|
avoid a 5 hour offset, when it is assumed to be in GMT."""
|
||||||
|
records = IvyService.samples_from_ivy_file(self.ivy_file)
|
||||||
|
self.assertEqual("987654321", records[0].student_id)
|
||||||
|
self.assertIsNotNone(records[0].date.tzinfo, "on ingestion, the date should be in EST")
|
||||||
|
|
||||||
|
# original date "202009030809"
|
||||||
|
date_string = '202009031209' # UTC is 4 hours head for this date
|
||||||
|
date = datetime.datetime.strptime(date_string, '%Y%m%d%H%M')
|
||||||
|
|
||||||
|
db.session.add(records[0])
|
||||||
|
db.session.commit()
|
||||||
|
self.assertEqual(date, records[0].date)
|
||||||
|
|
||||||
|
|
||||||
def test_load_directory(self):
|
def test_load_directory(self):
|
||||||
self.assertEqual(0, db.session.query(IvyFile).count())
|
self.assertEqual(0, db.session.query(IvyFile).count())
|
||||||
app.config['IVY_IMPORT_DIR'] = os.path.join(app.root_path, '..', 'tests', 'data', 'import_directory')
|
app.config['IVY_IMPORT_DIR'] = os.path.join(app.root_path, '..', 'tests', 'data', 'import_directory')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user