From 867c19e7b084d833b674bf52889da4030108b94f Mon Sep 17 00:00:00 2001 From: sjanssen2 Date: Wed, 19 Jun 2024 08:37:10 +0200 Subject: [PATCH 01/11] use SQL's NOW() fct to log creation of a new user account (validated or not). --- qiita_db/support_files/populate_test_db.sql | 2 +- qiita_db/support_files/qiita-db-unpatched.sql | 10 ++++- qiita_db/test/test_user.py | 38 +++++++++++++++---- qiita_db/user.py | 6 +++ qiita_pet/handlers/user_handlers.py | 8 +++- qiita_pet/templates/user_profile.html | 3 ++ 6 files changed, 56 insertions(+), 11 deletions(-) diff --git a/qiita_db/support_files/populate_test_db.sql b/qiita_db/support_files/populate_test_db.sql index 46c0aaed7..0a71959ac 100644 --- a/qiita_db/support_files/populate_test_db.sql +++ b/qiita_db/support_files/populate_test_db.sql @@ -50,7 +50,7 @@ INSERT INTO qiita.user_level VALUES (7, 'wet-lab admin', 'Can access the private -- Data for Name: qiita_user; Type: TABLE DATA; Schema: qiita; Owner: antoniog -- -INSERT INTO qiita.qiita_user VALUES ('test@foo.bar', 4, '$2a$12$gnUi8Qg.0tvW243v889BhOBhWLIHyIJjjgaG6dxuRJkUM8nXG9Efe', 'Dude', 'Nowhere University', '123 fake st, Apt 0, Faketown, CO 80302', '111-222-3344', NULL, NULL, NULL, false, '0000-0002-0975-9019', 'Rob-Knight', '_e3QL94AAAAJ'); +INSERT INTO qiita.qiita_user VALUES ('test@foo.bar', 4, '$2a$12$gnUi8Qg.0tvW243v889BhOBhWLIHyIJjjgaG6dxuRJkUM8nXG9Efe', 'Dude', 'Nowhere University', '123 fake st, Apt 0, Faketown, CO 80302', '111-222-3344', NULL, NULL, NULL, false, '0000-0002-0975-9019', 'Rob-Knight', '_e3QL94AAAAJ', '2015-12-03 13:52:42.751331-07'); INSERT INTO qiita.qiita_user VALUES ('shared@foo.bar', 4, '$2a$12$gnUi8Qg.0tvW243v889BhOBhWLIHyIJjjgaG6dxuRJkUM8nXG9Efe', 'Shared', 'Nowhere University', '123 fake st, Apt 0, Faketown, CO 80302', '111-222-3344', NULL, NULL, NULL, false); INSERT INTO qiita.qiita_user VALUES ('admin@foo.bar', 1, '$2a$12$gnUi8Qg.0tvW243v889BhOBhWLIHyIJjjgaG6dxuRJkUM8nXG9Efe', 'Admin', 'Owner University', '312 noname st, Apt K, Nonexistantown, CO 80302', '222-444-6789', NULL, NULL, NULL, false); INSERT INTO qiita.qiita_user VALUES ('demo@microbio.me', 4, '$2a$12$gnUi8Qg.0tvW243v889BhOBhWLIHyIJjjgaG6dxuRJkUM8nXG9Efe', 'Demo', 'Qiita Dev', '1345 Colorado Avenue', '303-492-1984', NULL, NULL, NULL, false); diff --git a/qiita_db/support_files/qiita-db-unpatched.sql b/qiita_db/support_files/qiita-db-unpatched.sql index a61b4645d..137e72963 100644 --- a/qiita_db/support_files/qiita-db-unpatched.sql +++ b/qiita_db/support_files/qiita-db-unpatched.sql @@ -1891,7 +1891,8 @@ CREATE TABLE qiita.qiita_user ( receive_processing_job_emails boolean DEFAULT false, social_orcid character varying DEFAULT NULL, social_researchgate character varying DEFAULT NULL, - social_googlescholar character varying DEFAULT NULL + social_googlescholar character varying DEFAULT NULL, + creation_timestamp timestamp without time zone DEFAULT NULL ); @@ -1931,6 +1932,13 @@ COMMENT ON COLUMN qiita.qiita_user.pass_reset_code IS 'Randomly generated code f COMMENT ON COLUMN qiita.qiita_user.pass_reset_timestamp IS 'Time the reset code was generated'; +-- +-- Name: COLUMN qiita_user.creation_timestamp; Type: COMMENT; Schema: qiita +-- + +COMMENT ON COLUMN qiita.qiita_user.creation_timestamp IS 'The date the user account was created'; + + -- -- Name: reference; Type: TABLE; Schema: qiita -- diff --git a/qiita_db/test/test_user.py b/qiita_db/test/test_user.py index 666746c36..f5d54ab3d 100644 --- a/qiita_db/test/test_user.py +++ b/qiita_db/test/test_user.py @@ -75,7 +75,8 @@ def setUp(self): 'receive_processing_job_emails': True, 'social_orcid': None, 'social_researchgate': None, - 'social_googlescholar': None + 'social_googlescholar': None, + 'creation_timestamp': None } def tearDown(self): @@ -88,7 +89,22 @@ def test_instantiate_unknown_user(self): with self.assertRaises(qdb.exceptions.QiitaDBUnknownIDError): qdb.user.User('FAIL@OMG.bar') - def _check_correct_info(self, obs, exp): + def _check_correct_info(self, obs, exp, ts_before=None): + """Compares info dict of user with special handling of specific keys. + + Parameters + ---------- + obs : dict + Observed user info dictionary. + exp : dict + Expected user info dictionary. + ts_before : datetime.datetime or None + User.create records the creation timestamp through SQL's NOW(). + Since it is set by the database to the microsecond, we can't + predict it a priori and therefore simply record timestamp before + execution of user.create() and compare the relation. + The DB creation_timestamp column is optional, i.e. can be None. + """ self.assertEqual(set(exp.keys()), set(obs.keys())) for key in exp: # user_verify_code and password seed randomly generated so just @@ -97,10 +113,14 @@ def _check_correct_info(self, obs, exp): self.assertEqual(len(obs[key]), 20) elif key == "password": self.assertEqual(len(obs[key]), 60) + elif key == "creation_timestamp": + self.assertTrue(((exp[key] is None) and (obs[key] is None)) + or (ts_before <= exp[key])) else: self.assertEqual(obs[key], exp[key]) def test_create_user(self): + before = datetime.now() user = qdb.user.User.create('testcreateuser@test.bar', 'password') # adding a couple of messages @@ -131,8 +151,9 @@ def test_create_user(self): 'email': 'testcreateuser@test.bar', 'social_orcid': None, 'social_researchgate': None, - 'social_googlescholar': None} - self._check_correct_info(obs, exp) + 'social_googlescholar': None, + 'creation_timestamp': datetime.now()} + self._check_correct_info(obs, exp, before) # Make sure new system messages are linked to user sql = """SELECT message_id FROM qiita.message_user @@ -146,6 +167,7 @@ def test_create_user(self): qdb.util.clear_system_messages() def test_create_user_info(self): + before = datetime.now() user = qdb.user.User.create('testcreateuserinfo@test.bar', 'password', self.userinfo) self.assertEqual(user.id, 'testcreateuserinfo@test.bar') @@ -171,8 +193,9 @@ def test_create_user_info(self): 'email': 'testcreateuserinfo@test.bar', 'social_orcid': None, 'social_researchgate': None, - 'social_googlescholar': None} - self._check_correct_info(obs, exp) + 'social_googlescholar': None, + 'creation_timestamp': datetime.now()} + self._check_correct_info(obs, exp, before) def test_create_user_column_not_allowed(self): self.userinfo["email"] = "FAIL" @@ -241,7 +264,8 @@ def test_get_info(self): 'phone': '222-444-6789', 'social_orcid': None, 'social_researchgate': None, - 'social_googlescholar': None + 'social_googlescholar': None, + 'creation_timestamp': None } self.assertEqual(self.user.info, expinfo) diff --git a/qiita_db/user.py b/qiita_db/user.py index b4beac184..094d48d57 100644 --- a/qiita_db/user.py +++ b/qiita_db/user.py @@ -234,6 +234,12 @@ def create(cls, email, password, info=None): cls._table, ','.join(columns), ','.join(['%s'] * len(values))) qdb.sql_connection.TRN.add(sql, values) + # log timestamp of user creation + sql = """UPDATE qiita.{0} + SET creation_timestamp = NOW() + WHERE email = %s""".format(cls._table) + qdb.sql_connection.perform_as_transaction(sql, [email]) + # Add system messages to user sql = """INSERT INTO qiita.message_user (email, message_id) SELECT %s, message_id FROM qiita.message diff --git a/qiita_pet/handlers/user_handlers.py b/qiita_pet/handlers/user_handlers.py index d75316a80..cd65f18c7 100644 --- a/qiita_pet/handlers/user_handlers.py +++ b/qiita_pet/handlers/user_handlers.py @@ -196,7 +196,9 @@ class UserProfileHandler(BaseHandler): def get(self): profile = UserProfile() profile.process(data=self.current_user.info) - self.render("user_profile.html", profile=profile, msg="", passmsg="") + self.render("user_profile.html", profile=profile, msg="", passmsg="", + creation_timestamp=self.current_user.info[ + 'creation_timestamp']) @authenticated @execute_as_transaction @@ -248,7 +250,9 @@ def post(self): else: passmsg = "Incorrect old password" self.render("user_profile.html", user=user.id, profile=form_data, - msg=msg, passmsg=passmsg) + msg=msg, passmsg=passmsg, + creation_timestamp=self.current_user.info[ + 'creation_timestamp']) class ForgotPasswordHandler(BaseHandler): diff --git a/qiita_pet/templates/user_profile.html b/qiita_pet/templates/user_profile.html index 66da290d9..cb8519f75 100644 --- a/qiita_pet/templates/user_profile.html +++ b/qiita_pet/templates/user_profile.html @@ -27,6 +27,9 @@

User Information

{% end %} {% end %} + {%if creation_timestamp is not None %} +
account created at {{creation_timestamp}}
+ {% end %}
{{msg}}
From c94ccb92ca814594165b631c782303c2c8ffcead Mon Sep 17 00:00:00 2001 From: sjanssen2 Date: Wed, 19 Jun 2024 08:43:53 +0200 Subject: [PATCH 02/11] at -> on --- qiita_pet/templates/user_profile.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiita_pet/templates/user_profile.html b/qiita_pet/templates/user_profile.html index cb8519f75..5f5336d95 100644 --- a/qiita_pet/templates/user_profile.html +++ b/qiita_pet/templates/user_profile.html @@ -28,7 +28,7 @@

User Information

{% end %} {%if creation_timestamp is not None %} -
account created at {{creation_timestamp}}
+
account created on {{creation_timestamp}}
{% end %}
{{msg}}
From ca55a2fc99f9d9d1282646b3be96295d57cad3fe Mon Sep 17 00:00:00 2001 From: sjanssen2 Date: Wed, 19 Jun 2024 09:07:37 +0200 Subject: [PATCH 03/11] add new col --- qiita_db/test/test_util.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qiita_db/test/test_util.py b/qiita_db/test/test_util.py index 26fff3004..57afd6b4d 100644 --- a/qiita_db/test/test_util.py +++ b/qiita_db/test/test_util.py @@ -93,7 +93,8 @@ def test_get_table_cols(self): exp = {"email", "user_level_id", "password", "name", "affiliation", "address", "phone", "user_verify_code", "pass_reset_code", "pass_reset_timestamp", "receive_processing_job_emails", - "social_orcid", "social_researchgate", "social_googlescholar"} + "social_orcid", "social_researchgate", "social_googlescholar", + "creation_timestamp"} self.assertEqual(set(obs), exp) def test_exists_table(self): From 1488be79e9468e240ea318ae8920fd6559030307 Mon Sep 17 00:00:00 2001 From: sjanssen2 Date: Wed, 19 Jun 2024 17:13:58 +0200 Subject: [PATCH 04/11] use patch for DB changes --- qiita_db/support_files/patches/93.sql | 8 ++++++++ qiita_db/support_files/qiita-db-unpatched.sql | 3 +-- qiita_db/user.py | 6 ------ 3 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 qiita_db/support_files/patches/93.sql diff --git a/qiita_db/support_files/patches/93.sql b/qiita_db/support_files/patches/93.sql new file mode 100644 index 000000000..6730f8494 --- /dev/null +++ b/qiita_db/support_files/patches/93.sql @@ -0,0 +1,8 @@ +-- Jun 19, 2024 +-- Adding a new column to the user table that logs when this account was created +-- Usefull e.g. to prune non-verified=inactive user or to plot user growth + +ALTER TABLE qiita.qiita_user + ADD creation_timestamp timestamp without time zone DEFAULT NOW(); + +COMMENT ON COLUMN qiita.qiita_user.creation_timestamp IS 'The date the user account was created'; diff --git a/qiita_db/support_files/qiita-db-unpatched.sql b/qiita_db/support_files/qiita-db-unpatched.sql index 137e72963..57580fa26 100644 --- a/qiita_db/support_files/qiita-db-unpatched.sql +++ b/qiita_db/support_files/qiita-db-unpatched.sql @@ -1891,8 +1891,7 @@ CREATE TABLE qiita.qiita_user ( receive_processing_job_emails boolean DEFAULT false, social_orcid character varying DEFAULT NULL, social_researchgate character varying DEFAULT NULL, - social_googlescholar character varying DEFAULT NULL, - creation_timestamp timestamp without time zone DEFAULT NULL + social_googlescholar character varying DEFAULT NULL ); diff --git a/qiita_db/user.py b/qiita_db/user.py index 094d48d57..b4beac184 100644 --- a/qiita_db/user.py +++ b/qiita_db/user.py @@ -234,12 +234,6 @@ def create(cls, email, password, info=None): cls._table, ','.join(columns), ','.join(['%s'] * len(values))) qdb.sql_connection.TRN.add(sql, values) - # log timestamp of user creation - sql = """UPDATE qiita.{0} - SET creation_timestamp = NOW() - WHERE email = %s""".format(cls._table) - qdb.sql_connection.perform_as_transaction(sql, [email]) - # Add system messages to user sql = """INSERT INTO qiita.message_user (email, message_id) SELECT %s, message_id FROM qiita.message From 3c75556437aec2836adbf905f73f281a15a04b29 Mon Sep 17 00:00:00 2001 From: sjanssen2 Date: Wed, 19 Jun 2024 17:22:16 +0200 Subject: [PATCH 05/11] forgot to remove addition of comment here --- qiita_db/support_files/qiita-db-unpatched.sql | 7 ------- 1 file changed, 7 deletions(-) diff --git a/qiita_db/support_files/qiita-db-unpatched.sql b/qiita_db/support_files/qiita-db-unpatched.sql index 57580fa26..a61b4645d 100644 --- a/qiita_db/support_files/qiita-db-unpatched.sql +++ b/qiita_db/support_files/qiita-db-unpatched.sql @@ -1931,13 +1931,6 @@ COMMENT ON COLUMN qiita.qiita_user.pass_reset_code IS 'Randomly generated code f COMMENT ON COLUMN qiita.qiita_user.pass_reset_timestamp IS 'Time the reset code was generated'; --- --- Name: COLUMN qiita_user.creation_timestamp; Type: COMMENT; Schema: qiita --- - -COMMENT ON COLUMN qiita.qiita_user.creation_timestamp IS 'The date the user account was created'; - - -- -- Name: reference; Type: TABLE; Schema: qiita -- From dd0ee7407bd92cfd9a479f265682cb335ee3dd4f Mon Sep 17 00:00:00 2001 From: sjanssen2 Date: Wed, 19 Jun 2024 22:41:44 +0200 Subject: [PATCH 06/11] moving changes to patch 92 --- qiita_db/support_files/patches/92.sql | 9 +++++++++ qiita_db/support_files/patches/93.sql | 8 -------- 2 files changed, 9 insertions(+), 8 deletions(-) delete mode 100644 qiita_db/support_files/patches/93.sql diff --git a/qiita_db/support_files/patches/92.sql b/qiita_db/support_files/patches/92.sql index a8a7d8bb0..e6c2f4b0a 100644 --- a/qiita_db/support_files/patches/92.sql +++ b/qiita_db/support_files/patches/92.sql @@ -27,3 +27,12 @@ ALTER TABLE qiita.prep_template ADD current_human_filtering boolean DEFAULT Fals -- Adding a new column: reprocess_job_id to qiita.prep_template to keep track of -- the job that reprocessed this prep ALTER TABLE qiita.prep_template ADD reprocess_job_id uuid DEFAULT NULL; + +-- Jun 19, 2024 +-- Adding a new column to the user table that logs when this account was created +-- Usefull e.g. to prune non-verified=inactive user or to plot user growth + +ALTER TABLE qiita.qiita_user + ADD creation_timestamp timestamp without time zone DEFAULT NOW(); + +COMMENT ON COLUMN qiita.qiita_user.creation_timestamp IS 'The date the user account was created'; diff --git a/qiita_db/support_files/patches/93.sql b/qiita_db/support_files/patches/93.sql deleted file mode 100644 index 6730f8494..000000000 --- a/qiita_db/support_files/patches/93.sql +++ /dev/null @@ -1,8 +0,0 @@ --- Jun 19, 2024 --- Adding a new column to the user table that logs when this account was created --- Usefull e.g. to prune non-verified=inactive user or to plot user growth - -ALTER TABLE qiita.qiita_user - ADD creation_timestamp timestamp without time zone DEFAULT NOW(); - -COMMENT ON COLUMN qiita.qiita_user.creation_timestamp IS 'The date the user account was created'; From 6769053de94db5f8ce9241efe293e3b5038de6b3 Mon Sep 17 00:00:00 2001 From: sjanssen2 Date: Wed, 19 Jun 2024 22:53:22 +0200 Subject: [PATCH 07/11] move adding date from populate_test_db.sql to here --- qiita_db/support_files/patches/92.sql | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qiita_db/support_files/patches/92.sql b/qiita_db/support_files/patches/92.sql index e6c2f4b0a..45fd7e252 100644 --- a/qiita_db/support_files/patches/92.sql +++ b/qiita_db/support_files/patches/92.sql @@ -36,3 +36,7 @@ ALTER TABLE qiita.qiita_user ADD creation_timestamp timestamp without time zone DEFAULT NOW(); COMMENT ON COLUMN qiita.qiita_user.creation_timestamp IS 'The date the user account was created'; + +-- for testing: provide creation date for one of the existing users + +UPDATE SET creation_timestamp = '2015-12-03 13:52:42.751331-07' WHERE email = 'test@foo.bar'; From 2ef5de7f23f5972c0dc594abdb5a4e444e436d13 Mon Sep 17 00:00:00 2001 From: sjanssen2 Date: Wed, 19 Jun 2024 22:53:54 +0200 Subject: [PATCH 08/11] revert changes, see patch --- qiita_db/support_files/populate_test_db.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiita_db/support_files/populate_test_db.sql b/qiita_db/support_files/populate_test_db.sql index 0a71959ac..46c0aaed7 100644 --- a/qiita_db/support_files/populate_test_db.sql +++ b/qiita_db/support_files/populate_test_db.sql @@ -50,7 +50,7 @@ INSERT INTO qiita.user_level VALUES (7, 'wet-lab admin', 'Can access the private -- Data for Name: qiita_user; Type: TABLE DATA; Schema: qiita; Owner: antoniog -- -INSERT INTO qiita.qiita_user VALUES ('test@foo.bar', 4, '$2a$12$gnUi8Qg.0tvW243v889BhOBhWLIHyIJjjgaG6dxuRJkUM8nXG9Efe', 'Dude', 'Nowhere University', '123 fake st, Apt 0, Faketown, CO 80302', '111-222-3344', NULL, NULL, NULL, false, '0000-0002-0975-9019', 'Rob-Knight', '_e3QL94AAAAJ', '2015-12-03 13:52:42.751331-07'); +INSERT INTO qiita.qiita_user VALUES ('test@foo.bar', 4, '$2a$12$gnUi8Qg.0tvW243v889BhOBhWLIHyIJjjgaG6dxuRJkUM8nXG9Efe', 'Dude', 'Nowhere University', '123 fake st, Apt 0, Faketown, CO 80302', '111-222-3344', NULL, NULL, NULL, false, '0000-0002-0975-9019', 'Rob-Knight', '_e3QL94AAAAJ'); INSERT INTO qiita.qiita_user VALUES ('shared@foo.bar', 4, '$2a$12$gnUi8Qg.0tvW243v889BhOBhWLIHyIJjjgaG6dxuRJkUM8nXG9Efe', 'Shared', 'Nowhere University', '123 fake st, Apt 0, Faketown, CO 80302', '111-222-3344', NULL, NULL, NULL, false); INSERT INTO qiita.qiita_user VALUES ('admin@foo.bar', 1, '$2a$12$gnUi8Qg.0tvW243v889BhOBhWLIHyIJjjgaG6dxuRJkUM8nXG9Efe', 'Admin', 'Owner University', '312 noname st, Apt K, Nonexistantown, CO 80302', '222-444-6789', NULL, NULL, NULL, false); INSERT INTO qiita.qiita_user VALUES ('demo@microbio.me', 4, '$2a$12$gnUi8Qg.0tvW243v889BhOBhWLIHyIJjjgaG6dxuRJkUM8nXG9Efe', 'Demo', 'Qiita Dev', '1345 Colorado Avenue', '303-492-1984', NULL, NULL, NULL, false); From 9260ac53f1f68698ca00d1b35fc8316890e95f5a Mon Sep 17 00:00:00 2001 From: Stefan Janssen Date: Thu, 20 Jun 2024 08:03:32 +0200 Subject: [PATCH 09/11] adding table name :-/ --- qiita_db/support_files/patches/92.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiita_db/support_files/patches/92.sql b/qiita_db/support_files/patches/92.sql index 7c83262c5..2162533d4 100644 --- a/qiita_db/support_files/patches/92.sql +++ b/qiita_db/support_files/patches/92.sql @@ -42,4 +42,4 @@ COMMENT ON COLUMN qiita.qiita_user.creation_timestamp IS 'The date the user acco -- for testing: provide creation date for one of the existing users -UPDATE SET creation_timestamp = '2015-12-03 13:52:42.751331-07' WHERE email = 'test@foo.bar'; +UPDATE qiita.qiita_user SET creation_timestamp = '2015-12-03 13:52:42.751331-07' WHERE email = 'test@foo.bar'; From b883817d87e4d81ef3a82e50b551e8cfbad3f73b Mon Sep 17 00:00:00 2001 From: sjanssen2 Date: Thu, 20 Jun 2024 10:10:37 +0200 Subject: [PATCH 10/11] order in DB changed due to UPDATE of creation_timestamp for user test@foo.bar --- qiita_db/handlers/tests/test_user.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qiita_db/handlers/tests/test_user.py b/qiita_db/handlers/tests/test_user.py index 38831471b..4898976ce 100644 --- a/qiita_db/handlers/tests/test_user.py +++ b/qiita_db/handlers/tests/test_user.py @@ -51,10 +51,11 @@ def test_get(self): obs = loads(obs.body) exp = {'data': [ - {'email': 'test@foo.bar', 'name': 'Dude'}, {'email': 'shared@foo.bar', 'name': 'Shared'}, {'email': 'admin@foo.bar', 'name': 'Admin'}, - {'email': 'demo@microbio.me', 'name': 'Demo'}]} + {'email': 'demo@microbio.me', 'name': 'Demo'}, + {'email': 'test@foo.bar', 'name': 'Dude'} + ]} self.assertEqual(obs, exp) From 6601e24c66597246330321d329bcfc1691073065 Mon Sep 17 00:00:00 2001 From: sjanssen2 Date: Thu, 20 Jun 2024 12:31:41 +0200 Subject: [PATCH 11/11] fix test --- qiita_db/test/test_user.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/qiita_db/test/test_user.py b/qiita_db/test/test_user.py index f5d54ab3d..0d14d2c8a 100644 --- a/qiita_db/test/test_user.py +++ b/qiita_db/test/test_user.py @@ -76,7 +76,7 @@ def setUp(self): 'social_orcid': None, 'social_researchgate': None, 'social_googlescholar': None, - 'creation_timestamp': None + 'creation_timestamp': datetime(2015, 12, 3, 13, 52, 42, 751331) } def tearDown(self): @@ -265,8 +265,19 @@ def test_get_info(self): 'social_orcid': None, 'social_researchgate': None, 'social_googlescholar': None, - 'creation_timestamp': None + 'creation_timestamp': datetime(2015, 12, 3, 13, 52, 42, 751331) } + + # test database is re-populated during testing several times. + # Creation_timestamp depends on the percise timing of the repopulation, + # i.e. we cannot predict its value. We just test that this date should + # be within an hour and now. For the remainder of tests, we update + # our expectation. + self.assertTrue(datetime.now() - timedelta(hours=1) < + self.user.info['creation_timestamp'] < + datetime.now()) + expinfo['creation_timestamp'] = self.user.info['creation_timestamp'] + self.assertEqual(self.user.info, expinfo) def test_set_info(self):