Ejemplo n.º 1
0
 def test_session_name_and_email_set(self):
     req = MockRequest(self.env)
     req.session.last_visit = 42
     req.session['name'] = 'joe'
     req.session['email'] = '*****@*****.**'
     rv = self.strategy.test(req, None, None, '127.0.0.1')
     self.assertEqual((6, "Existing session found"), rv)
 def _test_authenticated_session(self, username, fullname, email):
     """
     Verifies that a session cookie does not get used if the user is logged
     in, and that Trac expires the cookie.
     """
     req = MockRequest(self.env, authname=username)
     req.incookie['trac_session'] = '123456'
     session = Session(self.env, req)
     self.assertEqual(username, session.sid)
     session['email'] = email
     session['name'] = fullname
     session.save()
Ejemplo n.º 3
0
    def test_template_data_for_time_field_with_date_format(self):
        value = datetime(2016, 2, 22, 22, 22, 22, tzinfo=utc)
        self.env.config.set('ticket-custom', 'timefield', 'time')
        self.env.config.set('ticket-custom', 'timefield.format', 'date')
        self._insert_ticket(summary='Time fields', timefield=value)
        self.assertEqual(value, Ticket(self.env, 1)['timefield'])

        gmt12 = timezone('GMT +12:00')
        req = MockRequest(self.env,
                          method='GET',
                          path_info='/ticket/1',
                          tz=gmt12)
        expected = user_time(req, format_date, value)
        self.assertIn('23', expected)  # check 23 in day part
        self.assertTrue(self.ticket_module.match_request(req))
        data = self.ticket_module.process_request(req)[1]

        for f in data['fields']:
            if f['name'] == 'timefield':
                self.assertEqual(expected, f['edit'])
                break
        else:
            self.fail('Missing timefield field')
Ejemplo n.º 4
0
 def test_title_and_description_with_sub_vars_in_sql(self):
     with self.env.db_transaction:
         id_ = self._insert_report(
             'Tickets on $M for $USER', '-- M=milestone1\r\n'
             'SELECT * FROM ticket WHERE milestone=$M AND owner=$USER\r\n',
             'Show tickets on $M for $USER')
         for milestone in ('milestone1', 'milestone2'):
             insert_ticket(self.env,
                           status='new',
                           summary='Test 1',
                           owner='joe',
                           milestone=milestone)
     req = MockRequest(self.env,
                       path_info='/report/%d' % id_,
                       authname='joe')
     self.assertTrue(self.report_module.match_request(req))
     data = self.report_module.process_request(req)[1]
     self.assertEqual('{%d} Tickets on milestone1 for joe' % id_,
                      data['title'])
     self.assertEqual('Show tickets on milestone1 for joe',
                      data['description'])
     self.assertIsNone(data['message'])
     self.assertEqual(1, data['numrows'])
Ejemplo n.º 5
0
 def test_add(self):
     req = MockRequest(self.env, authname='joe')
     with self.env.db_transaction:
         self._add_subscriber(req, 'TicketSubscriber1', format='text/html')
         self._add_subscriber(req, 'TicketSubscriber2')
         self._add_subscriber(req, 'TicketSubscriber3', format='text/html')
         self._add_subscriber(req, 'XmppSubscriber1', distributor='xmpp',
                              adverb='never')
     self.assertEqual(
         [('joe', 1, 'email', 'text/html', 1, 'always',
           'TicketSubscriber1'),
          ('joe', 1, 'email', 'text/plain', 2, 'always',
           'TicketSubscriber2'),
          ('joe', 1, 'email', 'text/html', 3, 'always',
           'TicketSubscriber3'),
          ('joe', 1, 'xmpp',  'text/plain', 1, 'never',
           'XmppSubscriber1')],
         self.env.db_query("""\
             SELECT sid, authenticated, distributor, format, priority,
                    adverb, class
             FROM notify_subscription
             WHERE sid=%s AND authenticated=%s
             ORDER BY distributor, priority""", ('joe', 1)))
