Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Simon János
/
orchestrator
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f5330dd2
authored
Dec 18, 2016
by
Simon János
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
api endpoint prefixed with version (v1)
parent
8267d5c4
Pipeline
#635
failed with stage
in 2 minutes 10 seconds
Changes
2
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
26 deletions
+27
-26
orchestrator/api/stacks.py
+2
-2
tests/test_api.py
+25
-24
No files found.
orchestrator/api/stacks.py
View file @
f5330dd2
...
...
@@ -99,8 +99,8 @@ def handle_bad_request(*args):
def
create_app
():
stack_controller
=
Stack
()
app
=
falcon
.
API
(
middleware
=
[
LoggingMiddleware
()])
app
.
add_route
(
'/stacks'
,
stack_controller
)
app
.
add_route
(
'/stacks/{stack_id}'
,
stack_controller
)
app
.
add_route
(
'/
v1/
stacks'
,
stack_controller
)
app
.
add_route
(
'/
v1/
stacks/{stack_id}'
,
stack_controller
)
app
.
add_error_handler
(
TypeError
,
handle_method_not_allowed
)
app
.
add_error_handler
(
InvalidResourceException
,
handle_bad_request
)
return
app
...
...
tests/test_api.py
View file @
f5330dd2
...
...
@@ -7,6 +7,7 @@ from mockito import mock, when, any # pylint: disable=redefined-builtin
from
orchestrator.api
import
stacks
API_ENDPOINT
=
'/v1/stacks'
TEST_INSTANCE_ARGS
=
{
'cpu_count'
:
2
,
'memory'
:
256
*
1000
*
1000
...
...
@@ -29,15 +30,15 @@ class StackTest(testing.TestCase):
super
(
StackTest
,
self
)
.
tearDown
()
def
test_stacks_api_allowed_methods_on_endpoints
(
self
):
self
.
assertEqual
(
HTTP_OK
,
self
.
simulate_get
(
'/stacks'
)
.
status
)
self
.
assertEqual
(
HTTP_NOT_FOUND
,
self
.
simulate_put
(
'/
stacks/42'
)
.
status
)
self
.
assertEqual
(
HTTP_NOT_FOUND
,
self
.
simulate_delete
(
'/
stacks/42'
)
.
status
)
self
.
assertEqual
(
HTTP_NOT_FOUND
,
self
.
simulate_get
(
'/
stacks/42'
)
.
status
)
self
.
assertEqual
(
HTTP_BAD_REQUEST
,
self
.
simulate_post
(
'/stacks'
)
.
status
)
self
.
assertEqual
(
HTTP_OK
,
self
.
simulate_get
(
API_ENDPOINT
)
.
status
)
self
.
assertEqual
(
HTTP_NOT_FOUND
,
self
.
simulate_put
(
'/
%
s/
%
s'
%
(
API_ENDPOINT
,
42
)
)
.
status
)
self
.
assertEqual
(
HTTP_NOT_FOUND
,
self
.
simulate_delete
(
'/
%
s/
%
s'
%
(
API_ENDPOINT
,
42
)
)
.
status
)
self
.
assertEqual
(
HTTP_NOT_FOUND
,
self
.
simulate_get
(
'/
%
s/
%
s'
%
(
API_ENDPOINT
,
42
)
)
.
status
)
self
.
assertEqual
(
HTTP_BAD_REQUEST
,
self
.
simulate_post
(
API_ENDPOINT
)
.
status
)
self
.
assertEqual
(
HTTP_METHOD_NOT_ALLOWED
,
self
.
simulate_post
(
'/
stacks/42'
)
.
status
)
self
.
assertEqual
(
HTTP_METHOD_NOT_ALLOWED
,
self
.
simulate_put
(
'/stacks'
)
.
status
)
self
.
assertEqual
(
HTTP_METHOD_NOT_ALLOWED
,
self
.
simulate_delete
(
'/stacks'
)
.
status
)
self
.
assertEqual
(
HTTP_METHOD_NOT_ALLOWED
,
self
.
simulate_post
(
'/
%
s/
%
s'
%
(
API_ENDPOINT
,
42
)
)
.
status
)
self
.
assertEqual
(
HTTP_METHOD_NOT_ALLOWED
,
self
.
simulate_put
(
API_ENDPOINT
)
.
status
)
self
.
assertEqual
(
HTTP_METHOD_NOT_ALLOWED
,
self
.
simulate_delete
(
API_ENDPOINT
)
.
status
)
def
test_stacks_api_create
(
self
):
# given
...
...
@@ -81,7 +82,7 @@ class StackTest(testing.TestCase):
}
# when
result
=
self
.
simulate_post
(
'/stacks'
,
body
=
json
.
dumps
(
stack_request_body
))
result
=
self
.
simulate_post
(
API_ENDPOINT
,
body
=
json
.
dumps
(
stack_request_body
))
# then
self
.
assertEqual
(
sort_resources
(
stack_request_body
),
sort_resources
(
result
.
json
))
...
...
@@ -92,7 +93,7 @@ class StackTest(testing.TestCase):
empty_request_body
=
'{}'
# when
result
=
self
.
simulate_post
(
'/stacks'
,
body
=
empty_request_body
,
headers
=
{
'content-type'
:
'application/json'
})
result
=
self
.
simulate_post
(
API_ENDPOINT
,
body
=
empty_request_body
,
headers
=
{
'content-type'
:
'application/json'
})
# then
self
.
assertIn
(
'id'
,
result
.
json
.
keys
())
...
...
@@ -103,7 +104,7 @@ class StackTest(testing.TestCase):
def
test_stacks_api_create_with_empty_body
(
self
):
# when
result
=
self
.
simulate_post
(
'/stacks'
,
headers
=
{
'content-type'
:
'application/json'
})
result
=
self
.
simulate_post
(
API_ENDPOINT
,
headers
=
{
'content-type'
:
'application/json'
})
# then
self
.
assertEqual
(
HTTP_BAD_REQUEST
,
result
.
status
)
...
...
@@ -117,7 +118,7 @@ class StackTest(testing.TestCase):
for
body
in
invalid_request_bodies
:
# when
result
=
self
.
simulate_post
(
'/stacks'
,
body
=
body
,
headers
=
{
'content-type'
:
'application/json'
})
result
=
self
.
simulate_post
(
API_ENDPOINT
,
body
=
body
,
headers
=
{
'content-type'
:
'application/json'
})
# then
self
.
assertEqual
(
HTTP_BAD_REQUEST
,
result
.
status
)
...
...
@@ -138,9 +139,9 @@ class StackTest(testing.TestCase):
}
# when
self
.
simulate_post
(
'/stacks'
,
body
=
json
.
dumps
(
group1
))
put_result
=
self
.
simulate_put
(
'/
stacks/
%
s'
%
stack_id
,
body
=
json
.
dumps
(
group2
))
get_result
=
self
.
simulate_get
(
'/stacks'
)
self
.
simulate_post
(
API_ENDPOINT
,
body
=
json
.
dumps
(
group1
))
put_result
=
self
.
simulate_put
(
'/
%
s/
%
s'
%
(
API_ENDPOINT
,
stack_id
)
,
body
=
json
.
dumps
(
group2
))
get_result
=
self
.
simulate_get
(
API_ENDPOINT
)
# then
self
.
assertEqual
(
expected_diff
,
put_result
.
json
)
...
...
@@ -153,10 +154,10 @@ class StackTest(testing.TestCase):
resource
.
update
(
TEST_INSTANCE_ARGS
)
# when
self
.
simulate_post
(
'/stacks'
,
body
=
json
.
dumps
(
resource
))
list_result_before_delete
=
self
.
simulate_get
(
'/stacks'
)
delete_result
=
self
.
simulate_delete
(
'/
stacks/
%
s'
%
resource_id
)
list_result_after_delete
=
self
.
simulate_get
(
'/stacks'
)
self
.
simulate_post
(
API_ENDPOINT
,
body
=
json
.
dumps
(
resource
))
list_result_before_delete
=
self
.
simulate_get
(
API_ENDPOINT
)
delete_result
=
self
.
simulate_delete
(
'/
%
s/
%
s'
%
(
API_ENDPOINT
,
resource_id
)
)
list_result_after_delete
=
self
.
simulate_get
(
API_ENDPOINT
)
# then
self
.
assertEqual
([
resource
],
list_result_before_delete
.
json
)
...
...
@@ -171,9 +172,9 @@ class StackTest(testing.TestCase):
resource2
.
update
(
TEST_INSTANCE_ARGS
)
# when
self
.
simulate_post
(
'/stacks'
,
body
=
json
.
dumps
(
resource1
))
self
.
simulate_post
(
'/stacks'
,
body
=
json
.
dumps
(
resource2
))
result
=
self
.
simulate_get
(
'/stacks'
)
.
json
self
.
simulate_post
(
API_ENDPOINT
,
body
=
json
.
dumps
(
resource1
))
self
.
simulate_post
(
API_ENDPOINT
,
body
=
json
.
dumps
(
resource2
))
result
=
self
.
simulate_get
(
API_ENDPOINT
)
.
json
# then
self
.
assertEqual
(
2
,
len
(
result
))
...
...
@@ -187,8 +188,8 @@ class StackTest(testing.TestCase):
resource
.
update
(
TEST_INSTANCE_ARGS
)
# when
self
.
simulate_post
(
'/stacks'
,
body
=
json
.
dumps
(
resource
))
result
=
self
.
simulate_get
(
'/
stacks/
%
s'
%
resource_id
)
.
json
self
.
simulate_post
(
API_ENDPOINT
,
body
=
json
.
dumps
(
resource
))
result
=
self
.
simulate_get
(
'/
%
s/
%
s'
%
(
API_ENDPOINT
,
resource_id
)
)
.
json
# then
self
.
assertEqual
([
resource
],
result
)
...
...
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