示例#1
0
 def test_post_process_request_error_handling(self):
     """Exception not raised in post_process_request error handling.
     """
     module = BatchModifyModule(self.env)
     req = MockRequest(self.env, path_info='/query')
     self.assertEqual((None, None, None),
                      module.post_process_request(req, None, None, None))
示例#2
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))
示例#3
0
 def test_ignore_summary_reporter_and_description(self):
     """These cannot be added through the UI, but if somebody tries
     to build their own POST data they will be ignored."""
     batch = BatchModifyModule(self.env)
     self.req.args = {}
     self.req.args['batchmod_value_summary'] = 'test ticket'
     self.req.args['batchmod_value_reporter'] = 'anonymous'
     self.req.args['batchmod_value_description'] = 'synergize the widgets'
     values = batch._get_new_ticket_values(self.req)
     self.assertEqual(len(values), 0)
示例#4
0
 def test_ignore_summary_reporter_and_description(self):
     """These cannot be added through the UI, but if somebody tries
     to build their own POST data they will be ignored."""
     batch = BatchModifyModule(self.env)
     self.req.args = {}
     self.req.args['batchmod_value_summary'] = 'test ticket'
     self.req.args['batchmod_value_reporter'] = 'anonymous'
     self.req.args['batchmod_value_description'] = 'synergize the widgets'
     values = batch._get_new_ticket_values(self.req)
     self.assertEqual(len(values), 0)
示例#5
0
文件: batch.py 项目: pkdevbox/trac
    def test_save_comment(self):
        """Comments are saved to all selected tickets."""
        first_ticket_id = self._insert_ticket('Test 1', reporter='joe')
        second_ticket_id = self._insert_ticket('Test 2', reporter='joe')
        selected_tickets = [first_ticket_id, second_ticket_id]

        batch = BatchModifyModule(self.env)
        batch._save_ticket_changes(self.req, selected_tickets, {}, 'comment',
                                   'leave')

        self.assertCommentAdded(first_ticket_id, 'comment')
        self.assertCommentAdded(second_ticket_id, 'comment')
示例#6
0
    def test_save_comment(self):
        """Comments are saved to all selected tickets."""
        first_ticket_id = self._insert_ticket('Test 1', reporter='joe')
        second_ticket_id = self._insert_ticket('Test 2', reporter='joe')
        selected_tickets = [first_ticket_id, second_ticket_id]

        batch = BatchModifyModule(self.env)
        batch._save_ticket_changes(self.req, selected_tickets, {}, 'comment',
                                   'leave')

        self.assertCommentAdded(first_ticket_id, 'comment')
        self.assertCommentAdded(second_ticket_id, 'comment')
示例#7
0
文件: batch.py 项目: khoi-huynh/trac
    def test_require_post_method(self):
        batch = BatchModifyModule(self.env)

        req = MockRequest(self.env, method='GET', path_info='/batchmodify')
        req.session['query_href'] = req.href.query()
        self.assertTrue(batch.match_request(req))
        self.assertRaises(HTTPBadRequest, batch.process_request, req)

        req = MockRequest(self.env, method='POST', path_info='/batchmodify',
                          args={'selected_tickets': ''})
        req.session['query_href'] = req.href.query()
        self.assertTrue(batch.match_request(req))
        self.assertRaises(RequestDone, batch.process_request, req)
示例#8
0
    def test_save_values(self):
        """Changed values are saved to all tickets."""
        first_ticket_id = self._insert_ticket('Test 1', reporter='joe',
                                              component='foo')
        second_ticket_id = self._insert_ticket('Test 2', reporter='joe')
        selected_tickets = [first_ticket_id, second_ticket_id]
        new_values = { 'component' : 'bar' }

        batch = BatchModifyModule(self.env)
        batch._save_ticket_changes(self.req, selected_tickets, new_values, '',
                                   'leave')

        self.assertFieldChanged(first_ticket_id, 'component', 'bar')
        self.assertFieldChanged(second_ticket_id, 'component', 'bar')
