launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #24649
[Merge] ~twom/launchpad:oci-projects-should-be-exported-on-distribuion into launchpad:master
Tom Wardill has proposed merging ~twom/launchpad:oci-projects-should-be-exported-on-distribuion into launchpad:master.
Commit message:
Create and export searchOCIProjects on IDistribution
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~twom/launchpad/+git/launchpad/+merge/383157
We need a way to get to OCIProjects that are on a distribution. A simple list isn't ideal, and isn't similar to Source Packages.
Copy the approach from Source Packages of having a 'search' method, but search the name of the OCIProject (as it's the only useful field on the model).
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/launchpad:oci-projects-should-be-exported-on-distribuion into launchpad:master.
diff --git a/lib/lp/_schema_circular_imports.py b/lib/lp/_schema_circular_imports.py
index 141c581..7e0a047 100644
--- a/lib/lp/_schema_circular_imports.py
+++ b/lib/lp/_schema_circular_imports.py
@@ -456,11 +456,14 @@ patch_collection_return_type(
IDistribution, 'getDevelopmentSeries', IDistroSeries)
patch_entry_return_type(
IDistribution, 'getSourcePackage', IDistributionSourcePackage)
+patch_entry_return_type(IDistribution, 'getOCIProject', IOCIProject)
patch_collection_return_type(
IDistribution, 'searchSourcePackages', IDistributionSourcePackage)
patch_reference_property(IDistribution, 'main_archive', IArchive)
patch_collection_property(IDistribution, 'all_distro_archives', IArchive)
patch_entry_return_type(IDistribution, 'newOCIProject', IOCIProject)
+patch_collection_return_type(
+ IDistribution, 'searchOCIProjects', IOCIProject)
# IDistributionMirror
diff --git a/lib/lp/registry/interfaces/distribution.py b/lib/lp/registry/interfaces/distribution.py
index 23bd93b..fe94cda 100644
--- a/lib/lp/registry/interfaces/distribution.py
+++ b/lib/lp/registry/interfaces/distribution.py
@@ -506,12 +506,28 @@ class IDistributionPublic(
create a mirror.
"""
+ @operation_parameters(
+ name=TextLine(title=_("OCI project name"), required=True))
+ # Really returns IOCIProject, see _schema_circular_imports.py.
+ @operation_returns_entry(Interface)
+ @export_read_operation()
+ @operation_for_version("devel")
def getOCIProject(name):
"""Return a `OCIProject` with the given name for this
distribution, or None.
"""
@operation_parameters(
+ text=TextLine(title=_("OCI title substring match "), required=False))
+ # Really returns IOCIProject, see
+ # _schema_circular_imports.py.
+ @operation_returns_collection_of(Interface)
+ @export_read_operation()
+ @operation_for_version("devel")
+ def searchOCIProjects(text):
+ """Search for OCI projects that match the title text."""
+
+ @operation_parameters(
name=TextLine(title=_("Package name"), required=True))
# Really returns IDistributionSourcePackage, see
# _schema_circular_imports.py.
diff --git a/lib/lp/registry/model/distribution.py b/lib/lp/registry/model/distribution.py
index 9bc2b23..5fa7d32 100644
--- a/lib/lp/registry/model/distribution.py
+++ b/lib/lp/registry/model/distribution.py
@@ -135,6 +135,7 @@ from lp.registry.model.milestone import (
HasMilestonesMixin,
Milestone,
)
+from lp.registry.model.ociprojectname import OCIProjectName
from lp.registry.model.oopsreferences import referenced_oops
from lp.registry.model.pillar import HasAliasMixin
from lp.registry.model.sourcepackagename import SourcePackageName
@@ -1122,6 +1123,19 @@ class Distribution(SQLBase, BugTargetBase, MakesAnnouncements,
return result_set.order_by(DistributionSourcePackageCache.name)
+ def searchOCIProjects(self, text=None):
+ """See `IDistribution`."""
+ # circular import
+ from lp.registry.model.ociproject import OCIProject
+ store = Store.of(self)
+
+ result = store.find(
+ OCIProject,
+ OCIProject.distribution == self,
+ OCIProject.ociprojectname_id == OCIProjectName.id,
+ OCIProjectName.name.contains_string(text))
+ return result
+
def guessPublishedSourcePackageName(self, pkgname):
"""See `IDistribution`"""
assert isinstance(pkgname, basestring), (
diff --git a/lib/lp/registry/tests/test_distribution.py b/lib/lp/registry/tests/test_distribution.py
index 8f20b7b..19136dd 100644
--- a/lib/lp/registry/tests/test_distribution.py
+++ b/lib/lp/registry/tests/test_distribution.py
@@ -312,6 +312,30 @@ class TestDistribution(TestCaseWithFactory):
result = distro.getOCIProject(first_project.name)
self.assertEqual(first_project, result)
+ def test_searchOCIProjects_by_name(self):
+ name = self.factory.getUniqueUnicode()
+ distro = self.factory.makeDistribution()
+ first_name = self.factory.makeOCIProjectName(name=name)
+ first_project = self.factory.makeOCIProject(
+ pillar=distro, ociprojectname=first_name)
+ self.factory.makeOCIProject(pillar=distro)
+
+ result = distro.searchOCIProjects(text=name)
+ self.assertEqual(1, result.count())
+ self.assertEqual(first_project, result[0])
+
+ def test_searchOCIProjects_by_partial_name(self):
+ name = u'testpartialname'
+ distro = self.factory.makeDistribution()
+ first_name = self.factory.makeOCIProjectName(name=name)
+ first_project = self.factory.makeOCIProject(
+ pillar=distro, ociprojectname=first_name)
+ self.factory.makeOCIProject(pillar=distro)
+
+ result = distro.searchOCIProjects(text=u'partial')
+ self.assertEqual(1, result.count())
+ self.assertEqual(first_project, result[0])
+
class TestDistributionCurrentSourceReleases(
CurrentSourceReleasesMixin, TestCase):