Пример #1
0
 def test_add_component_with_spaces(self):
     cap = ComponentAdminPanel(self.env)
     name = 'comp on ent 4'
     self.assertRaises(ResourceNotFound, Component, self.env, name)
     req = MockRequest(self.env,
                       method='POST',
                       args={
                           'name': ' comp \t on \t ent \t 4 ',
                           'owner': 'user4',
                           'add': True
                       })
     self.assertRaises(RequestDone, cap.render_admin_panel, req, 'ticket',
                       'component', None)
     self.assertIn('The component "comp on ent 4" has been added.',
                   req.chrome['notices'])
     component = Component(self.env, name)
     self.assertEqual(name, component.name)
     with self.assertRaises(ResourceExistsError) as cm:
         cap.render_admin_panel(req, 'ticket', 'component', None)
     self.assertIn('Component "comp on ent 4" already exists',
                   unicode(cm.exception))
Пример #2
0
    def test_save_component(self):
        cap = ComponentAdminPanel(self.env)
        old_name = 'component2'
        old_owner = 'somebody'
        new_name = 'comp on ent 2'
        new_owner = 'user2'
        component = Component(self.env, old_name)
        self.assertEqual(old_name, component.name)
        self.assertEqual(old_owner, component.owner)

        req = MockRequest(self.env,
                          method='POST',
                          args={
                              'name': ' component1 ',
                              'owner': 'somebody',
                              'save': True
                          })
        with self.assertRaises(ResourceExistsError) as cm:
            cap.render_admin_panel(req, 'ticket', 'component', old_name)
        self.assertIn('Component "component1" already exists',
                      unicode(cm.exception))

        req = MockRequest(self.env,
                          method='POST',
                          args={
                              'name': ' comp \t on \t ent \t 2 ',
                              'owner': new_owner,
                              'save': True
                          })
        self.assertRaises(RequestDone, cap.render_admin_panel, req, 'ticket',
                          'component', old_name)
        self.assertIn('Your changes have been saved.', req.chrome['notices'])

        component = Component(self.env, new_name)
        self.assertEqual(new_name, component.name)
        self.assertEqual(new_owner, component.owner)
        self.assertRaises(ResourceNotFound, cap.render_admin_panel, req,
                          'ticket', 'component', old_name)
        self.assertRaises(ResourceNotFound, Component, self.env, old_name)