15.2.454. camcops_server.tasks.tests.core10_tests¶
camcops_server/tasks/tests/core10_tests.py
Copyright (C) 2012, University of Cambridge, Department of Psychiatry. Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
This file is part of CamCOPS.
CamCOPS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
CamCOPS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
- class camcops_server.tasks.tests.core10_tests.Core10ReportDateRangeTests(methodName='runTest')[source]¶
Test code:
-- 2019-10-21 -- For SQLite: CREATE TABLE core10 (_pk INT, patient_id INT, when_created DATETIME, _current INT); .schema core10 INSERT INTO core10 (_pk,patient_id,when_created,_current) VALUES (1,1,'2018-06-01T00:00:00.000000+00:00',1), (2,1,'2018-08-01T00:00:00.000000+00:00',1), (3,1,'2018-10-01T00:00:00.000000+00:00',1), (4,2,'2018-06-01T00:00:00.000000+00:00',1), (5,2,'2018-08-01T00:00:00.000000+00:00',1), (6,2,'2018-10-01T00:00:00.000000+00:00',1), (7,3,'2018-06-01T00:00:00.000000+00:00',1), (8,3,'2018-08-01T00:00:00.000000+00:00',1), (9,3,'2018-10-01T00:00:00.000000+00:00',1); SELECT * from core10; SELECT STRFTIME('%Y-%m-%d %H:%M:%f', core10.when_created) from core10; -- ... gives e.g. -- 2018-06-01 00:00:00.000 SELECT * FROM core10 WHERE core10._current = 1 AND STRFTIME('%Y-%m-%d %H:%M:%f', core10.when_created) >= '2018-06-01 00:00:00.000000' AND STRFTIME('%Y-%m-%d %H:%M:%f', core10.when_created) < '2018-09-01 00:00:00.000000'; -- That fails. Either our date/time comparison code is wrong for SQLite, or -- we are inserting text in the wrong format. -- Ah. It's the number of decimal places: SELECT '2018-06-01 00:00:00.000' >= '2018-06-01 00:00:00.000000'; -- 0, false SELECT '2018-06-01 00:00:00.000' >= '2018-06-01 00:00:00.000'; -- 1, true
See
camcops_server.cc_modules.cc_sqla_coltypes.isotzdatetime_to_utcdatetime_sqlite()
.
- class camcops_server.tasks.tests.core10_tests.Core10ReportDoubleCountingTests(methodName='runTest')[source]¶