Commit 38890225 authored by Romain Courteaud's avatar Romain Courteaud

slapos_slap_tool: getSoftwareReleaseListFromSoftwareProduct is related to a project

parent 4a4b83fc
......@@ -2408,30 +2408,17 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
def test_getSoftwareReleaseListFromSoftwareProduct_fromUrl(self):
new_id = self.generateNewId()
software_product = self._makeSoftwareProduct(self.project, new_id=new_id)
software_product = self._makeSoftwareProduct(self.project, new_id=new_id,
url='http://example.org/1.cfg')
# 2 published software releases
software_release1 = self._makeSoftwareRelease(software_product)
software_release2 = self._makeSoftwareRelease(software_product)
software_release1 = software_product.contentValues(portal_type='Software Product Release Variation')[0]
software_release2 = self._makeSoftwareRelease(software_product, url='http://example.org/2.cfg')
# 1 released software release, should not appear
software_release3 = self._makeSoftwareRelease(software_product)
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())
self.project.getReference(),
software_release_url=software_release2.getUrlString())
# check returned XML
got_xml = etree.tostring(etree.fromstring(response),
pretty_print=True, encoding="UTF-8", xml_declaration=True)
......@@ -2443,7 +2430,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<string>%s</string>
</list>
</marshal>
""" % (software_release2.getUrlString(), software_release1.getUrlString())
""" % (software_release1.getUrlString(), software_release2.getUrlString())
self.assertEqual(expected_xml, got_xml,
'\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))]))
......@@ -3266,7 +3253,8 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
self.assertEqual(expected_xml, got_xml,
'\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))]))
self.assertRequestComputeNodeSimulator((), {'compute_node_title': compute_node_id, 'project_reference': self.project.getReference()})
self.assertRequestComputeNodeSimulator((), {'compute_node_title': compute_node_id,
'project_reference': self.project.getReference()})
finally:
if os.path.exists(self.compute_node_request_compute_node_simulator):
os.unlink(self.compute_node_request_compute_node_simulator)
......
......@@ -372,7 +372,7 @@ class SlapTool(BaseTool):
security.declareProtected(Permissions.AccessContentsInformation,
'getSoftwareReleaseListFromSoftwareProduct')
def getSoftwareReleaseListFromSoftwareProduct(self,
def getSoftwareReleaseListFromSoftwareProduct(self, project_reference,
software_product_reference=None, software_release_url=None):
"""
Get the list of all published Software Releases related to one of either:
......@@ -383,12 +383,23 @@ class SlapTool(BaseTool):
If referenced Software Product does not exist, return empty list.
If referenced Software Release does not exist, raise.
"""
project_list = self.getPortalObject().portal_catalog.portal_catalog(
portal_type='Project',
reference=project_reference,
validation_state='validated',
limit=2
)
if len(project_list) != 1:
raise NotImplementedError("%i projects '%s'" % (len(project_list), project_reference))
project = project_list[0]
if software_product_reference is None:
assert(software_release_url is not None)
software_product_reference = self.getPortalObject().portal_catalog.unrestrictedSearchResults(
portal_type='Software Product Release Variation',
parent__follow_up__uid=project.getUid(),
url_string=software_release_url
)[0].getObject().getAggregateValue().getReference()
)[0].getObject().getParentValue().getReference()
else:
# Don't accept both parameters
assert(software_release_url is None)
......@@ -396,6 +407,7 @@ class SlapTool(BaseTool):
software_product_list = self.getPortalObject().portal_catalog.unrestrictedSearchResults(
portal_type='Software Product',
reference=software_product_reference,
follow_up__uid=project.getUid(),
validation_state='published')
if len(software_product_list) is 0:
return dumps([])
......@@ -419,9 +431,7 @@ class SlapTool(BaseTool):
)
return dumps(
[software_release.getUrlString()
for software_release in software_release_list
if software_release.getValidationState() in \
['published', 'published_alive']])
for software_release in software_release_list])
security.declareProtected(Permissions.AccessContentsInformation,
'getHateoasUrl')
......
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