-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
log user creation timestamp #3416
Changes from 6 commits
867c19e
c94ccb9
ca55a2f
1488be7
3c75556
dd0ee74
6769053
2ef5de7
862eb20
9260ac5
b883817
6601e24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 ('[email protected]', 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 ('[email protected]', 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 ('[email protected]', 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 ('[email protected]', 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 ('[email protected]', 4, '$2a$12$gnUi8Qg.0tvW243v889BhOBhWLIHyIJjjgaG6dxuRJkUM8nXG9Efe', 'Demo', 'Qiita Dev', '1345 Colorado Avenue', '303-492-1984', NULL, NULL, NULL, false); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,8 @@ def setUp(self): | |
'receive_processing_job_emails': True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue with this test and my suggestion about using now() in the database is that there is going to be a small difference on the tests so they will need to be adjusted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to account for these unpredictable time differences with your "before < obs < after" assertions, e.g. here https://github.com/jlab/qiita/blob/1488be79e9468e240ea318ae8920fd6559030307/qiita_db/test/test_user.py#L170-L198 |
||
'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('[email protected]') | ||
|
||
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('[email protected]', 'password') | ||
|
||
# adding a couple of messages | ||
|
@@ -131,8 +151,9 @@ def test_create_user(self): | |
'email': '[email protected]', | ||
'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('[email protected]', 'password', | ||
self.userinfo) | ||
self.assertEqual(user.id, '[email protected]') | ||
|
@@ -171,8 +193,9 @@ def test_create_user_info(self): | |
'email': '[email protected]', | ||
'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) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the failure, you need to remove this change too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, I thought that the new patches should be free of test data. I've moved this addition of the creation_timestamp info into the 92.sql patch. Let's wait for the tests.