def test_verify_code(self): sql = ("insert into qiita.qiita_user values ('*****@*****.**', '1', " "'testtest', 'testuser', '', '', '', 'verifycode', 'resetcode'" ",null)") self.conn_handler.execute(sql) self.assertFalse(User.verify_code('*****@*****.**', 'wrongcode', 'create')) self.assertFalse(User.verify_code('*****@*****.**', 'wrongcode', 'reset')) self.assertTrue(User.verify_code('*****@*****.**', 'verifycode', 'create')) self.assertTrue(User.verify_code('*****@*****.**', 'resetcode', 'reset')) # make sure errors raised if code already used or wrong type with self.assertRaises(QiitaDBError): User.verify_code('*****@*****.**', 'verifycode', 'create') with self.assertRaises(QiitaDBError): User.verify_code('*****@*****.**', 'resetcode', 'reset') with self.assertRaises(IncompetentQiitaDeveloperError): User.verify_code('*****@*****.**', 'fakecode', 'badtype') # make sure default analyses created sql = ("SELECT email, name, description, dflt FROM qiita.analysis " "WHERE email = '*****@*****.**'") obs = self.conn_handler.execute_fetchall(sql) exp = [['*****@*****.**', '[email protected]', 'dflt', True], ['*****@*****.**', '[email protected]', 'dflt', True]] self.assertEqual(obs, exp)
def test_verify_code(self): add_system_message("TESTMESSAGE_OLD", datetime.now()) add_system_message("TESTMESSAGE", datetime.now() + timedelta(seconds=59)) sql = ("insert into qiita.qiita_user values ('*****@*****.**', '1', " "'testtest', 'testuser', '', '', '', 'verifycode', 'resetcode'" ",null)") self.conn_handler.execute(sql) self.assertFalse(User.verify_code('*****@*****.**', 'wrongcode', 'create')) self.assertFalse(User.verify_code('*****@*****.**', 'wrongcode', 'reset')) self.assertTrue(User.verify_code('*****@*****.**', 'verifycode', 'create')) self.assertTrue(User.verify_code('*****@*****.**', 'resetcode', 'reset')) # make sure errors raised if code already used or wrong type with self.assertRaises(QiitaDBError): User.verify_code('*****@*****.**', 'verifycode', 'create') with self.assertRaises(QiitaDBError): User.verify_code('*****@*****.**', 'resetcode', 'reset') with self.assertRaises(IncompetentQiitaDeveloperError): User.verify_code('*****@*****.**', 'fakecode', 'badtype') # make sure default analyses created sql = ("SELECT email, name, description, dflt FROM qiita.analysis " "WHERE email = '*****@*****.**'") obs = self.conn_handler.execute_fetchall(sql) exp = [['*****@*****.**', '[email protected]', 'dflt', True], ['*****@*****.**', '[email protected]', 'dflt', True]] self.assertEqual(obs, exp) # Make sure default analyses are linked with the portal sql = """SELECT COUNT(1) FROM qiita.analysis JOIN qiita.analysis_portal USING (analysis_id) JOIN qiita.portal_type USING (portal_type_id) WHERE email = '*****@*****.**' AND dflt = true""" self.assertEqual(self.conn_handler.execute_fetchone(sql)[0], 2) # Make sure new system messages are linked to user sql = """SELECT message_id FROM qiita.message_user WHERE email = '*****@*****.**'""" m_id = get_count('qiita.message') self.assertEqual(self.conn_handler.execute_fetchall(sql), [[m_id]])
def get(self, code): email = self.get_argument("email").strip().lower() if User.verify_code(email, code, "create"): msg = "Successfully verified user! You are now free to log in." else: msg = "Code not valid!" self.render("user_verified.html", msg=msg)
def get(self, code): email = self.get_argument("email").strip().lower() if User.verify_code(email, code, "create"): msg = "Successfully verified user! You are now free to log in." color = "black" r_client.zadd('qiita-usernames', email, 0) else: msg = "Code not valid!" color = "red" self.render("user_verified.html", msg=msg, color=color, email=self.get_argument("email").strip())
def test_verify_code(self): sql = ("insert into qiita.qiita_user values ('*****@*****.**', '1', " "'testtest', 'testuser', '', '', '', 'verifycode', 'resetcode'" ",null)") self.conn_handler.execute(sql) self.assertTrue(User.verify_code('*****@*****.**', 'verifycode', 'create')) self.assertTrue(User.verify_code('*****@*****.**', 'resetcode', 'reset')) self.assertFalse(User.verify_code('*****@*****.**', 'wrongcode', 'create')) self.assertFalse(User.verify_code('*****@*****.**', 'wrongcode', 'reset')) with self.assertRaises(IncompetentQiitaDeveloperError): User.verify_code('*****@*****.**', 'fakecode', 'badtype')
def test_verify_code(self): sql = ("insert into qiita.qiita_user values ('*****@*****.**', '1', " "'testtest', 'testuser', '', '', '', 'verifycode', 'resetcode'" ",null)") self.conn_handler.execute(sql) self.assertTrue( User.verify_code('*****@*****.**', 'verifycode', 'create')) self.assertTrue(User.verify_code('*****@*****.**', 'resetcode', 'reset')) self.assertFalse( User.verify_code('*****@*****.**', 'wrongcode', 'create')) self.assertFalse( User.verify_code('*****@*****.**', 'wrongcode', 'reset')) with self.assertRaises(IncompetentQiitaDeveloperError): User.verify_code('*****@*****.**', 'fakecode', 'badtype')
def get(self, code): email = self.get_argument("email").strip().lower() code_is_valid = False msg = "This code is not valid." # an exception is raised if the 'code type' is not available, otherwise # the method determines the validity of the code try: code_is_valid = User.verify_code(email, code, "create") except QiitaDBError: msg = "This user has already created an account." if code_is_valid: msg = "Successfully verified user. You are now free to log in." color = "black" r_client.zadd('qiita-usernames', email, 0) else: color = "red" self.render("user_verified.html", msg=msg, color=color, email=self.get_argument("email").strip())