Ejemplo n.º 6
0
    def test_load_session_key(self):
        """Load session key."""
        old_sid = 'a' * 24
        new_sid, name, email = self._insert_session()
        req = MockRequest(self.env,
                          method='POST',
                          path_info='/prefs/advanced',
                          cookie='trac_session=%s;' % old_sid,
                          args={
                              'loadsid': new_sid,
                              'restore': True
                          })
        module = PreferencesModule(self.env)

        self.assertEqual(old_sid, req.session.sid)
        self.assertIsNone(req.session.get('name'))
        self.assertIsNone(req.session.get('email'))
        self.assertTrue(module.match_request(req))
        module.process_request(req)
        self.assertIn("The session has been loaded.", req.chrome['notices'])
        self.assertEqual(new_sid, req.session.sid)
        self.assertEqual(name, req.session.get('name'))
        self.assertEqual(email, req.session.get('email'))
Ejemplo n.º 7
0
    def test_invalid_log_configuration_not_saved(self):
        """Invalid log configuration is reverted and not saved."""
        logging_config = self.env.config['logging']
        log_type = logging_config.get('log_type')
        log_file = logging_config.get('log_file')
        log_level = logging_config.get('log_level')
        req = MockRequest(self.env, path_info='/admin/general/logging',
                          method='POST',
                          args={'log_type': 'file',
                                'log_level': log_level,
                                'log_file': '/path/to/invalid/file'})
        mod = AdminModule(self.env)

        self.assertTrue(mod.match_request(req))
        self.assertRaises(RequestDone, mod.process_request, req)

        self.assertEqual(1, len(req.chrome['warnings']))
        self.assertIn('Changes not saved. Logger configuration error:',
                      req.chrome['warnings'][0])
        self.assertNotEqual('file', log_type)
        self.assertEqual(log_type, logging_config.get('log_type'))
        self.assertEqual(log_level, logging_config.get('log_level'))
        self.assertEqual(log_file, logging_config.get('log_file'))
Ejemplo n.º 8
0
    def test_new_component_has_no_owner(self):
        """Ticket is not disowned when the component is changed to a
        component with no owner.
        """
        self._add_component('component3', 'cowner3')
        self._add_component('component4', '')

        ticket = insert_ticket(self.env, reporter='reporter1',
                               summary='the summary', component='component3',
                               owner='cowner3', status='new')

        req = MockRequest(self.env, method='POST', args={
            'id': ticket.id,
            'field_component': 'component4',
            'submit': True,
            'action': 'leave',
            'view_time': str(to_utimestamp(ticket['changetime'])),
        })
        self.assertRaises(RequestDone, self.ticket_module.process_request, req)
        ticket = Ticket(self.env, ticket.id)

        self.assertEqual('component4', ticket['component'])
        self.assertEqual('cowner3', ticket['owner'])
Ejemplo n.º 9
0
    def test_old_owner_not_old_component_owner(self):
        """New ticket owner is not updated if old owner is not the owner
        of the old component.
        """
        self._add_component('component3', 'cowner3')
        self._add_component('component4', 'cowner4')

        ticket = insert_ticket(self.env, reporter='reporter1',
                               summary='the summary', component='component3',
                               owner='owner1', status='new')

        req = MockRequest(self.env, method='POST', args={
            'id': ticket.id,
            'field_component': 'component4',
            'submit': True,
            'action': 'leave',
            'view_time': str(to_utimestamp(ticket['changetime'])),
        })
        self.assertRaises(RequestDone, self.ticket_module.process_request, req)
        ticket = Ticket(self.env, ticket.id)

        self.assertEqual('component4', ticket['component'])
        self.assertEqual('owner1', ticket['owner'])
Ejemplo n.º 10
0
 def test_add_stylesheet(self):
     req = MockRequest(self.env)
     add_stylesheet(req, 'common/css/trac.css')
     add_stylesheet(req, 'common/css/trac.css')
     add_stylesheet(req, 'https://example.com/trac.css')
     add_stylesheet(req, '//example.com/trac.css')
     add_stylesheet(req, '/dynamic.css')
     add_stylesheet(req, 'plugin/css/plugin.css')
     links = req.chrome['links']['stylesheet']
     self.assertEqual(5, len(links))
     self.assertEqual('text/css', links[0]['type'])
     self.assertEqual('/trac.cgi/chrome/common/css/trac.css',
                      links[0]['href'])
     self.assertEqual('text/css', links[1]['type'])
     self.assertEqual('https://example.com/trac.css',
                      links[1]['href'])
     self.assertEqual('text/css', links[2]['type'])
     self.assertEqual('//example.com/trac.css',
                      links[2]['href'])
     self.assertEqual('/trac.cgi/dynamic.css',
                      links[3]['href'])
     self.assertEqual('/trac.cgi/chrome/plugin/css/plugin.css',
                      links[4]['href'])
Ejemplo n.º 11
0
    def test_grant_permission_with_permission_grant(self):
        """User can only grant permissions they possess."""
        ps = PermissionSystem(self.env)
        ps.grant_permission('user1', 'PERMISSION_GRANT')
        ps.grant_permission('group1', 'WIKI_ADMIN')
        req = MockRequest(self.env,
                          method='POST',
                          authname='user1',
                          args={
                              'add': True,
                              'subject': 'user2',
                              'group': 'group1'
                          })

        with self.assertRaises(PermissionError) as cm:
            self.panel.render_admin_panel(req, 'general', 'perm', None)

        self.assertEqual(
            "The subject <strong>user2</strong> was not added "
            "to the group <strong>group1</strong>. The "
            "group has <strong>WIKI_ADMIN</strong> permission "
            "and you cannot grant permissions you don't possess.",
            unicode(cm.exception))
Ejemplo n.º 12
0
Archivo: log.py Proyecto: volcani/trac
 def test_with_rev_and_limit(self):
     req = MockRequest(self.env,
                       path_info='/log/mock/file',
                       args={
                           'rev': '49',
                           'limit': '4'
                       })
     template, data = self.process_request(req)
     items = data['items']
     self.assertEqual(5, len(items))
     self.assertEqual([49, 46, 43, 40, 37], [item['rev'] for item in items])
     self.assertEqual(['file'] * 4 + ['file-old'],
                      [item['path'] for item in items])
     self.assertEqual([1] * 4 + [2], [item['depth'] for item in items])
     self.assertEqual([None] * 4 + ['file-old'],
                      [item.get('copyfrom_path') for item in items])
     self.assertEqual(['edit'] * 3 + ['move', None],
                      [item['change'] for item in items])
     links = req.chrome['links']['next']
     self.assertEqual(
         '/trac.cgi/log/mock/file-old?limit=4&rev=37&'
         'mode=stop_on_copy', links[0]['href'])
     self.assertEqual(1, len(links))
Ejemplo n.º 13
0
    def test_component_change_and_owner_change(self):
        """New ticket owner is not updated if owner is explicitly
        changed.
        """
        self._add_component('component3', 'cowner3')
        self._add_component('component4', 'cowner4')

        ticket = Ticket(self.env)
        ticket.populate({
            'reporter': 'reporter1',
            'summary': 'the summary',
            'component': 'component3',
            'status': 'new',
        })
        tkt_id = ticket.insert()

        req = MockRequest(self.env,
                          method='POST',
                          args={
                              'id':
                              tkt_id,
                              'field_component':
                              'component4',
                              'submit':
                              True,
                              'action':
                              'change_owner',
                              'action_change_owner_reassign_owner':
                              'owner1',
                              'view_time':
                              str(to_utimestamp(ticket['changetime'])),
                          })
        self.assertRaises(RequestDone, self.ticket_module.process_request, req)
        ticket = Ticket(self.env, tkt_id)

        self.assertEqual('component4', ticket['component'])
        self.assertEqual('owner1', ticket['owner'])
Ejemplo n.º 14
0
    def test_redirect_to_query_href_in_req_args(self):
        redirect_listener_args = []
        def redirect_listener(req, url, permanent):
            redirect_listener_args[:] = (url, permanent)

        module = BatchModifyModule(self.env)
        req = MockRequest(self.env, method='POST', path_info='/batchmodify')
        query_opened_tickets = req.href.query(status='!closed')
        query_default = req.href.query()
        req.args = {'selected_tickets': '',
                    'query_href': query_opened_tickets}
        req.session['query_href'] = query_default
        req.add_redirect_listener(redirect_listener)

        self.assertTrue(module.match_request(req))
        self.assertRaises(RequestDone, module.process_request, req)
        self.assertEqual([query_opened_tickets, False],
                         redirect_listener_args)
