Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ivan Tyagov
slapos.core
Commits
f932e38f
Commit
f932e38f
authored
Aug 06, 2013
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the hypermedia API to fetch software installation on computer.
parent
9e96f6f1
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
262 additions
and
117 deletions
+262
-117
master/bt5/slapos_hypermedia/SkinTemplateItem/portal_skins/slapos_hypermedia/Computer_getHateoas.xml
...em/portal_skins/slapos_hypermedia/Computer_getHateoas.xml
+1
-1
master/bt5/slapos_hypermedia/SkinTemplateItem/portal_skins/slapos_hypermedia/Computer_getHateoasSoftwareInstallationList.xml
...ypermedia/Computer_getHateoasSoftwareInstallationList.xml
+5
-4
master/bt5/slapos_hypermedia/SkinTemplateItem/portal_skins/slapos_hypermedia/Person_getHateoasComputerList.xml
...skins/slapos_hypermedia/Person_getHateoasComputerList.xml
+1
-1
master/bt5/slapos_hypermedia/SkinTemplateItem/portal_skins/slapos_hypermedia/SoftwareInstallation_getHateoas.xml
...ins/slapos_hypermedia/SoftwareInstallation_getHateoas.xml
+7
-5
master/bt5/slapos_hypermedia/TestTemplateItem/testSlapOSHypermediaScenario.py
...permedia/TestTemplateItem/testSlapOSHypermediaScenario.py
+1
-1
master/bt5/slapos_hypermedia/TestTemplateItem/testSlapOSHypermediaSkins.py
..._hypermedia/TestTemplateItem/testSlapOSHypermediaSkins.py
+246
-104
master/bt5/slapos_hypermedia/bt/revision
master/bt5/slapos_hypermedia/bt/revision
+1
-1
No files found.
master/bt5/slapos_hypermedia/SkinTemplateItem/portal_skins/slapos_hypermedia/Computer_getHateoas.xml
View file @
f932e38f
...
@@ -80,7 +80,7 @@ else:\n
...
@@ -80,7 +80,7 @@ else:\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.computer" },\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.computer" },\n
\n
\n
"http://slapos.org/reg/software": {\n
"http://slapos.org/reg/software": {\n
"href": "%s/Computer_getHateoasSoftwareList" % context.absolute_url(),\n
"href": "%s/Computer_getHateoasSoftware
Installation
List" % context.absolute_url(),\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.collection",\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.collection",\n
},\n
},\n
\n
\n
...
...
master/bt5/slapos_hypermedia/SkinTemplateItem/portal_skins/slapos_hypermedia/Computer_getHateoasSoftwareList.xml
→
master/bt5/slapos_hypermedia/SkinTemplateItem/portal_skins/slapos_hypermedia/Computer_getHateoasSoftware
Installation
List.xml
View file @
f932e38f
...
@@ -80,12 +80,13 @@ else:\n
...
@@ -80,12 +80,13 @@ else:\n
\n
\n
for sql_obj in context.getPortalObject().portal_catalog(\n
for sql_obj in context.getPortalObject().portal_catalog(\n
portal_type=\'Software Installation\',\n
portal_type=\'Software Installation\',\n
aggregate_relative_url=context.getRelativeUrl(),\n
default_aggregate_uid=context.getUid(),\n
validation_state=\'validated\',\n
):\n
):\n
obj = sql_obj.getObject()\n
obj = sql_obj.getObject()\n
result_dict[\'_links\'][\'item\'].append({\n
result_dict[\'_links\'][\'item\'].append({\n
\'href\': \'%s/Software_getHateoas\' % obj.absolute_url(),\n
\'href\': \'%s/Software
Installation
_getHateoas\' % obj.absolute_url(),\n
\'type\': \'application/vnd.slapos.org.hal+json; class=slapos.org.software\',\n
\'type\': \'application/vnd.slapos.org.hal+json; class=slapos.org.software
_installation
\',\n
})\n
})\n
\n
\n
response.setHeader(\'Content-Type\', type)\n
response.setHeader(\'Content-Type\', type)\n
...
@@ -98,7 +99,7 @@ else:\n
...
@@ -98,7 +99,7 @@ else:\n
</item>
</item>
<item>
<item>
<key>
<string>
id
</string>
</key>
<key>
<string>
id
</string>
</key>
<value>
<string>
Computer_getHateoasSoftwareList
</string>
</value>
<value>
<string>
Computer_getHateoasSoftware
Installation
List
</string>
</value>
</item>
</item>
</dictionary>
</dictionary>
</pickle>
</pickle>
...
...
master/bt5/slapos_hypermedia/SkinTemplateItem/portal_skins/slapos_hypermedia/Person_getHateoasComputerList.xml
View file @
f932e38f
...
@@ -80,7 +80,7 @@ else:\n
...
@@ -80,7 +80,7 @@ else:\n
\n
\n
for sql_obj in context.getPortalObject().portal_catalog(\n
for sql_obj in context.getPortalObject().portal_catalog(\n
portal_type="Computer",\n
portal_type="Computer",\n
source_administration_uid=context.getUid(),\n
default_
source_administration_uid=context.getUid(),\n
):\n
):\n
obj = sql_obj.getObject()\n
obj = sql_obj.getObject()\n
result_dict[\'_links\'][\'item\'].append({\n
result_dict[\'_links\'][\'item\'].append({\n
...
...
master/bt5/slapos_hypermedia/SkinTemplateItem/portal_skins/slapos_hypermedia/Software_getHateoas.xml
→
master/bt5/slapos_hypermedia/SkinTemplateItem/portal_skins/slapos_hypermedia/Software
Installation
_getHateoas.xml
View file @
f932e38f
...
@@ -56,7 +56,7 @@ if REQUEST is None:\n
...
@@ -56,7 +56,7 @@ if REQUEST is None:\n
raise Unauthorized\n
raise Unauthorized\n
\n
\n
response = REQUEST.RESPONSE\n
response = REQUEST.RESPONSE\n
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.software\'\n
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.software
_installation
\'\n
\n
\n
if REQUEST.other[\'method\'] != "GET":\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
response.setStatus(405)\n
...
@@ -78,15 +78,17 @@ else:\n
...
@@ -78,15 +78,17 @@ else:\n
\n
\n
import json\n
import json\n
result_dict = {\n
result_dict = {\n
\'_class\': \'slapos.org.software\',\n
\'_class\': \'slapos.org.software
_installation
\',\n
\'title\': context.getTitle(),\n
\'title\': context.getTitle(),\n
\'software_url\': context.getUrlString(),\n
\'status\': state,\n
\'status\': state,\n
\'_links\': {\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl(),\n
"self": { "href": context.Base_getRequestUrl(),\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.software" },\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.software
_installation
" },\n
},\n
},\n
}\n
}\n
url_string = context.getUrlString(None)\n
if url_string is not None:\n
result_dict["_links"]["software_release"] = { "href": url_string }\n
\n
\n
response.setHeader(\'Content-Type\', type)\n
response.setHeader(\'Content-Type\', type)\n
return json.dumps(result_dict)\n
return json.dumps(result_dict)\n
...
@@ -98,7 +100,7 @@ else:\n
...
@@ -98,7 +100,7 @@ else:\n
</item>
</item>
<item>
<item>
<key>
<string>
id
</string>
</key>
<key>
<string>
id
</string>
</key>
<value>
<string>
Software_getHateoas
</string>
</value>
<value>
<string>
Software
Installation
_getHateoas
</string>
</value>
</item>
</item>
</dictionary>
</dictionary>
</pickle>
</pickle>
...
...
master/bt5/slapos_hypermedia/TestTemplateItem/testSlapOSHypermediaScenario.py
View file @
f932e38f
...
@@ -322,7 +322,7 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
...
@@ -322,7 +322,7 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
# Get user's software
# Get user's software
#####################################################
#####################################################
content_type
=
"application/vnd.slapos.org.hal+json; "
\
content_type
=
"application/vnd.slapos.org.hal+json; "
\
"class=slapos.org.software"
"class=slapos.org.software
_installation
"
software_link_dict
=
software_collection_hal
[
'_links'
]
\
software_link_dict
=
software_collection_hal
[
'_links'
]
\
[
'item'
][
0
]
[
'item'
][
0
]
...
...
master/bt5/slapos_hypermedia/TestTemplateItem/testSlapOSHypermediaSkins.py
View file @
f932e38f
...
@@ -327,6 +327,12 @@ class TestSlapOSPerson_getHateoas(testSlapOSMixin):
...
@@ -327,6 +327,12 @@ class TestSlapOSPerson_getHateoas(testSlapOSMixin):
"method"
:
"POST"
,
"method"
:
"POST"
,
"type"
:
"application/json; class=slapos.org.hosting_subscription"
,
"type"
:
"application/json; class=slapos.org.hosting_subscription"
,
},
},
"http://slapos.org/reg/computer"
:
{
"href"
:
"%s/Person_getHateoasComputerList"
%
\
person_user
.
absolute_url
(),
"type"
:
"application/vnd.slapos.org.hal+json; "
\
"class=slapos.org.collection"
,
},
"http://slapos.org/reg/hosting_subscription"
:
{
"http://slapos.org/reg/hosting_subscription"
:
{
"href"
:
"%s/Person_getHateoasHostingSubscriptionList"
%
\
"href"
:
"%s/Person_getHateoasHostingSubscriptionList"
%
\
person_user
.
absolute_url
(),
person_user
.
absolute_url
(),
...
@@ -921,30 +927,7 @@ class TestSlapOSInstance_getHateoasNews(testSlapOSMixin):
...
@@ -921,30 +927,7 @@ class TestSlapOSInstance_getHateoasNews(testSlapOSMixin):
},
},
})))
})))
class
ComputerAndSoftwareMixin
(
testSlapOSMixin
):
class
TestSlapOSPerson_getHateoasComputerList
(
testSlapOSMixin
):
script_name
=
None
def
afterSetUp
(
self
):
self
.
logout
()
self
.
login
(
'ERP5TypeTestCase'
)
self
.
erp5_person
=
self
.
_makePerson
()
#self.logout()
self
.
login
(
self
.
erp5_person
.
getReference
())
self
.
portal
.
portal_slap
.
requestComputer
(
"computer %s"
%
self
.
erp5_person
.
getReference
())
self
.
tic
()
self
.
computer
=
self
.
portal
.
portal_catalog
(
portal_type
=
"Computer"
,
sort_on
=
[(
'creation_date'
,
'descending'
)])[
0
].
getObject
()
self
.
tic
()
self
.
portal
.
portal_slap
.
supplySupply
(
"http://foo.com/software.cfg"
,
self
.
computer
.
getReference
(),
"available"
)
self
.
tic
()
self
.
software_installation
=
self
.
portal
.
portal_catalog
(
portal_type
=
"Software Installation"
,
aggregate_relative_url
=
self
.
computer
.
getRelativeUrl
())[
0
].
getObject
()
def
_makePerson
(
self
):
def
_makePerson
(
self
):
new_id
=
self
.
generateNewId
()
new_id
=
self
.
generateNewId
()
...
@@ -962,66 +945,62 @@ class ComputerAndSoftwareMixin(testSlapOSMixin):
...
@@ -962,66 +945,62 @@ class ComputerAndSoftwareMixin(testSlapOSMixin):
self
.
tic
()
self
.
tic
()
return
person_user
return
person_user
def
test_REQUEST_mandatory
(
self
):
def
_makeComputer
(
self
):
computer
=
self
.
portal
.
computer_module
\
.
template_computer
.
Base_createCloneDocument
(
batch_mode
=
1
)
computer
.
validate
()
return
computer
def
test_getHateoasComputerList_REQUEST_mandatory
(
self
):
self
.
assertRaises
(
self
.
assertRaises
(
Unauthorized
,
Unauthorized
,
getattr
(
self
.
portal
,
self
.
script_name
)
self
.
portal
.
Person_getHateoasComputerList
)
)
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
'return "application/vnd+bar"'
)
'return "application/vnd+bar"'
)
def
test_wrong_ACCEPT
(
self
):
def
test_
getHateoasComputerList_
wrong_ACCEPT
(
self
):
fake_request
=
do_fake_request
(
"GET"
)
fake_request
=
do_fake_request
(
"GET"
)
result
=
getattr
(
self
.
portal
,
self
.
script_name
)
(
REQUEST
=
fake_request
)
result
=
self
.
portal
.
Person_getHateoasComputerList
(
REQUEST
=
fake_request
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
406
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
406
)
self
.
assertEquals
(
result
,
""
)
self
.
assertEquals
(
result
,
""
)
def
test_bad_method
(
self
):
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
'return "application/vnd.slapos.org.hal+json; '
\
'return "application/vnd.slapos.org.hal+json; '
\
'class='
+
self
.
json_class
+
'
"'
)
'class=slapos.org.collection
"'
)
def
check
_bad_method
(
self
):
def
test_getHateoasComputerList
_bad_method
(
self
):
fake_request
=
do_fake_request
(
"POST"
)
fake_request
=
do_fake_request
(
"POST"
)
result
=
getattr
(
self
.
portal
,
self
.
script_name
)(
REQUEST
=
fake_request
)
result
=
self
.
portal
.
Person_getHateoasComputerList
(
REQUEST
=
fake_request
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
405
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
405
)
self
.
assertEquals
(
result
,
""
)
self
.
assertEquals
(
result
,
""
)
check_bad_method
(
self
)
def
test_request_not_correct_context
(
self
):
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
'return "application/vnd.slapos.org.hal+json; '
\
'return "application/vnd.slapos.org.hal+json; '
\
'class='
+
self
.
json_class
+
'
"'
)
'class=slapos.org.collection
"'
)
def
check
_not_correct_context
(
self
):
def
test_getHateoasComputerList_request
_not_correct_context
(
self
):
fake_request
=
do_fake_request
(
"GET"
)
fake_request
=
do_fake_request
(
"GET"
)
result
=
getattr
(
self
.
portal
,
self
.
script_name
)
(
REQUEST
=
fake_request
)
result
=
self
.
portal
.
Person_getHateoasComputerList
(
REQUEST
=
fake_request
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
403
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
403
)
self
.
assertEquals
(
result
,
""
)
self
.
assertEquals
(
result
,
""
)
check_not_correct_context
(
self
)
def
checkResult
(
self
,
context
,
expected_data
):
@
simulate
(
'Base_getRequestUrl'
,
'*args, **kwargs'
,
@
simulate
(
'Base_getRequestUrl'
,
'*args, **kwargs'
,
'return "http://example.org/foo"'
)
'return "http://example.org/foo"'
)
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
'return "application/vnd.slapos.org.hal+json; '
\
'return "application/vnd.slapos.org.hal+json; '
\
'class='
+
self
.
json_class
+
'"'
)
'class=slapos.org.collection"'
)
def
check
(
self
):
def
test_getHateoasComputerList_result
(
self
):
person_user
=
self
.
_makePerson
()
computer
=
self
.
_makeComputer
()
computer
.
edit
(
source_administration_value
=
person_user
)
self
.
tic
()
fake_request
=
do_fake_request
(
"GET"
)
fake_request
=
do_fake_request
(
"GET"
)
result
=
getattr
(
context
,
self
.
script_name
)
(
REQUEST
=
fake_request
)
result
=
person_user
.
Person_getHateoasComputerList
(
REQUEST
=
fake_request
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
200
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
200
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
getHeader
(
'Content-Type'
),
self
.
assertEquals
(
fake_request
.
RESPONSE
.
getHeader
(
'Content-Type'
),
"application/vnd.slapos.org.hal+json; class="
+
self
.
json_class
"application/vnd.slapos.org.hal+json; class=slapos.org.collection"
)
)
self
.
assertEquals
(
result
,
json
.
dumps
(
expected_data
))
self
.
assertEquals
(
json
.
loads
(
result
),
json
.
loads
(
json
.
dumps
({
check
(
self
)
class
TestSlapOSPerson_getHateoasComputerList
(
ComputerAndSoftwareMixin
):
script_name
=
"Person_getHateoasComputerList"
json_class
=
"slapos.org.collection"
def
test_result
(
self
):
self
.
checkResult
(
self
.
erp5_person
,
{
'_class'
:
'slapos.org.collection'
,
'_class'
:
'slapos.org.collection'
,
'_links'
:
{
'_links'
:
{
"self"
:
{
"self"
:
{
...
@@ -1031,22 +1010,71 @@ class TestSlapOSPerson_getHateoasComputerList(ComputerAndSoftwareMixin):
...
@@ -1031,22 +1010,71 @@ class TestSlapOSPerson_getHateoasComputerList(ComputerAndSoftwareMixin):
},
},
"item"
:
[{
"item"
:
[{
"href"
:
"%s/Computer_getHateoas"
%
\
"href"
:
"%s/Computer_getHateoas"
%
\
self
.
computer
.
absolute_url
(),
computer
.
absolute_url
(),
"type"
:
"application/vnd.slapos.org.hal+json; "
\
"type"
:
"application/vnd.slapos.org.hal+json; "
\
"class=slapos.org.computer"
"class=slapos.org.computer"
}],
}],
},
},
})
})))
class
TestSlapOSComputer_getHateoas
(
testSlapOSMixin
):
def
_makeComputer
(
self
):
computer
=
self
.
portal
.
computer_module
\
.
template_computer
.
Base_createCloneDocument
(
batch_mode
=
1
)
computer
.
validate
()
self
.
tic
()
return
computer
def
test_getHateoasComputerList_REQUEST_mandatory
(
self
):
self
.
assertRaises
(
Unauthorized
,
self
.
portal
.
Computer_getHateoas
)
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
'return "application/vnd+bar"'
)
def
test_getHateoas_wrong_ACCEPT
(
self
):
fake_request
=
do_fake_request
(
"GET"
)
result
=
self
.
portal
.
Computer_getHateoas
(
REQUEST
=
fake_request
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
406
)
self
.
assertEquals
(
result
,
""
)
class
TestSlapOSComputer_getHateoas
(
ComputerAndSoftwareMixin
):
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
'return "application/vnd.slapos.org.hal+json; '
\
'class=slapos.org.computer"'
)
def
test_getHateoas_bad_method
(
self
):
fake_request
=
do_fake_request
(
"POST"
)
result
=
self
.
portal
.
Computer_getHateoas
(
REQUEST
=
fake_request
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
405
)
self
.
assertEquals
(
result
,
""
)
script_name
=
"Computer_getHateoas"
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
json_class
=
"slapos.org.computer"
'return "application/vnd.slapos.org.hal+json; '
\
'class=slapos.org.computer"'
)
def
test_getHateoas_request_not_correct_context
(
self
):
fake_request
=
do_fake_request
(
"GET"
)
result
=
self
.
portal
.
Computer_getHateoas
(
REQUEST
=
fake_request
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
403
)
self
.
assertEquals
(
result
,
""
)
def
test_result
(
self
):
@
simulate
(
'Base_getRequestUrl'
,
'*args, **kwargs'
,
self
.
checkResult
(
self
.
computer
,
{
'return "http://example.org/foo"'
)
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
'return "application/vnd.slapos.org.hal+json; '
\
'class=slapos.org.computer"'
)
def
test_getHateoas_result
(
self
):
computer
=
self
.
_makeComputer
()
fake_request
=
do_fake_request
(
"GET"
)
result
=
computer
.
Computer_getHateoas
(
REQUEST
=
fake_request
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
200
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
getHeader
(
'Content-Type'
),
"application/vnd.slapos.org.hal+json; class=slapos.org.computer"
)
self
.
assertEquals
(
json
.
loads
(
result
),
json
.
loads
(
json
.
dumps
({
'_class'
:
'slapos.org.computer'
,
'_class'
:
'slapos.org.computer'
,
'title'
:
self
.
computer
.
getTitle
(),
'title'
:
computer
.
getTitle
(),
'_links'
:
{
'_links'
:
{
"self"
:
{
"self"
:
{
"href"
:
"http://example.org/foo"
,
"href"
:
"http://example.org/foo"
,
...
@@ -1054,21 +1082,81 @@ class TestSlapOSComputer_getHateoas(ComputerAndSoftwareMixin):
...
@@ -1054,21 +1082,81 @@ class TestSlapOSComputer_getHateoas(ComputerAndSoftwareMixin):
"class=slapos.org.computer"
"class=slapos.org.computer"
},
},
"http://slapos.org/reg/software"
:
{
"http://slapos.org/reg/software"
:
{
"href"
:
"%s/Computer_getHateoasSoftwareList"
%
\
"href"
:
"%s/Computer_getHateoasSoftware
Installation
List"
%
\
self
.
computer
.
absolute_url
(),
computer
.
absolute_url
(),
"type"
:
"application/vnd.slapos.org.hal+json; "
\
"type"
:
"application/vnd.slapos.org.hal+json; "
\
"class=slapos.org.collection"
"class=slapos.org.collection"
},
},
},
},
})
})))
class
TestSlapOSComputer_getHateoasSoftwareInstallationList
(
testSlapOSMixin
):
def
_makeComputer
(
self
):
computer
=
self
.
portal
.
computer_module
\
.
template_computer
.
Base_createCloneDocument
(
batch_mode
=
1
)
computer
.
validate
()
return
computer
def
_makeSoftwareInstallation
(
self
):
software_installation
=
self
.
portal
.
software_installation_module
\
.
template_software_installation
.
Base_createCloneDocument
(
batch_mode
=
1
)
software_installation
.
validate
()
return
software_installation
def
test_getSoftwareInstallationList_REQUEST_mandatory
(
self
):
self
.
assertRaises
(
Unauthorized
,
self
.
portal
.
Computer_getHateoasSoftwareInstallationList
)
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
'return "application/vnd+bar"'
)
def
test_getSoftwareInstallationList_wrong_ACCEPT
(
self
):
fake_request
=
do_fake_request
(
"GET"
)
result
=
self
.
portal
.
Computer_getHateoasSoftwareInstallationList
(
REQUEST
=
fake_request
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
406
)
self
.
assertEquals
(
result
,
""
)
class
TestSlapOSComputer_getSoftwareList
(
ComputerAndSoftwareMixin
):
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
'return "application/vnd.slapos.org.hal+json; '
\
'class=slapos.org.collection"'
)
def
test_getSoftwareInstallationList_bad_method
(
self
):
fake_request
=
do_fake_request
(
"POST"
)
result
=
self
.
portal
.
Computer_getHateoasSoftwareInstallationList
(
REQUEST
=
fake_request
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
405
)
self
.
assertEquals
(
result
,
""
)
script_name
=
"Computer_getHateoasSoftwareList"
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
json_class
=
"slapos.org.collection"
'return "application/vnd.slapos.org.hal+json; '
\
'class=slapos.org.collection"'
)
def
test_getSoftwareInstallationList_request_not_correct_context
(
self
):
fake_request
=
do_fake_request
(
"GET"
)
result
=
self
.
portal
.
Computer_getHateoasSoftwareInstallationList
(
REQUEST
=
fake_request
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
403
)
self
.
assertEquals
(
result
,
""
)
def
test_result
(
self
):
@
simulate
(
'Base_getRequestUrl'
,
'*args, **kwargs'
,
self
.
checkResult
(
self
.
computer
,
{
'return "http://example.org/foo"'
)
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
'return "application/vnd.slapos.org.hal+json; '
\
'class=slapos.org.collection"'
)
def
test_getSoftwareInstallationList_result
(
self
):
computer
=
self
.
_makeComputer
()
software_installation
=
self
.
_makeSoftwareInstallation
()
software_installation
.
edit
(
aggregate_value
=
computer
)
self
.
tic
()
fake_request
=
do_fake_request
(
"GET"
)
result
=
computer
.
Computer_getHateoasSoftwareInstallationList
(
REQUEST
=
fake_request
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
200
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
getHeader
(
'Content-Type'
),
"application/vnd.slapos.org.hal+json; class=slapos.org.collection"
)
self
.
assertEquals
(
json
.
loads
(
result
),
json
.
loads
(
json
.
dumps
({
'_class'
:
'slapos.org.collection'
,
'_class'
:
'slapos.org.collection'
,
'_links'
:
{
'_links'
:
{
"self"
:
{
"self"
:
{
...
@@ -1077,30 +1165,84 @@ class TestSlapOSComputer_getSoftwareList(ComputerAndSoftwareMixin):
...
@@ -1077,30 +1165,84 @@ class TestSlapOSComputer_getSoftwareList(ComputerAndSoftwareMixin):
"class=slapos.org.collection"
"class=slapos.org.collection"
},
},
"item"
:
[{
"item"
:
[{
"href"
:
"%s/Software_getHateoas"
%
\
"href"
:
"%s/Software
Installation
_getHateoas"
%
\
s
elf
.
s
oftware_installation
.
absolute_url
(),
software_installation
.
absolute_url
(),
"type"
:
"application/vnd.slapos.org.hal+json; "
\
"type"
:
"application/vnd.slapos.org.hal+json; "
\
"class=slapos.org.software"
"class=slapos.org.software
_installation
"
}],
}],
},
},
})
})))
class
TestSlapOSSoftwareInstallation_getHateoas
(
testSlapOSMixin
):
class
TestSlapOSSoftware_getHateoas
(
ComputerAndSoftwareMixin
):
def
_makeSoftwareInstallation
(
self
):
software_installation
=
self
.
portal
.
software_installation_module
\
.
template_software_installation
.
Base_createCloneDocument
(
batch_mode
=
1
)
software_installation
.
validate
()
return
software_installation
script_name
=
"Software_getHateoas"
def
test_getHateoas_REQUEST_mandatory
(
self
):
json_class
=
"slapos.org.software"
self
.
assertRaises
(
Unauthorized
,
self
.
portal
.
SoftwareInstallation_getHateoas
)
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
'return "application/vnd+bar"'
)
def
test_getHateoas_wrong_ACCEPT
(
self
):
fake_request
=
do_fake_request
(
"GET"
)
result
=
self
.
portal
.
SoftwareInstallation_getHateoas
(
REQUEST
=
fake_request
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
406
)
self
.
assertEquals
(
result
,
""
)
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
'return "application/vnd.slapos.org.hal+json; '
\
'class=slapos.org.software_installation"'
)
def
test_getHateoas_bad_method
(
self
):
fake_request
=
do_fake_request
(
"POST"
)
result
=
self
.
portal
.
SoftwareInstallation_getHateoas
(
REQUEST
=
fake_request
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
405
)
self
.
assertEquals
(
result
,
""
)
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
'return "application/vnd.slapos.org.hal+json; '
\
'class=slapos.org.software_installation"'
)
def
test_getHateoas_request_not_correct_context
(
self
):
fake_request
=
do_fake_request
(
"GET"
)
result
=
self
.
portal
.
SoftwareInstallation_getHateoas
(
REQUEST
=
fake_request
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
403
)
self
.
assertEquals
(
result
,
""
)
def
test_result
(
self
):
@
simulate
(
'Base_getRequestUrl'
,
'*args, **kwargs'
,
self
.
checkResult
(
self
.
software_installation
,
{
'return "http://example.org/foo"'
)
'_class'
:
'slapos.org.software'
,
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
'title'
:
self
.
software_installation
.
getTitle
(),
'return "application/vnd.slapos.org.hal+json; '
\
'class=slapos.org.software_installation"'
)
def
test_getHateoas_result
(
self
):
software_installation
=
self
.
_makeSoftwareInstallation
()
software_installation
.
edit
(
url_string
=
"http://foo.com/software.cfg"
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
software_installation
,
'start_requested'
)
fake_request
=
do_fake_request
(
"GET"
)
result
=
software_installation
.
SoftwareInstallation_getHateoas
(
REQUEST
=
fake_request
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
200
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
getHeader
(
'Content-Type'
),
"application/vnd.slapos.org.hal+json; class=slapos.org.software_installation"
)
self
.
assertEquals
(
json
.
loads
(
result
),
json
.
loads
(
json
.
dumps
({
'_class'
:
'slapos.org.software_installation'
,
'title'
:
software_installation
.
getTitle
(),
'status'
:
'started'
,
'status'
:
'started'
,
'software_url'
:
"http://foo.com/software.cfg"
,
'_links'
:
{
'_links'
:
{
"self"
:
{
"self"
:
{
"href"
:
"http://example.org/foo"
,
"href"
:
"http://example.org/foo"
,
"type"
:
"application/vnd.slapos.org.hal+json; "
\
"type"
:
"application/vnd.slapos.org.hal+json; "
\
"class=slapos.org.software"
"class=slapos.org.software
_installation
"
},
},
"software_release"
:
{
"href"
:
"http://foo.com/software.cfg"
,
},
},
})
},
})))
master/bt5/slapos_hypermedia/bt/revision
View file @
f932e38f
3
4
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment