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
Nicolas Wavrant
slapos.core
Commits
1b39608d
Commit
1b39608d
authored
May 04, 2012
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Software instance bang testing (WIP).
Also factorise code to avoid repetition and increase readability.
parent
b7ffabe1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
24 deletions
+128
-24
master/bt5/vifib_slapos_rest_api_v1_test/TestTemplateItem/testVifibSlaposRestAPIV1.py
..._api_v1_test/TestTemplateItem/testVifibSlaposRestAPIV1.py
+127
-23
master/bt5/vifib_slapos_rest_api_v1_test/bt/revision
master/bt5/vifib_slapos_rest_api_v1_test/bt/revision
+1
-1
No files found.
master/bt5/vifib_slapos_rest_api_v1_test/TestTemplateItem/testVifibSlaposRestAPIV1.py
View file @
1b39608d
...
@@ -8,7 +8,7 @@ import tempfile
...
@@ -8,7 +8,7 @@ import tempfile
import
os
import
os
import
xml_marshaller
import
xml_marshaller
class
Person_requestSoftwareInstance
Simulator
:
class
Simulator
:
def
__init__
(
self
,
outfile
):
def
__init__
(
self
,
outfile
):
self
.
outfile
=
outfile
self
.
outfile
=
outfile
...
@@ -16,7 +16,7 @@ class Person_requestSoftwareInstanceSimulator:
...
@@ -16,7 +16,7 @@ class Person_requestSoftwareInstanceSimulator:
"""Simulation Method"""
"""Simulation Method"""
open
(
self
.
outfile
,
'a'
).
write
(
'recargs = %r
\
n
reckwargs = %r'
%
(
args
,
kwargs
))
open
(
self
.
outfile
,
'a'
).
write
(
'recargs = %r
\
n
reckwargs = %r'
%
(
args
,
kwargs
))
class
Person_requestSoftwareInstanceRaisingSimulator
(
Person_requestSoftwareInstance
Simulator
):
class
RaisingSimulator
(
Simulator
):
def
__init__
(
self
,
exception
):
def
__init__
(
self
,
exception
):
self
.
exception
=
exception
self
.
exception
=
exception
...
@@ -50,8 +50,7 @@ class VifibSlaposRestAPIV1Mixin(ERP5TypeTestCase):
...
@@ -50,8 +50,7 @@ class VifibSlaposRestAPIV1Mixin(ERP5TypeTestCase):
for
assignment
in
customer
.
contentValues
(
portal_type
=
'Assignment'
):
for
assignment
in
customer
.
contentValues
(
portal_type
=
'Assignment'
):
assignment
.
open
()
assignment
.
open
()
customer
.
requestSoftwareInstance
=
Person_requestSoftwareInstanceSimulator
(
customer
.
requestSoftwareInstance
=
Simulator
(
self
.
person_request_simulator
)
self
.
simulator
)
transaction
.
commit
()
transaction
.
commit
()
customer
.
recursiveImmediateReindexObject
()
customer
.
recursiveImmediateReindexObject
()
...
@@ -80,13 +79,13 @@ class VifibSlaposRestAPIV1Mixin(ERP5TypeTestCase):
...
@@ -80,13 +79,13 @@ class VifibSlaposRestAPIV1Mixin(ERP5TypeTestCase):
'Content-Type'
:
'application/json'
,
'Content-Type'
:
'application/json'
,
})
})
self
.
simulator
=
tempfile
.
mkstemp
()[
1
]
self
.
person_request_
simulator
=
tempfile
.
mkstemp
()[
1
]
self
.
customer
,
self
.
customer_reference
=
self
.
createPerson
()
self
.
customer
,
self
.
customer_reference
=
self
.
createPerson
()
transaction
.
commit
()
transaction
.
commit
()
def
beforeTearDown
(
self
):
def
beforeTearDown
(
self
):
if
os
.
path
.
exists
(
self
.
simulator
):
if
os
.
path
.
exists
(
self
.
person_request_
simulator
):
os
.
unlink
(
self
.
simulator
)
os
.
unlink
(
self
.
person_request_
simulator
)
def
cloneByPath
(
self
,
path
):
def
cloneByPath
(
self
,
path
):
return
self
.
portal
.
restrictedTraverse
(
path
).
Base_createCloneDocument
(
return
self
.
portal
.
restrictedTraverse
(
path
).
Base_createCloneDocument
(
...
@@ -116,14 +115,14 @@ class VifibSlaposRestAPIV1Mixin(ERP5TypeTestCase):
...
@@ -116,14 +115,14 @@ class VifibSlaposRestAPIV1Mixin(ERP5TypeTestCase):
def
assertResponseNoContentType
(
self
):
def
assertResponseNoContentType
(
self
):
self
.
assertEqual
(
self
.
response
.
getheader
(
'Content-Type'
),
None
)
self
.
assertEqual
(
self
.
response
.
getheader
(
'Content-Type'
),
None
)
def
assertSimulatorEmpty
(
self
):
def
assert
PersonRequest
SimulatorEmpty
(
self
):
self
.
assertEqual
(
open
(
self
.
simulator
).
read
(),
''
)
self
.
assertEqual
(
open
(
self
.
person_request_
simulator
).
read
(),
''
)
def
assertSimulator
(
self
,
args
,
kwargs
):
def
assert
PersonRequest
Simulator
(
self
,
args
,
kwargs
):
# fillup magic
# fillup magic
recargs
=
()
recargs
=
()
reckwargs
=
{}
reckwargs
=
{}
exec
(
open
(
self
.
simulator
).
read
())
exec
(
open
(
self
.
person_request_
simulator
).
read
())
# do the same translation magic as in tool
# do the same translation magic as in tool
kwargs
=
kwargs
.
copy
()
kwargs
=
kwargs
.
copy
()
for
k_j
,
k_i
in
(
for
k_j
,
k_i
in
(
...
@@ -152,7 +151,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
...
@@ -152,7 +151,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
auth
=
self
.
response
.
getheader
(
'WWW-Authenticate'
)
auth
=
self
.
response
.
getheader
(
'WWW-Authenticate'
)
self
.
assertTrue
(
auth
is
not
None
)
self
.
assertTrue
(
auth
is
not
None
)
self
.
assertTrue
(
'Bearer realm="'
in
auth
)
self
.
assertTrue
(
'Bearer realm="'
in
auth
)
self
.
assertSimulatorEmpty
()
self
.
assert
PersonRequest
SimulatorEmpty
()
def
test_no_json
(
self
):
def
test_no_json
(
self
):
self
.
connection
.
request
(
method
=
'POST'
,
self
.
connection
.
request
(
method
=
'POST'
,
...
@@ -164,7 +163,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
...
@@ -164,7 +163,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
self
.
assertResponseJson
()
self
.
assertResponseJson
()
self
.
assertTrue
(
'error'
in
self
.
json_response
)
self
.
assertTrue
(
'error'
in
self
.
json_response
)
self
.
assertEqual
(
"Data is not json object."
,
self
.
json_response
[
'error'
])
self
.
assertEqual
(
"Data is not json object."
,
self
.
json_response
[
'error'
])
self
.
assertSimulatorEmpty
()
self
.
assert
PersonRequest
SimulatorEmpty
()
def
test_bad_json
(
self
):
def
test_bad_json
(
self
):
self
.
connection
.
request
(
method
=
'POST'
,
self
.
connection
.
request
(
method
=
'POST'
,
...
@@ -177,7 +176,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
...
@@ -177,7 +176,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
self
.
assertResponseJson
()
self
.
assertResponseJson
()
self
.
assertTrue
(
'error'
in
self
.
json_response
)
self
.
assertTrue
(
'error'
in
self
.
json_response
)
self
.
assertEqual
(
"Data is not json object."
,
self
.
json_response
[
'error'
])
self
.
assertEqual
(
"Data is not json object."
,
self
.
json_response
[
'error'
])
self
.
assertSimulatorEmpty
()
self
.
assert
PersonRequest
SimulatorEmpty
()
def
test_empty_json
(
self
):
def
test_empty_json
(
self
):
self
.
connection
.
request
(
method
=
'POST'
,
self
.
connection
.
request
(
method
=
'POST'
,
...
@@ -197,7 +196,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
...
@@ -197,7 +196,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
"parameter"
:
"Missing."
,
"parameter"
:
"Missing."
,
"sla"
:
"Missing."
},
"sla"
:
"Missing."
},
self
.
json_response
)
self
.
json_response
)
self
.
assertSimulatorEmpty
()
self
.
assert
PersonRequest
SimulatorEmpty
()
def
test_status_slave_missing_json
(
self
):
def
test_status_slave_missing_json
(
self
):
self
.
connection
.
request
(
method
=
'POST'
,
self
.
connection
.
request
(
method
=
'POST'
,
...
@@ -229,7 +228,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
...
@@ -229,7 +228,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
"slave"
:
"Missing."
"slave"
:
"Missing."
},
},
self
.
json_response
)
self
.
json_response
)
self
.
assertSimulatorEmpty
()
self
.
assert
PersonRequest
SimulatorEmpty
()
def
test_slave_not_bool
(
self
):
def
test_slave_not_bool
(
self
):
kwargs
=
{
kwargs
=
{
...
@@ -256,7 +255,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
...
@@ -256,7 +255,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
"slave"
:
"Not boolean."
,
"slave"
:
"Not boolean."
,
},
},
self
.
json_response
)
self
.
json_response
)
self
.
assertSimulatorEmpty
()
self
.
assert
PersonRequest
SimulatorEmpty
()
def
test_correct
(
self
):
def
test_correct
(
self
):
kwargs
=
{
kwargs
=
{
...
@@ -279,7 +278,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
...
@@ -279,7 +278,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
self
.
assertBasicResponse
()
self
.
assertBasicResponse
()
self
.
assertResponseCode
(
202
)
self
.
assertResponseCode
(
202
)
self
.
assertResponseJson
()
self
.
assertResponseJson
()
self
.
assertSimulator
((),
kwargs
)
self
.
assert
PersonRequest
Simulator
((),
kwargs
)
self
.
assertEqual
({
self
.
assertEqual
({
"status"
:
"processing"
,
"status"
:
"processing"
,
},
},
...
@@ -287,7 +286,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
...
@@ -287,7 +286,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
def
test_correct_server_side_raise
(
self
):
def
test_correct_server_side_raise
(
self
):
self
.
customer
.
requestSoftwareInstance
=
\
self
.
customer
.
requestSoftwareInstance
=
\
Person_requestSoftwareInstance
RaisingSimulator
(
AttributeError
)
RaisingSimulator
(
AttributeError
)
transaction
.
commit
()
transaction
.
commit
()
kwargs
=
{
kwargs
=
{
'parameter'
:
{
'parameter'
:
{
...
@@ -313,7 +312,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
...
@@ -313,7 +312,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
"error"
:
"There is system issue, please try again later."
,
"error"
:
"There is system issue, please try again later."
,
},
},
self
.
json_response
)
self
.
json_response
)
self
.
assertSimulatorEmpty
()
self
.
assert
PersonRequest
SimulatorEmpty
()
def
test_content_negotiation_headers
(
self
):
def
test_content_negotiation_headers
(
self
):
self
.
connection
=
CustomHeaderHTTPConnection
(
host
=
self
.
api_netloc
,
self
.
connection
=
CustomHeaderHTTPConnection
(
host
=
self
.
api_netloc
,
...
@@ -344,7 +343,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
...
@@ -344,7 +343,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
'Content-Type'
:
"Header with value 'application/json' is required."
,
'Content-Type'
:
"Header with value 'application/json' is required."
,
'Accept'
:
"Header with value 'application/json' is required."
},
'Accept'
:
"Header with value 'application/json' is required."
},
self
.
json_response
)
self
.
json_response
)
self
.
assertSimulatorEmpty
()
self
.
assert
PersonRequest
SimulatorEmpty
()
# now check with incorrect headers
# now check with incorrect headers
self
.
connection
.
request
(
method
=
'POST'
,
self
.
connection
.
request
(
method
=
'POST'
,
...
@@ -361,7 +360,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
...
@@ -361,7 +360,7 @@ class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
'Content-Type'
:
"Header with value 'application/json' is required."
,
'Content-Type'
:
"Header with value 'application/json' is required."
,
'Accept'
:
"Header with value 'application/json' is required."
},
'Accept'
:
"Header with value 'application/json' is required."
},
self
.
json_response
)
self
.
json_response
)
self
.
assertSimulatorEmpty
()
self
.
assert
PersonRequest
SimulatorEmpty
()
# and with correct ones are set by default
# and with correct ones are set by default
class
TestInstanceOPTIONS
(
VifibSlaposRestAPIV1Mixin
):
class
TestInstanceOPTIONS
(
VifibSlaposRestAPIV1Mixin
):
...
@@ -376,7 +375,7 @@ class TestInstanceOPTIONS(VifibSlaposRestAPIV1Mixin):
...
@@ -376,7 +375,7 @@ class TestInstanceOPTIONS(VifibSlaposRestAPIV1Mixin):
self
.
assertBasicResponse
()
self
.
assertBasicResponse
()
self
.
assertResponseCode
(
204
)
self
.
assertResponseCode
(
204
)
self
.
assertResponseNoContentType
()
self
.
assertResponseNoContentType
()
self
.
assertSimulatorEmpty
()
self
.
assert
PersonRequest
SimulatorEmpty
()
class
VifibSlaposRestAPIV1InstanceMixin
(
VifibSlaposRestAPIV1Mixin
):
class
VifibSlaposRestAPIV1InstanceMixin
(
VifibSlaposRestAPIV1Mixin
):
def
afterSetUp
(
self
):
def
afterSetUp
(
self
):
...
@@ -564,3 +563,108 @@ class TestInstanceGETcertificate(VifibSlaposRestAPIV1InstanceMixin):
...
@@ -564,3 +563,108 @@ class TestInstanceGETcertificate(VifibSlaposRestAPIV1InstanceMixin):
self
.
prepareResponse
()
self
.
prepareResponse
()
self
.
assertBasicResponse
()
self
.
assertBasicResponse
()
self
.
assertResponseCode
(
404
)
self
.
assertResponseCode
(
404
)
class
VifibSlaposRestAPIV1BangMixin
(
VifibSlaposRestAPIV1InstanceMixin
):
def
afterSetUp
(
self
):
super
(
VifibSlaposRestAPIV1BangMixin
,
self
).
afterSetUp
()
self
.
instance_bang_simulator
=
tempfile
.
mkstemp
()[
1
]
self
.
software_instance
.
reportComputerPartitionBang
=
Simulator
(
self
.
instance_bang_simulator
)
transaction
.
commit
()
def
beforeTearDown
(
self
):
super
(
VifibSlaposRestAPIV1BangMixin
,
self
).
beforeTearDown
()
if
os
.
path
.
exists
(
self
.
instance_bang_simulator
):
os
.
unlink
(
self
.
instance_bang_simulator
)
def
assertInstanceBangSimulatorEmpty
(
self
):
self
.
assertEqual
(
open
(
self
.
instance_bang_simulator
).
read
(),
''
)
def
assertInstanceBangSimulator
(
self
,
args
,
kwargs
):
# fillup magic
recargs
=
()
reckwargs
=
{}
exec
(
open
(
self
.
instance_bang_simulator
).
read
())
# do the same translation magic as in workflow
kwargs
[
'comment'
]
=
kwargs
.
pop
(
'log'
)
self
.
assertEqual
(
args
,
recargs
)
self
.
assertEqual
(
kwargs
,
reckwargs
)
class
TestInstancePOSTbang
(
VifibSlaposRestAPIV1BangMixin
):
def
test
(
self
):
kwargs
=
{
'log'
:
'This is cool log!'
}
self
.
connection
.
request
(
method
=
'POST'
,
url
=
'/'
.
join
([
self
.
api_path
,
'instance'
,
self
.
software_instance
.
getRelativeUrl
(),
'bang'
]),
body
=
json
.
dumps
(
kwargs
),
headers
=
{
'REMOTE_USER'
:
self
.
customer_reference
})
self
.
prepareResponse
()
self
.
assertBasicResponse
()
self
.
assertResponseCode
(
204
)
self
.
assertInstanceBangSimulator
((),
kwargs
)
def
test_bad_xml
(
self
):
self
.
_destroySoftwareInstanceTextContentXml
(
self
.
software_instance
)
kwargs
=
{
'log'
:
'This is cool log!'
}
self
.
connection
.
request
(
method
=
'POST'
,
url
=
'/'
.
join
([
self
.
api_path
,
'instance'
,
self
.
software_instance
.
getRelativeUrl
(),
'bang'
]),
body
=
json
.
dumps
(
kwargs
),
headers
=
{
'REMOTE_USER'
:
self
.
customer_reference
})
self
.
prepareResponse
()
self
.
assertBasicResponse
()
self
.
assertResponseCode
(
500
)
self
.
assertResponseJson
()
self
.
assertEqual
({
"error"
:
"There is system issue, please try again later."
},
self
.
json_response
)
self
.
assertInstanceBangSimulatorEmpty
()
def
test_non_existing
(
self
):
non_existing
=
'software_instance_module/'
+
self
.
generateNewId
()
try
:
self
.
portal
.
restrictedTraverse
(
non_existing
)
except
KeyError
:
pass
else
:
raise
AssertionError
(
'It was impossible to test'
)
kwargs
=
{
'log'
:
'This is cool log!'
}
self
.
connection
.
request
(
method
=
'POST'
,
url
=
'/'
.
join
([
self
.
api_path
,
'instance'
,
self
.
software_instance
.
getRelativeUrl
(),
'bang'
]),
body
=
json
.
dumps
(
kwargs
),
headers
=
{
'REMOTE_USER'
:
self
.
customer_reference
})
self
.
prepareResponse
()
self
.
assertBasicResponse
()
self
.
assertResponseCode
(
404
)
self
.
assertInstanceBangSimulatorEmpty
()
def
test_something_else
(
self
):
kwargs
=
{
'log'
:
'This is cool log!'
}
self
.
connection
.
request
(
method
=
'POST'
,
url
=
'/'
.
join
([
self
.
api_path
,
'instance'
,
self
.
software_instance
.
getPredecessorRelatedValue
().
getRelativeUrl
(),
'bang'
]),
body
=
json
.
dumps
(
kwargs
),
headers
=
{
'REMOTE_USER'
:
self
.
customer_reference
})
self
.
prepareResponse
()
self
.
assertBasicResponse
()
self
.
assertResponseCode
(
404
)
self
.
assertInstanceBangSimulator
((),
kwargs
)
def
test_other_one
(
self
):
raise
NotImplementedError
def
test_no_json
(
self
):
raise
NotImplementedError
def
test_bad_json
(
self
):
raise
NotImplementedError
def
test_empty_json
(
self
):
raise
NotImplementedError
def
test_additional_key_json
(
self
):
raise
NotImplementedError
def
test_log_not_string
(
self
):
raise
NotImplementedError
master/bt5/vifib_slapos_rest_api_v1_test/bt/revision
View file @
1b39608d
20
21
\ 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