Ejemplo n.º 15
0
    def test_copy_permissions_to_subject(self):
        """Copy permissions to subject.

        Undefined actions are skipped.
        """
        ps = PermissionSystem(self.env)
        ps.grant_permission('user1', 'WIKI_VIEW')
        ps.grant_permission('user1', 'TICKET_VIEW')
        self.env.db_transaction("""
            INSERT INTO permission VALUES ('user1', 'TEST_PERM')
            """)
        req = MockRequest(self.env,
                          method='POST',
                          args={
                              'copy': True,
                              'subject': 'user1',
                              'target': 'user2'
                          })

        with self.assertRaises(RequestDone):
            self.panel.render_admin_panel(req, 'general', 'perm', None)

        self.assertEqual(['TICKET_VIEW', 'WIKI_VIEW'],
                         ps.get_users_dict().get('user2'))
        self.assertEqual(2, len(req.chrome['notices']))
        self.assertIn(
            "The subject user2 has been granted the permission "
            "TICKET_VIEW.", req.chrome['notices'])
        self.assertIn(
            "The subject user2 has been granted the permission "
            "WIKI_VIEW.", req.chrome['notices'])
        self.assertIn(("WARNING", "Skipped granting TEST_PERM to user2: "
                       "permission unavailable."), self.env.log_messages)
        self.assertIn(("INFO", "Granted permission for TICKET_VIEW to user2"),
                      self.env.log_messages)
        self.assertIn(("INFO", "Granted permission for TICKET_VIEW to user2"),
                      self.env.log_messages)
Ejemplo n.º 16
0
    def test_delete(self):
        req = MockRequest(self.env, authname='joe')
        with self.env.db_transaction:
            ids = [self._add_subscriber(req, 'TicketSubscriber1'),
                   self._add_subscriber(req, 'TicketSubscriber2'),
                   self._add_subscriber(req, 'TicketSubscriber3'),
                   self._add_subscriber(req, 'XmppSubscriber1',
                                        distributor='xmpp', adverb='never'),
                   self._add_subscriber(req, 'XmppSubscriber2',
                                        distributor='xmpp')]
        self.assertEqual(5, self.env.db_query("""\
            SELECT COUNT(*) FROM notify_subscription
            WHERE sid=%s AND authenticated=%s""", ('joe', 1))[0][0])

        Subscription.delete(self.env, ids[1])
        rows = self.env.db_query("""\
            SELECT id, distributor, priority, class FROM notify_subscription
            WHERE sid=%s AND authenticated=%s
            ORDER BY distributor, priority""", ('joe', 1))
        self.assertEqual((ids[0], 'email', 1, 'TicketSubscriber1'), rows[0])
        self.assertEqual((ids[2], 'email', 2, 'TicketSubscriber3'), rows[1])
        self.assertEqual((ids[3], 'xmpp', 1, 'XmppSubscriber1'), rows[2])
        self.assertEqual((ids[4], 'xmpp', 2, 'XmppSubscriber2'), rows[3])
        self.assertEqual(4, len(rows))
