Commit 55ee1128 authored by Cédric de Saint Martin's avatar Cédric de Saint Martin Committed by Gabriel Monnerat

[VIFIB product] Extend getSoftwareReleaseListFromSoftwareProduct to accept software_release_url.

Accept a software_release_url parameter as related document.
parent 72e0b0e8
...@@ -1756,6 +1756,52 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): ...@@ -1756,6 +1756,52 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
self.assertEqual(expected_xml, got_xml, self.assertEqual(expected_xml, got_xml,
'\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))])) '\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))]))
def test_getSoftwareReleaseListFromSoftwareProduct_fromUrl(self):
new_id = self.generateNewId()
software_product = self._makeSoftwareProduct(new_id)
# 2 published software releases
software_release1 = self._makeSoftwareRelease(new_id)
software_release2 = self._makeSoftwareRelease(self.generateNewId())
software_release1.publish()
software_release2.publish()
# 1 released software release, should not appear
software_release3 = self._makeSoftwareRelease(new_id)
self.assertTrue(software_release3.getValidationState() == 'released')
software_release1.edit(
aggregate_value=software_product.getRelativeUrl(),
url_string='http://example.org/1.cfg'
)
software_release2.edit(
aggregate_value=software_product.getRelativeUrl(),
url_string='http://example.org/2.cfg'
)
software_release3.edit(
aggregate_value=software_product.getRelativeUrl(),
url_string='http://example.org/3.cfg'
)
self.tic()
response = self.portal_slap.getSoftwareReleaseListFromSoftwareProduct(
software_release_url=software_release2.getUrlString())
# check returned XML
xml_fp = StringIO.StringIO()
xml.dom.ext.PrettyPrint(xml.dom.ext.reader.Sax.FromXml(response),
stream=xml_fp)
xml_fp.seek(0)
got_xml = xml_fp.read()
expected_xml = """\
<?xml version='1.0' encoding='UTF-8'?>
<marshal>
<list id='i2'>
<string>%s</string>
<string>%s</string>
</list>
</marshal>
""" % (software_release2.getUrlString(), software_release1.getUrlString())
self.assertEqual(expected_xml, got_xml,
'\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))]))
class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin): class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
def afterSetUp(self): def afterSetUp(self):
password = self.generateNewId() password = self.generateNewId()
......
...@@ -355,11 +355,27 @@ class SlapTool(BaseTool): ...@@ -355,11 +355,27 @@ class SlapTool(BaseTool):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getSoftwareReleaseListFromSoftwareProduct') 'getSoftwareReleaseListFromSoftwareProduct')
def getSoftwareReleaseListFromSoftwareProduct(self, software_product_reference): def getSoftwareReleaseListFromSoftwareProduct(self,
software_product_reference=None, software_release_url=None):
""" """
Get the list of published software releases from a given software product, Get the list of all published Software Releases related to one of either:
* A given Software Product as aggregate
* Another Software Release from the same Software Product as aggregate,
sorted by descending age (latest first). sorted by descending age (latest first).
""" If both software_product_reference/software_release_url are defined, raise.
If referenced Software Product does not exist, return empty list.
If referenced Software Release does not exist, raise.
"""
if software_product_reference is None:
assert(software_release_url is not None)
software_product_reference = self.getPortalObject().portal_catalog.unrestrictedSearchResults(
portal_type='Software Release',
url_string=software_release_url
)[0].getObject().getAggregateValue().getReference()
else:
# Don't accept both parameters
assert(software_release_url is None)
software_product_list = self.getPortalObject().portal_catalog.unrestrictedSearchResults( software_product_list = self.getPortalObject().portal_catalog.unrestrictedSearchResults(
portal_type='Software Product', portal_type='Software Product',
reference=software_product_reference, reference=software_product_reference,
......
...@@ -474,7 +474,8 @@ class slap(Interface): ...@@ -474,7 +474,8 @@ class slap(Interface):
Instanciate a supply in the slap library. Instanciate a supply in the slap library.
""" """
def getSoftwareReleaseListFromProduct(software_product_reference): def getSoftwareReleaseListFromProduct(software_product_reference, software_release_url):
""" """
Get the list of Software Releases from a product. Get the list of Software Releases from a product or from another related
Sofware Release, from a Software Product point of view.
""" """
...@@ -736,7 +736,13 @@ class slap: ...@@ -736,7 +736,13 @@ class slap:
def registerSupply(self): def registerSupply(self):
return Supply(connection_helper=self._connection_helper) return Supply(connection_helper=self._connection_helper)
def getSoftwareReleaseListFromSoftwareProduct(self, software_product_reference): def getSoftwareReleaseListFromSoftwareProduct(self,
xml = self._connection_helper.GET('/getSoftwareReleaseListFromSoftwareProduct?' \ software_product_reference=None, software_release_url=None):
'software_product_reference=%s' % software_product_reference) url = '/getSoftwareReleaseListFromSoftwareProduct?'
return xml_marshaller.loads(xml) if software_product_reference:
assert(software_release_url is None)
url += 'software_product_reference=%s' % software_product_reference
else:
assert(software_release_url is not None)
url += 'software_release_url=%s' % software_release_url
return xml_marshaller.loads(self._connection_helper.GET(url))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment