Exemple #1
0
    def test_messages(self):
        add_system_message('SYS MESSAGE', datetime.now())
        user = User('*****@*****.**')
        obs = user.messages()
        exp_msg = [
            (4, 'SYS MESSAGE'),
            (1, 'message 1'),
            (2, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. '
                'Pellentesque sed auctor ex, non placerat sapien. Vestibulum '
                'vestibulum massa ut sapien condimentum, cursus consequat diam'
                ' sodales. Nulla aliquam arcu ut massa auctor, et vehicula '
                'mauris tempor. In lacinia viverra ante quis pellentesque. '
                'Nunc vel mi accumsan, porttitor eros ut, pharetra elit. Nulla'
                ' ac nisi quis dui egestas malesuada vitae ut mauris. Morbi '
                'blandit non nisl a finibus. In erat velit, congue at ipsum '
                'sit amet, venenatis bibendum sem. Curabitur vel odio sed est '
                'rutrum rutrum. Quisque efficitur ut purus in ultrices. '
                'Pellentesque eu auctor justo.'),
            (3, 'message <a href="#">3</a>')]
        self.assertEqual([(x[0], x[1]) for x in obs], exp_msg)
        self.assertTrue(all(x[2] < datetime.now() for x in obs))
        self.assertFalse(all(x[3] for x in obs))
        self.assertEqual([x[4] for x in obs], [True, False, False, False])

        obs = user.messages(1)
        exp_msg = ['SYS MESSAGE']
        self.assertEqual([x[1] for x in obs], exp_msg)
Exemple #2
0
    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]])
Exemple #3
0
    def test_add_system_message(self):
        count = get_count('qiita.message') + 1
        add_system_message("SYS MESSAGE", datetime(2015, 8, 5, 19, 41))

        obs = [[x[0], x[1]] for x in User('*****@*****.**').messages()]
        exp = [[count, 'SYS MESSAGE'], [1, 'message 1']]
        self.assertEqual(obs, exp)
        obs = [[x[0], x[1]] for x in User('*****@*****.**').messages()]
        exp = [[count, 'SYS MESSAGE']]
        self.assertEqual(obs, exp)

        sql = "SELECT expiration from qiita.message WHERE message_id = %s"
        obs = self.conn_handler.execute_fetchall(sql, [count])
        exp = [[datetime(2015, 8, 5, 19, 41)]]
        self.assertEqual(obs, exp)
Exemple #4
0
    def test_clear_system_messages(self):
        message_id = get_count('qiita.message') + 1
        obs = [[x[0], x[1]] for x in User('*****@*****.**').messages()]
        exp = [[1, 'message 1']]
        self.assertEqual(obs, exp)

        add_system_message("SYS MESSAGE", datetime(2015, 8, 5, 19, 41))
        obs = [[x[0], x[1]] for x in User('*****@*****.**').messages()]
        exp = [[1, 'message 1'], [message_id, 'SYS MESSAGE']]
        self.assertItemsEqual(obs, exp)

        clear_system_messages()
        obs = [[x[0], x[1]] for x in User('*****@*****.**').messages()]
        exp = [[1, 'message 1']]
        self.assertEqual(obs, exp)

        # Run again with no system messages to make sure no errors
        clear_system_messages()