Ejemplo n.º 17
0
 def setUp(self):
     self.env = EnvironmentStub(default_data=True)
     self.perm_sys = PermissionSystem(self.env)
     self.ctlr = TicketSystem(self.env).action_controllers[0]
     self.ticket = insert_ticket(self.env, status='new')
     self.env.insert_users([
         (user, None, None) for user in ('user1', 'user2', 'user3', 'user4')
     ])
     permissions = [
         ('user1', 'TICKET_EDIT_CC'),
         ('user2', 'TICKET_EDIT_CC'),
         ('user2', 'TICKET_BATCH_MODIFY'),
         ('user3', 'TICKET_ADMIN'),
         ('user4', 'TICKET_VIEW'),
         ('user1', 'group1'),
         ('user2', 'group1'),
         ('user2', 'group2'),
         ('user3', 'group2'),
         ('user4', 'group3')
     ]
     for perm in permissions:
         self.perm_sys.grant_permission(*perm)
     self.req = MockRequest(self.env, authname='user1')
     self.expected = """\
Ejemplo n.º 18
0
    def test_zip_archive(self):
        req = MockRequest(self.env, path_info='/browser/trunk',
                          args={'format': 'zip'})
        self.assertRaises(RequestDone, self.process_request, req)

        z = zipfile.ZipFile(req.response_sent, 'r')
        self.assertEqual(['trunk/dir1/', 'trunk/dir1/file.txt',
                          'trunk/dir2/', 'trunk/dir2/file.txt'],
                         sorted(i.filename for i in z.infolist()))

        zi = z.getinfo('trunk/dir1/')
        self.assertEqual((0o40755 << 16) | 0x10, zi.external_attr)

        zi = z.getinfo('trunk/dir1/file.txt')
        self.assertEqual(0o644 << 16, zi.external_attr)
        self.assertEqual('Contents for trunk/dir1/file.txt',
                         z.read('trunk/dir1/file.txt'))
        self.assertEqual((2017, 3, 31, 12, 34, 56), zi.date_time)

        zi = z.getinfo('trunk/dir2/file.txt')
        self.assertEqual(0o644 << 16, zi.external_attr)
        self.assertEqual('Contents for trunk/dir2/file.txt',
                         z.read('trunk/dir2/file.txt'))
        self.assertEqual((2017, 3, 31, 12, 34, 56), zi.date_time)
Ejemplo n.º 19
0
    def test_reporter_and_owner_full_name_is_displayed(self):
        """Full name of reporter and owner are used in ticket properties."""
        self.env.insert_users([('user1', 'User One', ''),
                               ('user2', 'User Two', '')])
        ticket = self._insert_ticket(reporter='user1', owner='user2')
        PermissionSystem(self.env).grant_permission('user2', 'TICKET_VIEW')
        req = MockRequest(self.env,
                          authname='user2',
                          method='GET',
                          args={
                              'id': ticket.id,
                              'replyto': '1'
                          })

        data = self.ticket_module.process_request(req)[1]

        self.assertEqual(
            u'<a class="trac-author" href="/trac.cgi/query?'
            u'status=!closed&amp;reporter=user1">User One</a>',
            unicode(data['reporter_link']))
        self.assertEqual(
            u'<a class="trac-author-user" href="/trac.cgi/query?'
            u'status=!closed&amp;owner=user2">User Two</a>',
            unicode(data['owner_link']))
Ejemplo n.º 20
0
    def setUp(self):
        tmpdir = os.path.realpath(tempfile.gettempdir())
        self.env = EnvironmentStub(enable=['trac.*', AuthzPolicy], path=tmpdir)
        self.env.config.set('trac', 'permission_policies',
                            'AuthzPolicy, DefaultPermissionPolicy')
        self.env.config.set('ticket', 'restrict_owner', True)

        self.perm_sys = PermissionSystem(self.env)
        self.env.insert_users([('user1', 'User C', '*****@*****.**'),
                               ('user2', 'User A', '*****@*****.**'),
                               ('user3', 'User D', '*****@*****.**'),
                               ('user4', 'User B', '*****@*****.**')])
        self.perm_sys.grant_permission('user1', 'TICKET_MODIFY')
        self.perm_sys.grant_permission('user2', 'TICKET_VIEW')
        self.perm_sys.grant_permission('user3', 'TICKET_MODIFY')
        self.perm_sys.grant_permission('user4', 'TICKET_MODIFY')
        self.authz_file = os.path.join(tmpdir, 'trac-authz-policy')
        create_file(self.authz_file)
        self.env.config.set('authz_policy', 'authz_file', self.authz_file)
        self.ctlr = TicketSystem(self.env).action_controllers[0]
        self.req1 = MockRequest(self.env, authname='user1')
        self.ticket = Ticket(self.env)
        self.ticket['status'] = 'new'
        self.ticket.insert()
Ejemplo n.º 21
0
 def setUp(self):
     self.env = EnvironmentStub(default_data=True)
     self.perm_sys = PermissionSystem(self.env)
     self.ctlr = TicketSystem(self.env).action_controllers[0]
     self.ticket = insert_ticket(self.env, status='new')
     with self.env.db_transaction as db:
         for user in ('user1', 'user2', 'user3', 'user4'):
             db("INSERT INTO session VALUES (%s, %s, %s)", (user, 1, 0))
     permissions = [
         ('user1', 'TICKET_EDIT_CC'),
         ('user2', 'TICKET_EDIT_CC'),
         ('user2', 'TICKET_BATCH_MODIFY'),
         ('user3', 'TICKET_ADMIN'),
         ('user4', 'TICKET_VIEW'),
         ('user1', 'group1'),
         ('user2', 'group1'),
         ('user2', 'group2'),
         ('user3', 'group2'),
         ('user4', 'group3')
     ]
     for perm in permissions:
         self.perm_sys.grant_permission(*perm)
     self.req = MockRequest(self.env, authname='user1')
     self.expected = """\
