def test_goal_propose_decline_and_clear(self): # Webservice clients can decline and clear spec series goals. db_spec = self.factory.makeBlueprint(product=self.product, owner=self.proposer) # Propose for series goal with person_logged_in(self.proposer): launchpad = self.factory.makeLaunchpadService(person=self.proposer) spec = ws_object(launchpad, db_spec) series = ws_object(launchpad, self.series) spec.proposeGoal(goal=series) transaction.commit() self.assertEqual(db_spec.goal, self.series) self.assertFalse(spec.has_accepted_goal) with person_logged_in(self.driver): # Decline series goal launchpad = self.factory.makeLaunchpadService(person=self.driver) spec = ws_object(launchpad, db_spec) spec.declineGoal() transaction.commit() self.assertFalse(spec.has_accepted_goal) self.assertEqual(db_spec.goal, self.series) # Clear series goal as a driver spec.proposeGoal(goal=None) transaction.commit() self.assertIsNone(db_spec.goal)
def test_relink_same_source_package(self): """Attempts to re-link the same source package should not error""" db_src_pkg = self.factory.makeDistributionSourcePackage() db_comp = self.factory.makeBugTrackerComponent() db_comp.distro_source_package = db_src_pkg transaction.commit() component = ws_object(self.launchpad, db_comp) package = ws_object(self.launchpad, db_src_pkg) component.distro_source_package = package
def test_link_source_package(self): """Link a component to a given source package""" db_src_pkg = self.factory.makeDistributionSourcePackage() db_comp = self.factory.makeBugTrackerComponent() transaction.commit() comp = ws_object(self.launchpad, db_comp) src_pkg = ws_object(self.launchpad, db_src_pkg) self.assertIs(None, comp.distro_source_package) comp.distro_source_package = src_pkg self.assertIsNot(None, comp.distro_source_package)
def setUp(self): super(TestStructuralSubscriptionAPI, self).setUp() self.owner = self.factory.makePerson(name=u"foo") self.structure = self.factory.makeProduct(owner=self.owner, name=u"bar") with person_logged_in(self.owner): self.subscription = self.structure.addBugSubscription( self.owner, self.owner) self.initial_filter = self.subscription.bug_filters[0] transaction.commit() self.service = self.factory.makeLaunchpadService(self.owner) self.ws_subscription = ws_object(self.service, self.subscription) self.ws_subscription_filter = ws_object(self.service, self.initial_filter)
def setUp(self): super(TestStructuralSubscriptionAPI, self).setUp() self.owner = self.factory.makePerson(name=u"foo") self.structure = self.factory.makeProduct( owner=self.owner, name=u"bar") with person_logged_in(self.owner): self.subscription = self.structure.addBugSubscription( self.owner, self.owner) self.initial_filter = self.subscription.bug_filters[0] transaction.commit() self.service = self.factory.makeLaunchpadService(self.owner) self.ws_subscription = ws_object(self.service, self.subscription) self.ws_subscription_filter = ws_object( self.service, self.initial_filter)
def test_unsubscribe(self): # Test unsubscribe() API. with person_logged_in(ANONYMOUS): db_spec = self.factory.makeBlueprint() db_person = self.factory.makePerson() db_spec.subscribe(person=db_person) launchpad = self.factory.makeLaunchpadService(person=db_person) spec = ws_object(launchpad, db_spec) person = ws_object(launchpad, db_person) spec.unsubscribe(person=person) transaction.commit() # Check the results. self.assertFalse(db_spec.isSubscribed(db_person))
def test_subscribe(self): # Test subscribe() API. person = self.factory.makePerson() with person_logged_in(person): db_question = self.factory.makeQuestion() db_person = self.factory.makePerson() launchpad = self.factory.makeLaunchpadService() question = ws_object(launchpad, db_question) person = ws_object(launchpad, db_person) question.subscribe(person=person) transaction.commit() # Check the results. self.assertTrue(db_question.isSubscribed(db_person))
def test_add_component(self): """Add a custom (local) component to the component group""" db_comp_group = self.bug_tracker.addRemoteComponentGroup( u'alpha') comp_group = ws_object(self.launchpad, db_comp_group) comp_group.addComponent(component_name=u'c') self.assertEqual(1, len(comp_group.components))
def test_requestDiffs(self): # The generation of package diffs can be requested via the API. derived_changelog = self.factory.makeChangelog(versions=['1.0', '1.2']) parent_changelog = self.factory.makeChangelog(versions=['1.0', '1.3']) transaction.commit() # Yay, librarian. ds_diff = self.factory.makeDistroSeriesDifference( source_package_name_str='foo', versions={ 'derived': '1.2', 'parent': '1.3', 'base': '1.0' }, changelogs={ 'derived': derived_changelog, 'parent': parent_changelog, }) ws_diff = ws_object( self.factory.makeLaunchpadService(self.factory.makePerson()), ds_diff) ws_diff.requestPackageDiffs() transaction.commit() # Reload and check that the package diffs are there. utility = getUtility(IDistroSeriesDifferenceSource) ds_diff = utility.getByDistroSeriesNameAndParentSeries( ds_diff.derived_series, ds_diff.source_package_name.name, ds_diff.parent_series) self.assertIsNot(None, ds_diff.package_diff) self.assertIsNot(None, ds_diff.parent_package_diff)
def test_subscribe(self): # Test subscribe() API. with person_logged_in(ANONYMOUS): db_spec = self.factory.makeSpecification() db_person = self.factory.makePerson() launchpad = self.factory.makeLaunchpadService() spec = ws_object(launchpad, db_spec) person = ws_object(launchpad, db_person) spec.subscribe(person=person, essential=True) transaction.commit() # Check the results. sub = db_spec.subscription(db_person) self.assertIsNot(None, sub) self.assertTrue(sub.essential)
def test_requestDiffs(self): # The generation of package diffs can be requested via the API. derived_changelog = self.factory.makeChangelog( versions=['1.0', '1.2']) parent_changelog = self.factory.makeChangelog( versions=['1.0', '1.3']) transaction.commit() # Yay, librarian. ds_diff = self.factory.makeDistroSeriesDifference( source_package_name_str='foo', versions={ 'derived': '1.2', 'parent': '1.3', 'base': '1.0'}, changelogs={ 'derived': derived_changelog, 'parent': parent_changelog, }) ws_diff = ws_object(self.factory.makeLaunchpadService( self.factory.makePerson()), ds_diff) ws_diff.requestPackageDiffs() transaction.commit() # Reload and check that the package diffs are there. utility = getUtility(IDistroSeriesDifferenceSource) ds_diff = utility.getByDistroSeriesNameAndParentSeries( ds_diff.derived_series, ds_diff.source_package_name.name, ds_diff.parent_series) self.assertIsNot(None, ds_diff.package_diff) self.assertIsNot(None, ds_diff.parent_package_diff)
def test_set_configuration(self): """Test the mutator for setting configuration.""" with person_logged_in(ANONYMOUS): db_queue = self.factory.makeBranchMergeQueue() launchpad = launchpadlib_for( 'test', db_queue.owner, service_root="http://api.launchpad.dev:8085") configuration = simplejson.dumps({'test': 'make check'}) queue = ws_object(launchpad, db_queue) queue.configuration = configuration queue.lp_save() queue2 = ws_object(launchpad, db_queue) self.assertEqual(queue2.configuration, configuration)
def test_list_component_groups_for_bug_tracker(self): """Retrieve the component groups for a bug tracker""" self.bug_tracker.addRemoteComponentGroup(u'alpha') self.bug_tracker.addRemoteComponentGroup(u'beta') bug_tracker = ws_object(self.launchpad, self.bug_tracker) comp_groups = bug_tracker.getAllRemoteComponentGroups() self.assertEqual(2, len(list(comp_groups)))
def test_retrieve_component_group_from_bug_tracker(self): """Looks up specific component group in bug tracker""" self.bug_tracker.addRemoteComponentGroup(u'alpha') bug_tracker = ws_object(self.launchpad, self.bug_tracker) comp_group = bug_tracker.getRemoteComponentGroup( component_group_name=u'alpha') self.assertIsNot(None, comp_group)
def test_exported_sourcepackagename(self): # The difference's sourcepackagename is exposed. ds_diff = self.factory.makeDistroSeriesDifference( source_package_name_str=u'package') ws_diff = ws_object(self.factory.makeLaunchpadService( self.factory.makePerson()), ds_diff) self.assertEqual(u'package', ws_diff.sourcepackagename)
def test_exported_source_version(self): # The difference's source_version is exposed. ds_diff = self.factory.makeDistroSeriesDifference( versions={'derived': u'1.3'}) ws_diff = ws_object(self.factory.makeLaunchpadService( self.factory.makePerson()), ds_diff) self.assertEqual(u'1.3', ws_diff.source_version)
def test_exported_status(self): # The difference's status is exposed. ds_diff = self.factory.makeDistroSeriesDifference( status=DistroSeriesDifferenceStatus.BLACKLISTED_ALWAYS) ws_diff = ws_object(self.factory.makeLaunchpadService( self.factory.makePerson()), ds_diff) self.assertEqual(u'Blacklisted always', ws_diff.status)
def test_exported_base_version(self): # The difference's base_version is exposed. ds_diff = self.factory.makeDistroSeriesDifference( versions={'base': u'0.5'}, set_base_version=True) ws_diff = ws_object(self.factory.makeLaunchpadService( self.factory.makePerson()), ds_diff) self.assertEqual(u'0.5', ws_diff.base_version)
def test_setChroot_wrong_sha1sum(self): # If the sha1sum calculated is different, the chroot is not set. das = self.factory.makeDistroArchSeries() user = das.distroseries.distribution.main_archive.owner webservice = launchpadlib_for("testing", user) ws_das = ws_object(webservice, das) self.assertRaises( BadRequest, ws_das.setChroot, data='zyx', sha1sum='x')
def test_getBuildRecords(self): das = self.factory.makeDistroArchSeries() build = self.factory.makeBinaryPackageBuild(distroarchseries=das) build_title = build.title user = self.factory.makePerson() launchpad = launchpadlib_for("testing", user) ws_das = ws_object(launchpad, das) self.assertEqual([build_title], [entry.title for entry in ws_das.getBuildRecords()])
def test_exported_source_version(self): # The difference's source_version is exposed. ds_diff = self.factory.makeDistroSeriesDifference( versions={'derived': u'1.3'}) ws_diff = ws_object( self.factory.makeLaunchpadService(self.factory.makePerson()), ds_diff) self.assertEqual(u'1.3', ws_diff.source_version)
def test_get_linked_source_package(self): """Already linked source packages can be seen from the component""" db_src_pkg = self.factory.makeDistributionSourcePackage() db_comp = self.factory.makeBugTrackerComponent() db_comp.distro_source_package = db_src_pkg transaction.commit() comp = ws_object(self.launchpad, db_comp) self.assertIsNot(None, comp.distro_source_package)
def test_distroseries_architectures_authenticated(self): """Test authenticated DistroArchSeries API Access.""" distroseries = self._makeDistroArchSeries() #Create a user to use the authenticated API accessor = self.factory.makePerson() launchpad = launchpadlib_for('test', accessor.name, version='devel') ws_distroseries = ws_object(launchpad, distroseries) #See note above regarding testing of length of .entries self.assertEqual(1, len(ws_distroseries.architectures.entries))
def test_remove_component(self): """Make a component not visible in the UI""" db_comp = self.factory.makeBugTrackerComponent() transaction.commit() comp = ws_object(self.launchpad, db_comp) self.assertTrue(comp.is_visible) comp.is_visible = False self.assertFalse(comp.is_visible)
def test_setChroot_removeChroot_random_user(self): # Random users are not allowed to set or remove chroots. das = self.factory.makeDistroArchSeries() user = self.factory.makePerson() webservice = launchpadlib_for("testing", user, version='devel') ws_das = ws_object(webservice, das) self.assertRaises( Unauthorized, ws_das.setChroot, data='xyz', sha1sum='0') self.assertRaises(Unauthorized, ws_das.removeChroot)
def test_exported_base_version(self): # The difference's base_version is exposed. ds_diff = self.factory.makeDistroSeriesDifference( versions={'base': u'0.5'}, set_base_version=True) ws_diff = ws_object( self.factory.makeLaunchpadService(self.factory.makePerson()), ds_diff) self.assertEqual(u'0.5', ws_diff.base_version)
def test_distroseries_architectures_anonymous(self): """Test anonymous DistroArchSeries API Access.""" distroseries = self._makeDistroArchSeries() endInteraction() launchpad = launchpadlib_for('test', person=None, version='devel') ws_distroseries = ws_object(launchpad, distroseries) # Note, we test the length of architectures.entries, not # architectures due to the removal of the entries by lazr self.assertEqual(1, len(ws_distroseries.architectures.entries))
def test_get_difference(self): # DistroSeriesDifferences are available on the web service. ds_diff = self.factory.makeDistroSeriesDifference() ds_diff_path = canonical_url(ds_diff).replace('http://launchpad.dev', '') ws_diff = ws_object(self.factory.makeLaunchpadService(), ds_diff) self.assertTrue(ws_diff.self_link.endswith(ds_diff_path))
def test_exported_sourcepackagename(self): # The difference's sourcepackagename is exposed. ds_diff = self.factory.makeDistroSeriesDifference( source_package_name_str=u'package') ws_diff = ws_object( self.factory.makeLaunchpadService(self.factory.makePerson()), ds_diff) self.assertEqual(u'package', ws_diff.sourcepackagename)
def test_exported_status(self): # The difference's status is exposed. ds_diff = self.factory.makeDistroSeriesDifference( status=DistroSeriesDifferenceStatus.BLACKLISTED_ALWAYS) ws_diff = ws_object( self.factory.makeLaunchpadService(self.factory.makePerson()), ds_diff) self.assertEqual(u'Blacklisted always', ws_diff.status)
def test_anon_access_to_public_bug_attachment(self): # Attachments of public bugs can be accessed by anonymous users. # # Need to endInteraction() because launchpadlib_for_anonymous() will # setup a new one. endInteraction() launchpad = launchpadlib_for('test', None, version='devel') ws_bug = ws_object(launchpad, self.bug) ws_bugattachment = ws_bug.attachments[0] self.assertEqual('file content', ws_bugattachment.data.open().read())
def test_list_components_for_component_group(self): """Retrieve the components for a given group""" db_comp_group_alpha = self.bug_tracker.addRemoteComponentGroup( u'alpha') db_comp_group_alpha.addComponent(u'1') db_comp_group_alpha.addComponent(u'2') transaction.commit() comp_group = ws_object(self.launchpad, db_comp_group_alpha) self.assertEqual(2, len(comp_group.components))
def _createWSForDSDWithRequestedPackageDiff(self, versions): # Helper to create and return a webservice for a # DistroSeriesDifference with requested package diff(s). ds_diff = self.factory.makeDistroSeriesDifference(versions=versions, set_base_version=True) ws_diff = ws_object(self.factory.makeLaunchpadService( self.factory.makePerson()), ds_diff) ws_diff.requestPackageDiffs() transaction.commit() return ws_diff
def test_canBeUnsubscribedByUser(self): # Test canBeUnsubscribedByUser() API. webservice = LaunchpadWebServiceCaller('launchpad-library', 'salgado-change-anything', domain='api.launchpad.dev:8085') with person_logged_in(ANONYMOUS): db_spec = self.factory.makeSpecification() db_person = self.factory.makePerson() launchpad = self.factory.makeLaunchpadService() spec = ws_object(launchpad, db_spec) person = ws_object(launchpad, db_person) subscription = spec.subscribe(person=person, essential=True) transaction.commit() result = webservice.named_get(subscription['self_link'], 'canBeUnsubscribedByUser').jsonBody() self.assertTrue(result)
def test_canBeUnsubscribedByUser(self): # Test canBeUnsubscribedByUser() API. webservice = LaunchpadWebServiceCaller( 'launchpad-library', 'salgado-change-anything', domain='api.launchpad.dev:8085') with person_logged_in(ANONYMOUS): db_spec = self.factory.makeSpecification() db_person = self.factory.makePerson() launchpad = self.factory.makeLaunchpadService() spec = ws_object(launchpad, db_spec) person = ws_object(launchpad, db_person) subscription = spec.subscribe(person=person, essential=True) transaction.commit() result = webservice.named_get( subscription['self_link'], 'canBeUnsubscribedByUser').jsonBody() self.assertTrue(result)
def test_get_difference(self): # DistroSeriesDifferences are available on the web service. ds_diff = self.factory.makeDistroSeriesDifference() ds_diff_path = canonical_url(ds_diff).replace( 'http://launchpad.dev', '') ws_diff = ws_object(self.factory.makeLaunchpadService(), ds_diff) self.assertTrue( ws_diff.self_link.endswith(ds_diff_path))
def test_anon_access_to_public_bug_attachment(self): # Attachments of public bugs can be accessed by anonymous users. # # Need to endInteraction() because launchpadlib_for_anonymous() will # setup a new one. endInteraction() launchpad = launchpadlib_for('test', None, version='devel') ws_bug = ws_object(launchpad, self.bug) ws_bugattachment = ws_bug.attachments[0] self.assertEqual( 'file content', ws_bugattachment.data.open().read())
def test_bug_unlinking(self): # Set up a spec, person, and bug, then link the bug to the spec. with person_logged_in(ANONYMOUS): db_spec = self.factory.makeBlueprint() db_person = self.factory.makePerson() db_bug = self.factory.makeBug() launchpad = self.factory.makeLaunchpadService(person=db_person) spec = ws_object(launchpad, db_spec) bug = ws_object(launchpad, db_bug) spec.linkBug(bug=bug) # There is only one bug linked at the moment. self.assertEqual(1, spec.bugs.total_size) spec.unlinkBug(bug=bug) transaction.commit() # Now that we've unlinked the bug, there are no linked bugs at all. self.assertEqual(0, spec.bugs.total_size)
def test_anonymous_access_to_collection(self): product = self.factory.makeProduct() self.factory.makeSpecification(product=product, name="spec1") self.factory.makeSpecification(product=product, name="spec2") # Need to endInteraction() because launchpadlib_for_anonymous() will # setup a new one. endInteraction() lplib = launchpadlib_for('lplib-test', person=None, version='devel') ws_product = ws_object(lplib, removeSecurityProxy(product)) self.assertNamesOfSpecificationsAre(["spec1", "spec2"], ws_product.all_specifications)
def _createWSForDSDWithRequestedPackageDiff(self, versions): # Helper to create and return a webservice for a # DistroSeriesDifference with requested package diff(s). ds_diff = self.factory.makeDistroSeriesDifference( versions=versions, set_base_version=True) ws_diff = ws_object( self.factory.makeLaunchpadService(self.factory.makePerson()), ds_diff) ws_diff.requestPackageDiffs() transaction.commit() return ws_diff
def test_anonymous_access_to_collection(self): product = self.factory.makeProduct() self.factory.makeSpecification(product=product, name="spec1") self.factory.makeSpecification(product=product, name="spec2") # Need to endInteraction() because launchpadlib_for_anonymous() will # setup a new one. endInteraction() lplib = launchpadlib_for('lplib-test', person=None, version='devel') ws_product = ws_object(lplib, removeSecurityProxy(product)) self.assertNamesOfSpecificationsAre( ["spec1", "spec2"], ws_product.all_specifications)
def test_goal_propose_and_accept(self): # Webservice clients can propose and accept spec series goals. db_spec = self.factory.makeBlueprint(product=self.product, owner=self.proposer) # Propose for series goal with person_logged_in(self.proposer): launchpad = self.factory.makeLaunchpadService(person=self.proposer) spec = ws_object(launchpad, db_spec) series = ws_object(launchpad, self.series) spec.proposeGoal(goal=series) transaction.commit() self.assertEqual(db_spec.goal, self.series) self.assertFalse(spec.has_accepted_goal) # Accept series goal with person_logged_in(self.driver): launchpad = self.factory.makeLaunchpadService(person=self.driver) spec = ws_object(launchpad, db_spec) spec.acceptGoal() transaction.commit() self.assertTrue(spec.has_accepted_goal)
def test_bug_linking(self): # Set up a spec, person, and bug. with person_logged_in(ANONYMOUS): db_spec = self.factory.makeSpecification() db_person = self.factory.makePerson() db_bug = self.factory.makeBug() launchpad = self.factory.makeLaunchpadService() # Link the bug to the spec via the web service. with person_logged_in(db_person): spec = ws_object(launchpad, db_spec) bug = ws_object(launchpad, db_bug) # There are no bugs associated with the spec/blueprint yet. self.assertEqual(0, spec.bugs.total_size) spec.linkBug(bug=bug) transaction.commit() # The spec now has one bug associated with it and that bug is the one # we linked. self.assertEqual(1, spec.bugs.total_size) self.assertEqual(bug.id, spec.bugs[0].id)