Commit b30152cb authored by Jérome Perrin's avatar Jérome Perrin Committed by Kazuhiko Shiozaki

test_result: use monaco to edit SlapOS parameters

( until we finalize the complete integration of SlapOS parameter
editor )
parent 7406d8b1
from six.moves import urllib
import requests
from Products.ERP5Type.XMLObject import XMLObject
from DateTime import DateTime
from AccessControl import ClassSecurityInfo
......@@ -30,6 +33,36 @@ class TestSuite(XMLObject, PeriodicityMixin):
return portal.portal_task_distribution.getMemcachedDict().get(
"%s_ping_date" % (self.getRelativeUrl()))
security.declareProtected(
Permissions.AccessContentsInformation,
'getSlapOSInstanceParameterSchemaURL')
def getSlapOSInstanceParameterSchemaURL(self):
"""Return the URL of the schema to use for SlapOS parameters.
"""
for test_suite_repository in self.contentValues(
portal_type='Test Suite Repository'):
git_url = test_suite_repository.getGitUrl()
if git_url:
if git_url.endswith('/'):
git_url = git_url[:-1]
if git_url.endswith('.git'):
git_url = git_url[:-4]
software_json_url = "{git_url}/raw/{branch}/{profile_path}.json".format(
git_url=git_url,
branch=test_suite_repository.getBranch(),
profile_path=test_suite_repository.getProfilePath(),
)
try:
software_json = requests.get(software_json_url, timeout=5).json()
except ValueError:
return None
for software_type in ('RootSoftwareInstance', 'default'):
if software_type in software_json['software-type']:
return urllib.parse.urljoin(
software_json_url,
software_json['software-type'][software_type]['request'])
# Compatibility Code to be removed after 06/2018, since all instances using
# test suites should be migrated at that time. Purpose here was to fix the
# setting of some properties that were defined with type "lines" instead of "string".
......
......@@ -1916,3 +1916,57 @@ class TestGitlabRESTConnectorInterface(ERP5TypeTestCase):
)
self.test_result.start()
self.tic()
class TestSlapOSParameterEditor(TaskDistributionTestCase):
def afterSetUp(self):
super(TestSlapOSParameterEditor, self).afterSetUp()
self.test_suite = self.portal.test_suite_module.newContent(
portal_type='Test Suite',
title=self.id(),
)
def test_getSlapOSInstanceParameterSchemaURL_empty(self):
with responses.RequestsMock():
self.assertIsNone(
self.test_suite.getSlapOSInstanceParameterSchemaURL())
def test_getSlapOSInstanceParameterSchemaURL_ok(self):
self.test_suite.newContent(
portal_type='Test Suite Repository',
branch='master',
git_url='https://lab.example.com/nexedi/test.git',
buildout_section_id='test',
profile_path='software-release/software.cfg')
with responses.RequestsMock() as rsps:
rsps.add(
responses.GET,
'https://lab.example.com/nexedi/test/raw/master/software-release/software.cfg.json',
json={
"serialisation": "json-in-xml",
"software-type": {
"default": {
"request": "instance-input-schema.json",
}
}
})
self.assertEqual(
self.test_suite.getSlapOSInstanceParameterSchemaURL(),
'https://lab.example.com/nexedi/test/raw/master/software-release/instance-input-schema.json'
)
def test_getSlapOSInstanceParameterSchemaURL_404(self):
self.test_suite.newContent(
portal_type='Test Suite Repository',
branch='master',
git_url='https://lab.example.com/nexedi/test.git',
buildout_section_id='test',
profile_path='software-release/software.cfg')
with responses.RequestsMock() as rsps:
rsps.add(
responses.GET,
'https://lab.example.com/nexedi/test/raw/master/software-release/software.cfg.json',
'not found')
self.assertIsNone(self.test_suite.getSlapOSInstanceParameterSchemaURL())
erp5_monaco_editor
erp5_project
erp5_web_service
\ No newline at end of file
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