Ejemplo n.º 22
0
    def test_update_report_cancel(self):
        report = Report(self.env)
        report.query = "SELECT 1"
        report.insert()
        req = MockRequest(self.env,
                          method='POST',
                          args={
                              'action': 'edit',
                              'cancel': True,
                              'id': '1',
                              'title': "New Report edited",
                              'query': "SELECT 2",
                              'description': "The description edited"
                          })

        self.assertRaises(RequestDone, self.report_module.process_request, req)
        report = Report(self.env, 1)
        self.assertEqual("Active Tickets", report.title)
        self.assertEqual(
            " * List all active tickets by priority.\n"
            " * Color each row based on priority.\n", report.description)
        self.assertIn("SELECT p.value AS __color__", report.query)
        self.assertNotIn("Your changes have been saved.",
                         req.chrome['notices'])
Ejemplo n.º 23
0
    def test_modify_summary_and_description(self):
        """The ticket summary and description cannot be modified."""
        req = MockRequest(self.env,
                          authname='has_ta_&_bm',
                          method='POST',
                          path_info='/batchmodify',
                          args={
                              'batchmod_value_summary': 'the new summary',
                              'batchmod_value_description':
                              'the new description',
                              'batchmod_value_comment': '',
                              'action': 'leave',
                              'selected_tickets': '1,2',
                          })

        module = BatchModifyModule(self.env)
        self.assertTrue(module.match_request(req))
        with self.assertRaises(RequestDone):
            module.process_request(req)

        self.assertFieldValue(1, 'description', 'the desc')
        self.assertFieldValue(1, 'summary', 'Ticket 1')
        self.assertFieldValue(2, 'description', 'the desc')
        self.assertFieldValue(2, 'summary', 'Ticket 2')
Ejemplo n.º 24
0
 def test_follow_copy(self):
     req = MockRequest(self.env,
                       path_info='/log/mock/file',
                       args={
                           'rev': '43',
                           'limit': '4',
                           'mode': 'follow_copy'
                       })
     template, data = self.process_request(req)
     items = data['items']
     self.assertEqual(5, len(items))
     self.assertEqual([43, 40, 37, 34, 31], [item['rev'] for item in items])
     self.assertEqual(['file', 'file', 'file-old', 'file-old', 'file-old'],
                      [item['path'] for item in items])
     self.assertEqual([1, 1, 2, 2, 2], [item['depth'] for item in items])
     self.assertEqual([None, None, 'file-old', None, None],
                      [item.get('copyfrom_path') for item in items])
     self.assertEqual(['edit', 'move', 'edit', 'edit', None],
                      [item['change'] for item in items])
     links = req.chrome['links']['next']
     self.assertEqual(
         '/trac.cgi/log/mock/file-old?limit=4&rev=31&'
         'mode=follow_copy', links[0]['href'])
     self.assertEqual(1, len(links))
Ejemplo n.º 25
0
 def test_revranges_1_with_limit(self):
     req = MockRequest(self.env,
                       path_info='/log/mock/file',
                       args={
                           'revs': '70,79-82,94-100',
                           'limit': '4'
                       })
     template, data = self.process_request(req)
     items = data['items']
     self.assertEqual(6, len(items))
     self.assertEqual([100, 97, 94, 91, 82, 79],
                      [item['rev'] for item in items])
     self.assertEqual(['file'] * 6, [item['path'] for item in items])
     self.assertEqual([1] * 6, [item['depth'] for item in items])
     self.assertEqual([None] * 6,
                      [item.get('copyfrom_path') for item in items])
     self.assertEqual(['delete', 'edit', 'edit', None, 'edit', None],
                      [item['change'] for item in items])
     self.assertIn('next', req.chrome['links'])
     links = req.chrome['links']['next']
     self.assertEqual(
         '/trac.cgi/log/mock/file?limit=4&revs=70%2C79&'
         'rev=79&mode=stop_on_copy', links[0]['href'])
     self.assertEqual(1, len(links))
Ejemplo n.º 26
0
    def test_change_log_type(self):
        """Change the log type."""
        logging_config = self.env.config['logging']
        log_type = logging_config.get('log_type')
        log_file = logging_config.get('log_file')
        log_level = logging_config.get('log_level')
        req = MockRequest(self.env,
                          path_info='/admin/general/logging',
                          method='POST',
                          args={
                              'log_type': 'file',
                              'log_level': log_level,
                              'log_file': log_file
                          })
        mod = AdminModule(self.env)

        self.assertTrue(mod.match_request(req))
        self.assertRaises(RequestDone, mod.process_request, req)

        self.assertEqual(0, len(req.chrome['warnings']))
        self.assertNotEqual('file', log_type)
        self.assertEqual('file', logging_config.get('log_type'))
        self.assertEqual(log_level, logging_config.get('log_level'))
        self.assertEqual(log_file, logging_config.get('log_file'))
Ejemplo n.º 27
0
    def test_require_post_method(self):
        """Request must use POST method."""
        module = BatchModifyModule(self.env)
        req = MockRequest(self.env, method='GET', path_info='/batchmodify')
        req.session['query_href'] = req.href.query()

        self.assertTrue(module.match_request(req))
        with self.assertRaises(HTTPBadRequest):
            module.process_request(req)

        req = MockRequest(self.env,
                          method='POST',
                          path_info='/batchmodify',
                          args={'selected_tickets': ''})
        req.session['query_href'] = req.href.query()

        self.assertTrue(module.match_request(req))
        with self.assertRaises(RequestDone):
            module.process_request(req)
Ejemplo n.º 28
0
    def test_clear(self):
        req = MockRequest(self.env,
                          method='GET',
                          path_info='/report',
                          args={'action': 'clear'})
        req.session['query_href'] = req.href.query()
        req.session['query_tickets'] = '42'
        self.assertTrue(self.report_module.match_request(req))
        self.assertEqual('report_list.html',
                         self.report_module.process_request(req)[0])
        self.assertIn('query_href', req.session)
        self.assertIn('query_tickets', req.session)

        req = MockRequest(self.env,
                          method='POST',
                          path_info='/report',
                          args={'action': 'clear'})
        self.assertTrue(self.report_module.match_request(req))
        self.assertRaises(RequestDone, self.report_module.process_request, req)
        self.assertNotIn('query_href', req.session)
        self.assertNotIn('query_tickets', req.session)
Ejemplo n.º 29
0
    def test_ticket_manipulators(self):
        """The ticket manipulators are called to valid the ticket."""
        module = BatchModifyModule(self.env)
        self._insert_component('component3')
        self._insert_component('component4')
        self.env.enable_component(self.ticket_manipulators[0])
        self.env.enable_component(self.ticket_manipulators[1])
        req1 = MockRequest(self.env,
                           authname='has_bm',
                           method='POST',
                           path_info='/batchmodify',
                           args={
                               'batchmod_value_component': 'component3',
                               'action': 'leave',
                               'selected_tickets': '1,2',
                           })

        self.assertTrue(module.match_request(req1))
        with self.assertRaises(RequestDone):
            module.process_request(req1)

        self.assertEqual(1, len(req1.chrome['warnings']))
        self.assertEqual(
            "The ticket field <strong>component</strong> is "
            "invalid: Invalid Component", unicode(req1.chrome['warnings'][0]))
        self.assertFieldValue(1, 'component', 'component1')
        self.assertFieldValue(2, 'component', 'component2')

        req2 = MockRequest(self.env,
                           authname='has_bm',
                           method='POST',
                           path_info='/batchmodify',
                           args={
                               'batchmod_value_component': 'component4',
                               'action': 'leave',
                               'selected_tickets': '1,2',
                           })

        self.assertTrue(module.match_request(req2))
        with self.assertRaises(RequestDone):
            module.process_request(req2)

        self.assertEqual([], req2.chrome['warnings'])
        self.assertFieldValue(1, 'component', 'component4')
        self.assertFieldValue(2, 'component', 'component4')

        req3 = MockRequest(self.env,
                           authname='has_bm',
                           method='POST',
                           path_info='/batchmodify',
                           args={
                               'batchmod_value_comment':
                               'this comment has the badword!',
                               'batchmod_value_component': 'component3',
                               'action': 'leave',
                               'selected_tickets': '1,2',
                           })

        self.assertTrue(module.match_request(req3))
        with self.assertRaises(RequestDone):
            module.process_request(req3)

        self.assertEqual(
            "The ticket comment is invalid: Word is not allowed "
            "in comment", unicode(req3.chrome['warnings'][0]))
        self.assertFieldValue(1, 'component', 'component4')
        self.assertFieldValue(2, 'component', 'component4')
Ejemplo n.º 30
0
    def test_timeline_events(self):
        """Regression test for #11288"""
        req1 = MockRequest(self.env)
        tktmod = web_ui.TicketModule(self.env)
        now = datetime_now(utc)
        start = now - timedelta(hours=1)
        stop = now + timedelta(hours=1)
        events = tktmod.get_timeline_events(req1, start, stop,
                                            ['ticket_details'])
        self.assertTrue(all(ev[0] != 'batchmodify' for ev in events))

        prio_ids = {}
        for i in xrange(20):
            priority = ('', 'minor', 'major', 'critical')[i % 4]
            t = insert_ticket(self.env,
                              summary='Ticket %d' % i,
                              priority=priority)
            prio_ids.setdefault(t['priority'], []).append(t.id)
        tktids = prio_ids['critical'] + prio_ids['major'] + \
                 prio_ids['minor'] + prio_ids['']

        req2 = MockRequest(self.env,
                           method='POST',
                           authname='has_ta_&_bm',
                           path_info='/batchmodify',
                           args={
                               'batchmod_value_summary':
                               'batch updated ticket',
                               'batchmod_value_owner':
                               'ticket11288',
                               'batchmod_value_reporter':
                               'ticket11288',
                               'action':
                               'leave',
                               'selected_tickets':
                               ','.join(str(t) for t in tktids),
                           })

        batch = BatchModifyModule(self.env)
        self.assertTrue(batch.match_request(req2))
        with self.assertRaises(RequestDone):
            batch.process_request(req2)

        # shuffle ticket_change records
        with self.env.db_transaction as db:
            rows = db('SELECT * FROM ticket_change')
            db.execute('DELETE FROM ticket_change')
            rows = rows[0::4] + rows[1::4] + rows[2::4] + rows[3::4]
            db.executemany(
                'INSERT INTO ticket_change VALUES (%s)' % ','.join(
                    ('%s', ) * len(rows[0])), rows)

        events = tktmod.get_timeline_events(req1, start, stop,
                                            ['ticket_details'])
        events = [ev for ev in events if ev[0] == 'batchmodify']
        self.assertEqual(1, len(events))
        batch_ev = events[0]
        self.assertEqual('has_ta_&_bm', batch_ev[2])
        self.assertEqual(tktids, batch_ev[3][0])
        self.assertEqual('updated', batch_ev[3][1])

        context = web_context(req2)
        self.assertEqual(
            req2.href.query(id=','.join(str(t) for t in tktids)),
            tktmod.render_timeline_event(context, 'url', batch_ev))
Ejemplo n.º 31
0
 def test_default_repository_not_configured(self):
     """Test for regression of http://trac.edgewall.org/ticket/11599."""
     req = MockRequest(self.env, args={'new_path': '/'})
     self.assertRaises(TracError, self.cm.process_request, req)
Ejemplo n.º 32
0
 def setUp(self):
     self.env = EnvironmentStub(enable=[ReStructuredTextRenderer])
     self.renderer = ReStructuredTextRenderer(self.env)
     self.req = MockRequest(self.env)
     self.context = web_context(self.req)
Ejemplo n.º 33
0
 def test_session_email_set_but_invalid(self):
     req = MockRequest(self.env)
     req.session.last_visit = 42
     req.session['email'] = 'joey'
     rv = self.strategy.test(req, None, None, '127.0.0.1')
     self.assertEqual((2, "Existing session found"), rv)