def add_requirements_test(self): """Check that multiple requirements can be added at once.""" reqs = PayloadRequirements() self.assertTrue(reqs.empty) # add a package, group & unknown requirement type req_list = [] req_list.append(Requirement.for_package("foo-package", reason="foo package needed")) req_list.append(Requirement.for_group("bar-group", reason="bar group needed")) unknown_req = Requirement() unknown_req.name = "baz-unknown" unknown_req.reson = "unknown reason for installation" unknown_req.type = "baz-unknown-type" req_list.append(unknown_req) # add the requrements list and check it is processed correctly reqs.add_requirements(req_list) self.assertFalse(reqs.empty) # package self.assertEqual(len(reqs.packages), 1) self.assertEqual(reqs.packages[0].id, "foo-package") self.assertEqual(len(reqs.packages[0].reasons), 1) self.assertEqual(reqs.packages[0].reasons[0], "foo package needed") self.assertTrue(reqs.packages[0].strong) # group self.assertEqual(len(reqs.groups), 1) self.assertEqual(reqs.groups[0].id, "bar-group") self.assertEqual(len(reqs.groups[0].reasons), 1) self.assertEqual(reqs.groups[0].reasons[0], "bar group needed") self.assertTrue(reqs.groups[0].strong)
def _create_requirement(self, name, reason, req_type=REQUIREMENT_TYPE_PACKAGE): """Create a new requirement.""" requirement = Requirement() requirement.type = req_type requirement.name = name requirement.reason = reason return requirement