示例#9
0
    def test_validate_ticket_custom_field_max_size(self):
        """The [ticket-custom] max_size attribute is enforced."""
        module = BatchModifyModule(self.env)
        req1 = MockRequest(self.env, authname='has_bm', method='POST',
                           path_info='/batchmodify', args={
            'batchmod_value_text1': '12345',
            'action': 'leave',
            'selected_tickets': '1,2',
        })
        req2 = MockRequest(self.env, authname='has_bm', method='POST',
                           path_info='/batchmodify', args={
            'batchmod_value_text1': '123456',
            'action': 'leave',
            'selected_tickets': '1,2',
        })

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

        self.assertEqual([], req1.chrome['warnings'])
        self.assertEqual('12345', model.Ticket(self.env, 1)['text1'])
        self.assertEqual('12345', model.Ticket(self.env, 2)['text1'])

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

        self.assertEqual(1, len(req2.chrome['warnings']))
        self.assertEqual("The ticket field <strong>Text1</strong> is "
                         "invalid: Must be less than or equal to 5 "
                         "characters", unicode(req2.chrome['warnings'][0]))
        self.assertEqual('12345', model.Ticket(self.env, 1)['text1'])
        self.assertEqual('12345', model.Ticket(self.env, 2)['text1'])
示例#10
0
    def test_validate_ticket_comment_size(self):
        """The [ticket] max_comment_size value is enforced."""
        module = BatchModifyModule(self.env)
        self.env.config.set('ticket', 'max_comment_size', 5)
        req1 = MockRequest(self.env, authname='has_bm', method='POST',
                           path_info='/batchmodify', args={
            'batchmod_value_comment': '12345',
            'action': 'leave',
            'selected_tickets': '1,2',
        })
        req2 = MockRequest(self.env, authname='has_bm', method='POST',
                           path_info='/batchmodify', args={
            'batchmod_value_comment': '123456',
            'action': 'leave',
            'selected_tickets': '1,2',
        })

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

        self.assertEqual([], req1.chrome['warnings'])
        self.assertCommentAdded(1, '12345')
        self.assertCommentAdded(2, '12345')

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

        self.assertEqual(1, len(req2.chrome['warnings']))
        self.assertEqual("The ticket comment is invalid: Must be less than or "
                         "equal to 5 characters",
                         unicode(req2.chrome['warnings'][0]))
        self.assertEqual(1, len(model.Ticket(self.env, 1).get_changelog()))
        self.assertEqual(1, len(model.Ticket(self.env, 2).get_changelog()))
示例#11
0
文件: batch.py 项目: pkdevbox/trac
    def test_save_values(self):
        """Changed values are saved to all tickets."""
        first_ticket_id = self._insert_ticket('Test 1', reporter='joe',
                                              component='foo')
        second_ticket_id = self._insert_ticket('Test 2', reporter='joe')
        selected_tickets = [first_ticket_id, second_ticket_id]
        new_values = {'component': 'bar'}

        batch = BatchModifyModule(self.env)
        batch._save_ticket_changes(self.req, selected_tickets, new_values, '',
                                   'leave')

        self.assertFieldChanged(first_ticket_id, 'component', 'bar')
        self.assertFieldChanged(second_ticket_id, 'component', 'bar')
示例#12
0
    def test_timeline_events(self):
        """Regression test for #11288"""
        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(self.req, start, stop,
                                            ['ticket_details'])
        self.assertEqual(True, all(ev[0] != 'batchmodify' for ev in events))

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

        new_values = {
            'summary': 'batch updated ticket',
            'owner': 'ticket11288',
            'reporter': 'ticket11288'
        }
        batch = BatchModifyModule(self.env)
        batch._save_ticket_changes(self.req, tktids, new_values, '', 'leave')
        # 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(self.req, 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('anonymous', batch_ev[2])
        self.assertEqual(tktids, batch_ev[3][0])
        self.assertEqual('updated', batch_ev[3][1])

        context = web_context(self.req)
        self.assertEqual(
            self.req.href.query(id=','.join(str(t) for t in tktids)),
            tktmod.render_timeline_event(context, 'url', batch_ev))
示例#13
0
    def test_save_list_fields(self):
        batch = BatchModifyModule(self.env)
        with self.env.db_transaction:
            ticket_ids = [
                self._insert_ticket('Test 1', reporter='joe', keywords='foo'),
                self._insert_ticket('Test 2', reporter='joe', keywords='baz'),
            ]

        self.req.args = {
            'action': 'leave',
            'batchmod_mode_keywords': '+',  # add
            'batchmod_primary_keywords': 'baz new',
            'batchmod_secondary_keywords': '*****'
        }
        batch._save_ticket_changes(self.req, ticket_ids, {}, '', 'leave')
        self.assertFieldChanged(ticket_ids[0], 'keywords', 'foo, baz, new')
        self.assertFieldChanged(ticket_ids[1], 'keywords', 'baz, new')

        self.req.args = {
            'action': 'leave',
            'batchmod_mode_keywords': '+-',  # add / remove
            'batchmod_primary_keywords': 'one two three',
            'batchmod_secondary_keywords': 'baz missing'
        }
        batch._save_ticket_changes(self.req, ticket_ids, {}, '', 'leave')
        self.assertFieldChanged(ticket_ids[0], 'keywords',
                                'foo, new, one, two, three')
        self.assertFieldChanged(ticket_ids[1], 'keywords',
                                'new, one, two, three')

        self.req.args = {
            'action': 'leave',
            'batchmod_mode_keywords': '-',  # remove
            'batchmod_primary_keywords': 'new two',
            'batchmod_secondary_keywords': '*****'
        }
        batch._save_ticket_changes(self.req, ticket_ids, {}, '', 'leave')
        self.assertFieldChanged(ticket_ids[0], 'keywords', 'foo, one, three')
        self.assertFieldChanged(ticket_ids[1], 'keywords', 'one, three')

        self.req.args = {
            'action': 'leave',
            'batchmod_mode_keywords': '=',  # set
            'batchmod_primary_keywords': 'orange',
            'batchmod_secondary_keywords': '*****'
        }
        batch._save_ticket_changes(self.req, ticket_ids, {}, '', 'leave')
        self.assertFieldChanged(ticket_ids[0], 'keywords', 'orange')
        self.assertFieldChanged(ticket_ids[1], 'keywords', 'orange')
示例#14
0
文件: batch.py 项目: pkdevbox/trac
    def test_action_with_state_change(self):
        """Actions can have change status."""
        self.env.config.set('ticket-workflow', 'embiggen', '* -> big')

        first_ticket_id = self._insert_ticket('Test 1', reporter='joe',
                                              status='small')
        second_ticket_id = self._insert_ticket('Test 2', reporter='joe')
        selected_tickets = [first_ticket_id, second_ticket_id]

        batch = BatchModifyModule(self.env)
        batch._save_ticket_changes(self.req, selected_tickets, {}, '',
                                   'embiggen')

        self.assertFieldChanged(first_ticket_id, 'status', 'big')
        self.assertFieldChanged(second_ticket_id, 'status', 'big')
示例#15
0
    def test_action_with_state_change(self):
        """Actions can have change status."""
        self.env.config.set('ticket-workflow', 'embiggen', '* -> big')

        first_ticket_id = self._insert_ticket('Test 1', reporter='joe',
                                              status='small')
        second_ticket_id = self._insert_ticket('Test 2', reporter='joe')
        selected_tickets = [first_ticket_id, second_ticket_id]

        batch = BatchModifyModule(self.env)
        batch._save_ticket_changes(self.req, selected_tickets, {}, '',
                                   'embiggen')

        self.assertFieldChanged(first_ticket_id, 'status', 'big')
        self.assertFieldChanged(second_ticket_id, 'status', 'big')
示例#16
0
文件: batch.py 项目: khoi-huynh/trac
    def test_redirect_to_query_href_in_req_args(self):
        redirect_listener_args = []
        def redirect_listener(req, url, permanent):
            redirect_listener_args[:] = (url, permanent)

        batch = 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(batch.match_request(req))
        self.assertRaises(RequestDone, batch.process_request, req)
        self.assertEqual([query_opened_tickets, False], redirect_listener_args)
示例#17
0
    def test_post_process_request_add_template_data(self):
        """Template data added by post_process_request."""
        self._insert_ticket("Ticket 1", status='new')
        self._insert_ticket("Ticket 2", status='new')
        req = MockRequest(self.env, path_info='/query')
        req.session['query_href'] = '/query?status=!closed'
        batch = BatchModifyModule(self.env)
        data_in = {'tickets': [{'id': 1}, {'id': 2}]}

        data_out = batch.post_process_request(req, 'query.html', data_in,
                                              'text/html')[1]

        self.assertTrue(data_out['batch_modify'])
        self.assertEqual(
            ['leave', 'resolve', 'reassign', 'acknowledge', 'accept'],
            [a[0] for a in data_out['action_controls']])
示例#18
0
    def test_action_with_state_change(self):
        """Actions can have change status."""
        req = MockRequest(self.env, method='POST', authname='has_bm',
                          path_info='/batchmodify', args={
            'action': 'acknowledge',
            'batchmod_value_comment': '',
            'selected_tickets': '1,2',
        })

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

        self.assertFieldValue(1, 'status', 'acknowledged')
        self.assertFieldValue(2, 'status', 'acknowledged')
示例#19
0
    def test_save_comment(self):
        """Comments are saved to all selected tickets."""
        req = MockRequest(self.env, method='POST', authname='has_bm',
                          path_info='/batchmodify', args={
            'batchmod_value_comment': 'the comment',
            'action': 'leave',
            'selected_tickets': '1,2',
        })

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

        self.assertCommentAdded(1, 'the comment')
        self.assertCommentAdded(2, 'the comment')
示例#20
0
    def test_list_fields_set(self):
        req = MockRequest(self.env, method='POST', authname='has_bm',
                          path_info='/batchmodify', args={
            'batchmod_mode_keywords': '=',
            'batchmod_primary_keywords': 'orange',
            'batchmod_secondary_keywords': '*****',
            'action': 'leave',
            'selected_tickets': '1,2',
        })

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

        self.assertFieldValue(1, 'keywords', 'orange')
        self.assertFieldValue(2, 'keywords', 'orange')
示例#21
0
    def test_list_fields_addrem(self):
        req = MockRequest(self.env, method='POST', authname='has_bm',
                          path_info='/batchmodify', args={
            'batchmod_mode_keywords': '+-',
            'batchmod_primary_keywords': 'one three four',
            'batchmod_secondary_keywords': 'baz missing',
            'action': 'leave',
            'selected_tickets': '1,2',
        })

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

        self.assertFieldValue(1, 'keywords', 'foo, one, three, four')
        self.assertFieldValue(2, 'keywords', 'two, one, three, four')
示例#22
0
    def test_modify_reporter_without_ticket_admin(self):
        """User without TICKET_ADMIN cannot batch modify the reporter."""
        req = MockRequest(self.env, method='POST', authname='has_bm',
                          path_info='/batchmodify', args={
            'batchmod_value_reporter': 'user2',
            '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, 'reporter', 'user1')
        self.assertFieldValue(2, 'reporter', 'user1')
示例#23
0
    def test_validate_select_fields(self):
        """The select field values are validated."""
        req = MockRequest(self.env, authname='has_bm', method='POST',
                          path_info='/batchmodify', args={
            'batchmod_value_component': 'component3',
            '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.assertEqual(1, len(req.chrome['warnings']))
        self.assertEqual('The ticket field <strong>component</strong> is '
                         'invalid: "component3" is not a valid value',
                         unicode(req.chrome['warnings'][0]))
示例#24
0
文件: batch.py 项目: pkdevbox/trac
    def test_action_with_side_effects(self):
        """Actions can have operations with side effects."""
        self.env.config.set('ticket-workflow', 'buckify', '* -> *')
        self.env.config.set('ticket-workflow', 'buckify.operations',
                                               'set_owner')
        self.req.args = {'action_buckify_reassign_owner': 'buck'}

        first_ticket_id = self._insert_ticket('Test 1', reporter='joe',
                                              owner='foo')
        second_ticket_id = self._insert_ticket('Test 2', reporter='joe')
        selected_tickets = [first_ticket_id, second_ticket_id]

        batch = BatchModifyModule(self.env)
        batch._save_ticket_changes(self.req, selected_tickets, {}, '',
                                   'buckify')

        self.assertFieldChanged(first_ticket_id, 'owner', 'buck')
        self.assertFieldChanged(second_ticket_id, 'owner', 'buck')
示例#25
0
文件: batch.py 项目: khoi-huynh/trac
    def test_action_with_side_effects(self):
        """Actions can have operations with side effects."""
        self.env.config.set('ticket-workflow', 'buckify', '* -> *')
        self.env.config.set('ticket-workflow', 'buckify.operations',
                                               'set_owner')
        self.req.args = {'action_buckify_reassign_owner': 'buck'}

        first_ticket_id = self._insert_ticket('Test 1', reporter='joe',
                                              owner='foo')
        second_ticket_id = self._insert_ticket('Test 2', reporter='joe')
        selected_tickets = [first_ticket_id, second_ticket_id]

        batch = BatchModifyModule(self.env)
        batch._save_ticket_changes(self.req, selected_tickets, {}, '',
                                   'buckify')

        self.assertFieldChanged(first_ticket_id, 'owner', 'buck')
        self.assertFieldChanged(second_ticket_id, 'owner', 'buck')
示例#26
0
    def test_action_with_side_effects(self):
        """Actions can have operations with side effects."""
        req = MockRequest(self.env, method='POST', authname='has_bm',
                          path_info='/batchmodify', args={
            'action': 'reassign',
            'action_reassign_reassign_owner': 'user3',
            'batchmod_value_comment': '',
            'selected_tickets': '1,2',
        })

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

        self.assertFieldValue(1, 'owner', 'user3')
        self.assertFieldValue(2, 'owner', 'user3')
        self.assertFieldValue(1, 'status', 'assigned')
        self.assertFieldValue(2, 'status', 'assigned')
示例#27
0
文件: batch.py 项目: pkdevbox/trac
    def test_timeline_events(self):
        """Regression test for #11288"""
        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(self.req, start, stop,
                                            ['ticket_details'])
        self.assertEqual(True, all(ev[0] != 'batchmodify' for ev in events))

        ids = []
        for i in xrange(20):
            ticket = Ticket(self.env)
            ticket['summary'] = 'Ticket %d' % i
            ids.append(ticket.insert())
        ids.sort()
        new_values = {'summary': 'batch updated ticket',
                      'owner': 'ticket11288', 'reporter': 'ticket11288'}
        batch = BatchModifyModule(self.env)
        batch._save_ticket_changes(self.req, ids, new_values, '', 'leave')
        # 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(self.req, 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('anonymous', batch_ev[2])
        self.assertEqual(ids, sorted(batch_ev[3][0]))
        self.assertEqual('updated', batch_ev[3][1])

        context = web_context(self.req)
        self.assertEqual(
            self.req.href.query(id=','.join(str(t) for t in ids)),
            tktmod.render_timeline_event(context, 'url', batch_ev))
示例#28
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')
示例#29
0
    def test_actions_added_by_additional_ticket_action_controllers(self):
        """Actions added by custom ticket action controller.

        Regression test for #12938.
        """
        class TestOperation(Component):
            """TicketActionController that directly provides an action."""
            implements(api.ITicketActionController)

            def get_ticket_actions(self, req, ticket):
                return [(0, 'test')]

            def get_all_status(self):
                return []

            def render_ticket_action_control(self, req, ticket, action):
                return "test", '', "This is a null action."

            def get_ticket_changes(self, req, ticket, action):
                return {}

            def apply_action_side_effects(self, req, ticket, action):
                pass

        self._insert_ticket("Ticket 1", status='new')
        self._insert_ticket("Ticket 2", status='new')
        req = MockRequest(self.env, path_info='/query')
        req.session['query_href'] = '/query?status=!closed'
        batch = BatchModifyModule(self.env)
        data_in = {'tickets': [{'id': 1}, {'id': 2}]}
        self.env.config.set('ticket', 'workflow',
                            'ConfigurableTicketWorkflow, TestOperation')
        self.env.enable_component(TestOperation)

        data_out = batch.post_process_request(req, 'query.html', data_in,
                                              'text/html')[1]

        self.assertEqual(
            ['leave', 'test', 'resolve', 'reassign', 'acknowledge', 'accept'],
            [a[0] for a in data_out['action_controls']])
示例#30
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)
示例#31
0
文件: batch.py 项目: khoi-huynh/trac
    def test_modify_reporter_without_ticket_admin(self):
        """User without TICKET_ADMIN cannot batch modify the reporter."""
        self._insert_ticket('Ticket 1', reporter='user1')
        self._insert_ticket('Ticket 2', reporter='user1')
        req = MockRequest(self.env, method='POST', authname='has_bm', args={
            'batchmod_value_reporter': 'user2',
            'batchmod_value_comment': '',
            'action': 'leave',
            'selected_tickets': '1,2',
        })

        bmm = BatchModifyModule(self.env)
        self.assertRaises(RequestDone, bmm.process_request, req)
        self.assertFieldChanged(1, 'reporter', 'user1')
        self.assertFieldChanged(2, 'reporter', 'user1')
示例#32
0
    def test_validate_time_fields(self):
        """The time fields are validated."""
        module = BatchModifyModule(self.env)
        req1 = MockRequest(self.env,
                           authname='has_bm',
                           method='POST',
                           path_info='/batchmodify',
                           args={
                               'batchmod_value_time1': '2016-01-02T12:34:56Z',
                               'action': 'leave',
                               'selected_tickets': '1,2',
                           })
        req2 = MockRequest(self.env,
                           authname='has_bm',
                           method='POST',
                           path_info='/batchmodify',
                           args={
                               'batchmod_value_time1': 'invalid',
                               'action': 'leave',
                               'selected_tickets': '1,2',
                           })
        dt = datetime(2016, 1, 2, 12, 34, 56, tzinfo=utc)

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

        self.assertEqual(dt, model.Ticket(self.env, 1)['time1'])
        self.assertEqual(dt, model.Ticket(self.env, 2)['time1'])
        self.assertEqual([], req1.chrome['warnings'])

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

        self.assertEqual(1, len(req2.chrome['warnings']))
        self.assertRegexpMatches(
            unicode(req2.chrome['warnings'][0]),
            'The ticket field <strong>Time1</strong> is invalid: "invalid" '
            'is an invalid date, or the date format is not known. '
            'Try "[^"]+" or "[^"]+" instead.')
        self.assertEqual(dt, model.Ticket(self.env, 1)['time1'])
        self.assertEqual(dt, model.Ticket(self.env, 2)['time1'])
示例#33
0
文件: batch.py 项目: pkdevbox/trac
 def test_no_selected_tickets(self):
     """If nothing is selected, the return value is the empty list."""
     self.req.args = {'selected_tickets': ''}
     batch = BatchModifyModule(self.env)
     selected_tickets = batch._get_selected_tickets(self.req)
     self.assertEqual(selected_tickets, [])
示例#34
0
文件: batch.py 项目: pkdevbox/trac
 def _change_list_test_helper(self, original, new, new2, mode):
     batch = BatchModifyModule(self.env)
     return batch._change_list(original, new, new2, mode)
示例#35
0
文件: batch.py 项目: pkdevbox/trac
 def test_add_batchmod_value_data_from_request(self):
     batch = BatchModifyModule(self.env)
     self.req.args = {'batchmod_value_milestone': 'milestone1'}
     values = batch._get_new_ticket_values(self.req)
     self.assertEqual(values['milestone'], 'milestone1')
示例#36
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')
示例#37
0
 def _change_list_test_helper(self, original, new, new2, mode):
     batch = BatchModifyModule(self.env)
     return batch._change_list(original, new, new2, mode)
示例#38
0
 def test_no_selected_tickets(self):
     """If nothing is selected, the return value is the empty list."""
     self.req.args = {'selected_tickets': ''}
     batch = BatchModifyModule(self.env)
     selected_tickets = batch._get_selected_tickets(self.req)
     self.assertEqual(selected_tickets, [])
示例#39
0
 def test_selected_tickets(self):
     self.req.args = {'selected_tickets': '1,2,3'}
     batch = BatchModifyModule(self.env)
     selected_tickets = batch._get_selected_tickets(self.req)
     self.assertEqual(selected_tickets, ['1', '2', '3'])
示例#40
0
文件: batch.py 项目: pkdevbox/trac
 def test_selected_tickets(self):
     self.req.args = {'selected_tickets': '1,2,3'}
     batch = BatchModifyModule(self.env)
     selected_tickets = batch._get_selected_tickets(self.req)
     self.assertEqual(selected_tickets, ['1', '2', '3'])