[dataimport] Prefer now(pytz.utc) to utcnow
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 21 Jun 2016 16:37:17 +0200
changeset 11308 df75fe529ba8
parent 11307 74f5814ecdf0
child 11309 31bf3254be69
[dataimport] Prefer now(pytz.utc) to utcnow
cubicweb/dataimport/massive_store.py
cubicweb/dataimport/stores.py
cubicweb/dataimport/test/test_stores.py
--- a/cubicweb/dataimport/massive_store.py	Fri Jan 29 15:08:13 2016 +0100
+++ b/cubicweb/dataimport/massive_store.py	Tue Jun 21 16:37:17 2016 +0200
@@ -24,6 +24,8 @@
 
 from six.moves import range
 
+import pytz
+
 from yams.constraints import SizeConstraint
 
 from psycopg2 import ProgrammingError
@@ -119,7 +121,7 @@
         self._dbh = PGHelper(self._cnx, pg_schema)
         self._data_entities = defaultdict(list)
         self._data_relations = defaultdict(list)
-        self._now = datetime.utcnow()
+        self._now = datetime.now(pytz.utc)
         self._default_cwuri = make_uid('_auto_generated')
         self._count_cwuri = 0
         self.on_commit_callback = on_commit_callback
--- a/cubicweb/dataimport/stores.py	Fri Jan 29 15:08:13 2016 +0100
+++ b/cubicweb/dataimport/stores.py	Tue Jun 21 16:37:17 2016 +0200
@@ -63,6 +63,8 @@
 
 from six import text_type
 
+import pytz
+
 from logilab.common.deprecation import deprecated
 from logilab.common.decorators import cached
 
@@ -262,7 +264,7 @@
         if source is None:
             source = cnx.repo.system_source
         self.source = source
-        self._now = datetime.utcnow()
+        self._now = datetime.now(pytz.utc)
         # attributes/relations shared by all entities of the same type
         self.etype_attrs = []
         self.etype_rels = []
--- a/cubicweb/dataimport/test/test_stores.py	Fri Jan 29 15:08:13 2016 +0100
+++ b/cubicweb/dataimport/test/test_stores.py	Tue Jun 21 16:37:17 2016 +0200
@@ -19,6 +19,8 @@
 
 import datetime as DT
 
+import pytz
+
 from cubicweb.dataimport import stores
 from cubicweb.devtools.testlib import CubicWebTC
 
@@ -80,7 +82,7 @@
             metagen = stores.MetaGenerator(cnx)
             # hijack gen_modification_date to ensure we don't go through it
             metagen.gen_modification_date = None
-            md = DT.datetime.utcnow() - DT.timedelta(days=1)
+            md = DT.datetime.now(pytz.utc) - DT.timedelta(days=1)
             entity, rels = metagen.base_etype_dicts('CWUser')
             entity.cw_edited.update(dict(modification_date=md))
             with cnx.ensure_cnx_set: