def test_request4(self): """test request validation (incoming + outgoing)""" Request.SCHEMA = self.fixture_file('request_simple.xsd') self.assertRaises(etree.DocumentInvalid, Request.find, '456') req = Request() req.add_action(type='submit') req.add_invalid(attr='inv') # no http request is made because validation fails self.assertRaises(etree.DocumentInvalid, req.store) req = Request() req.add_action(type='submit') # check that validation is ok req.validate() # we get an invalid response self.assertRaises(etree.DocumentInvalid, req.store)
def create(cls, renderer, submit, changedevel, role, grouprole, delete, info): """Creates a new request.""" global SHOW_TEMPLATE request = Request() message = info.message if message is None: message = edit_message() cls._create_submit_actions(request, submit) cls._create_changedevel_actions(request, changedevel) cls._create_role_actions(request, role) cls._create_grouprole_actions(request, grouprole) cls._create_delete_actions(request, delete) request.description = message request.store() renderer.render(SHOW_TEMPLATE, request=request)
def test_request1(self): """get a request""" req = Request.find('123') self.assertTrue(len(req.action[:]) == 2) self.assertEqual(req.action[0].get('type'), 'submit') self.assertEqual(req.action[0].source.get('package'), 'abc') self.assertEqual(req.action[0].source.get('project'), 'xyz') self.assertEqual(req.action[0].options.sourceupdate, 'cleanup') self.assertEqual(req.action[0].options.updatelink, '1') self.assertEqual(req.action[1].get('type'), 'add_role') self.assertEqual(req.action[1].target.get('project'), 'home:foo') self.assertEqual(req.action[1].person.get('name'), 'bar') self.assertEqual(req.action[1].person.get('role'), 'maintainer') self.assertEqual(req.action[1].group.get('name'), 'groupxyz') self.assertEqual(req.action[1].group.get('role'), 'reader') self.assertEqual(req.state.get('name'), 'review') self.assertEqual(req.state.get('when'), '2010-12-27T01:36:29') self.assertEqual(req.state.get('who'), 'abc') self.assertEqual(req.review.get('by_group'), 'group1') self.assertEqual(req.review.get('state'), 'new') self.assertEqual(req.review.get('when'), '2010-12-28T00:11:22') self.assertEqual(req.review.get('who'), 'abc') self.assertTrue(len(req.history[:]) == 1) self.assertEqual(req.review.comment, 'review start') self.assertEqual(req.history[0].get('name'), 'new') self.assertEqual(req.history[0].get('when'), '2010-12-11T00:00:00') self.assertEqual(req.history[0].get('who'), 'creator')
def test_request18(self): """test request diff (returned object should have a write_to method""" req = Request.find('120703') f = req.diff() sio = StringIO() f.write_to(sio) self.assertEqual(sio.getvalue(), 'some diff content\n')
def test_request22(self): """test Request's add_review method (by_group, by_package)""" req = Request.find('120703') req.add_review(by_group='group', by_project='prj', by_package='pkg', comment='review')
def real_obj(self): """Returns a "real" Request object. The returned object is "writable" too that is its state can be changed etc. """ return Request(xml_data=etree.tostring(self))
def test_request3(self): """test request validation (incoming + outgoing)""" Request.SCHEMA = self.fixture_file('request_simple.xsd') req = Request.find('456') req = Request() req.add_action(type='submit') req.store()
def test_request19(self): """create a request (test None attrib filter in class ElementFactory""" # nearly identical to test_request2 (except the None's here and there) req = Request() action = req.add_action(type='submit', xyz=None) action.add_source(project='foo', package='bar', rev='12345') action.add_target(project='foobar', package=None) options = action.add_options() options.add_sourceupdate('cleanup', attr=None) req.description = 'some description' req.store() self.assertEqual(req.get('id'), '42') self.assertTrue(len(req.action) == 1) self.assertEqual(req.action[0].get('type'), 'submit') self.assertEqual(req.action[0].source.get('project'), 'foo') self.assertEqual(req.action[0].source.get('package'), 'bar') self.assertEqual(req.action[0].source.get('rev'), '12345') self.assertEqual(req.action[0].target.get('project'), 'foobar') self.assertIsNone(req.action[0].target.get('package')) self.assertEqual(req.action[0].options.sourceupdate, 'cleanup') self.assertIsNone(req.action[0].options.sourceupdate.get('attr')) self.assertEqual(req.state.get('name'), 'new') self.assertEqual(req.state.get('who'), 'username') self.assertEqual(req.state.get('when'), '2011-06-10T14:33:55') self.assertEqual(req.description, 'some description')
def test_request11(self): """test decline request""" req = Request.find('73270') self.assertEqual(req.get('id'), '73270') self.assertEqual(req.state.get('name'), 'new') # decline request req.decline(comment='does not build') self.assertEqual(req.get('id'), '73270') self.assertEqual(req.state.get('name'), 'declined') self.assertEqual(req.state.comment, 'does not build')
def test_request10(self): """test revoke request""" req = Request.find('73270') self.assertEqual(req.get('id'), '73270') self.assertEqual(req.state.get('name'), 'new') # revoke request req.revoke(comment='needs some more work') self.assertEqual(req.get('id'), '73270') self.assertEqual(req.state.get('name'), 'revoked') self.assertEqual(req.state.comment, 'needs some more work')
def test_request9(self): """test accept request""" req = Request.find('73270') self.assertEqual(req.get('id'), '73270') self.assertEqual(req.state.get('name'), 'new') # accept request req.accept(comment='thanks') self.assertEqual(req.get('id'), '73270') self.assertEqual(req.state.get('name'), 'accepted') self.assertEqual(req.state.comment, 'thanks')
def show(cls, renderer, reqid, info): """Shows the request specified by reqid.""" global SHOW_TEMPLATE request = Request.find(reqid) if info.interactive: cls.shell(renderer, info.shell_cls, [request], info) return renderer.render(SHOW_TEMPLATE, request=request) if info.diff: cls.diff(request)
def change_request_state(cls, renderer, reqid, method, message, info, supersede_id=None): """Changes the state of the request id reqid. method is the method which is called on the retrieved request object. If message is None $EDITOR is opened. """ request = Request.find(reqid) cls._change_request_state(renderer, request, method, message, info, supersede_id)
def test_request12(self): """test supersede request""" req = Request.find('73270') self.assertEqual(req.get('id'), '73270') self.assertEqual(req.state.get('name'), 'new') self.assertTrue(req.state.get('superseded_by') is None) # supersed request req.supersede('59130', comment='already accepted') self.assertEqual(req.get('id'), '73270') self.assertEqual(req.state.get('name'), 'superseded') # XXX: or should this be a reference to the request object? self.assertEqual(req.state.get('superseded_by'), '59130') self.assertEqual(req.state.comment, 'already accepted')
def add(cls, renderer, reqid, message, info): """Adds a new review to a request.""" request = Request.find(reqid) if message is None: message = edit_message() kwargs = {'comment': message, 'by_user': info.user, 'by_group': info.group} if info.package: kwargs['by_project'] = info.package[0].project kwargs['by_package'] = info.package[0].package elif info.project is not None: kwargs['by_project'] = info.project request.add_review(**kwargs) renderer.render(SHOW_TEMPLATE, request=request)
def change_review_state(cls, renderer, reqid, method, message, info, supersede_id=None): """Changes the state of a review. method is the method which is called on the retrieved request object. If message is None $EDITOR is opened. """ request = Request.find(reqid) reviews = cls._find_reviews(request, info) if reviews: # take the first review cls._change_review_state(renderer, request, reviews[0], method, message, info, supersede_id)
def test_request13(self): """test accept review""" req = Request.find('120704') self.assertEqual(req.get('id'), '120704') self.assertEqual(req.state.get('name'), 'review') self.assertEqual(len(req.review[:]), 3) review = req.review[2] self.assertTrue(review.get('state'), 'new') self.assertTrue(review.get('by_group'), 'autobuild-team') # accept review req.accept(comment='Thanks', review=review) self.assertEqual(req.get('id'), '120704') self.assertEqual(req.state.get('name'), 'review') self.assertEqual(len(req.review[:]), 3) self.assertEqual(req.review[2].get('state'), 'accepted') self.assertEqual(req.review[2].comment, 'Thanks')
def test_request14(self): """test decline review""" req = Request.find('120704') self.assertEqual(req.get('id'), '120704') self.assertEqual(req.state.get('name'), 'review') self.assertEqual(len(req.review[:]), 3) review = req.review[2] self.assertTrue(review.get('state'), 'new') self.assertTrue(review.get('by_group'), 'autobuild-team') # decline review req.decline(comment='does not look good', review=review) self.assertEqual(req.get('id'), '120704') self.assertEqual(req.state.get('name'), 'declined') self.assertEqual(len(req.review[:]), 3) self.assertEqual(req.review[2].get('state'), 'declined') self.assertEqual(req.review[2].comment, 'does not look good')
def test_request15(self): """test supersede review""" req = Request.find('120704') self.assertEqual(req.get('id'), '120704') self.assertEqual(req.state.get('name'), 'review') self.assertEqual(len(req.review[:]), 3) review = req.review[2] self.assertTrue(review.get('state'), 'new') self.assertTrue(review.get('by_group'), 'autobuild-team') # supersede review req.supersede('12345', comment='see rq12345', review=review) self.assertEqual(req.get('id'), '120704') self.assertEqual(req.state.get('name'), 'superseded') self.assertEqual(len(req.review[:]), 3) self.assertEqual(req.review[2].get('state'), 'superseded') self.assertEqual(req.review[2].comment, 'see rq12345')
def test_request16(self): """test accept review (by_project and by_package)""" req = Request.find('120703') self.assertEqual(req.get('id'), '120703') self.assertEqual(req.state.get('name'), 'review') self.assertEqual(len(req.review[:]), 3) review = req.review[2] self.assertTrue(review.get('state'), 'new') self.assertTrue(review.get('by_project'), 'project') self.assertTrue(review.get('by_package'), 'package') # accept review req.accept(comment='Thanks', review=review) self.assertEqual(req.get('id'), '120703') self.assertEqual(req.state.get('name'), 'review') self.assertEqual(len(req.review[:]), 3) self.assertEqual(req.review[2].get('state'), 'accepted') self.assertEqual(req.review[2].comment, 'Thanks')
def test_request20(self): """test Request's __cmp__ method""" l = [] l.append(Request(id='2')) l.append(Request(id='5')) l.append(Request(id='4')) l.append(Request(id='9')) l.append(Request()) l.append(Request(id='11')) l.append(Request(id='1')) l.sort() self.assertIsNone(l[0].get('id')) self.assertEqual(l[1].get('id'), '1') self.assertEqual(l[2].get('id'), '2') self.assertEqual(l[3].get('id'), '4') self.assertEqual(l[4].get('id'), '5') self.assertEqual(l[5].get('id'), '9') self.assertEqual(l[6].get('id'), '11')
def test_request2(self): """create a request""" req = Request() action = req.add_action(type='submit') action.add_source(project='foo', package='bar', rev='12345') action.add_target(project='foobar') options = action.add_options() options.add_sourceupdate('cleanup') req.description = 'some description' req.store() self.assertEqual(req.get('id'), '42') self.assertTrue(len(req.action) == 1) self.assertEqual(req.action[0].get('type'), 'submit') self.assertEqual(req.action[0].source.get('project'), 'foo') self.assertEqual(req.action[0].source.get('package'), 'bar') self.assertEqual(req.action[0].source.get('rev'), '12345') self.assertEqual(req.action[0].target.get('project'), 'foobar') self.assertEqual(req.action[0].options.sourceupdate, 'cleanup') self.assertEqual(req.state.get('name'), 'new') self.assertEqual(req.state.get('who'), 'username') self.assertEqual(req.state.get('when'), '2011-06-10T14:33:55') self.assertEqual(req.description, 'some description')
def test_request5(self): """test exists method""" self.assertTrue(Request.exists('123'))
def test_request21(self): """test Request's add_review method (by_user, by_project)""" req = Request.find('120703') req.add_review(by_user='******', by_project='project', comment='Please review sources')
def test_request6(self): """test exists method""" self.assertFalse(Request.exists('123'))
def test_request7(self): """test delete method""" self.assertTrue(Request.delete('123'))
def test_request8(self): """test delete method""" self.assertFalse(Request.delete('123'))
def test_request23(self): """test Request's add_review method (no comment)""" req = Request.find('120703') req.add_review(by_group='group')
def test_request17(self): """test request diff""" req = Request.find('120703') f = req.diff() self.assertEqual(f.read(), 'some diff content\n')