Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
snf-occi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
itminedu
snf-occi
Commits
1b369c3e
Commit
1b369c3e
authored
Oct 18, 2016
by
Stavros Sachtouris
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit tests for Synnefo/kamaki app
parent
6077c3a6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
105 additions
and
0 deletions
+105
-0
soi/tests/unit/synnefo.py
soi/tests/unit/synnefo.py
+105
-0
No files found.
soi/tests/unit/synnefo.py
0 → 100644
View file @
1b369c3e
# Copyright (C) 2016 GRNET S.A.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
from
soi
import
synnefo
from
mock
import
patch
from
json
import
dumps
def
test__stringify_json_values
():
"""Make strings of all single values in a json"""
examples
=
(
(
# Simple case, trouble free
{
'a'
:
'a'
,
'b'
:
[
'a'
,
'b'
],
'c'
:
{
'a'
:
'a'
,
'b'
:
'b'
}},
{
'a'
:
'a'
,
'b'
:
[
'a'
,
'b'
],
'c'
:
{
'a'
:
'a'
,
'b'
:
'b'
}},
),
(
# Numbers as values and 1 level nesting
{
'a'
:
1
,
'b'
:
[
1
,
'b'
],
'c'
:
{
'a'
:
'a'
,
'b'
:
2
}},
{
'a'
:
'1'
,
'b'
:
[
'1'
,
'b'
],
'c'
:
{
'a'
:
'a'
,
'b'
:
'2'
}},
),
(
# Numbers as keys must stay unchanged
{
1
:
'a'
,
'b'
:
[
1
,
'b'
],
3
:
{
1
:
'a'
,
'b'
:
2
}},
{
1
:
'a'
,
'b'
:
[
'1'
,
'b'
],
3
:
{
1
:
'a'
,
'b'
:
'2'
}},
),
(
# 2-level nesting
{
'a'
:
1
,
'b'
:
[{
1
:
1
,
2
:
'2'
},
'b'
],
'c'
:
{
'a'
:
'a'
,
'b'
:
[
1
,
'2'
,
'c'
]}},
{
'a'
:
'1'
,
'b'
:
[{
1
:
'1'
,
2
:
'2'
},
'b'
],
'c'
:
{
'a'
:
'a'
,
'b'
:
[
'1'
,
'2'
,
'c'
]}},
)
)
for
input_
,
output_
in
examples
:
r
=
synnefo
.
_stringify_json_values
(
input_
)
assert
r
==
output_
class
DummyResponse
:
status_code
=
1000
status
=
'status'
headers
=
{
'content-length'
:
'10'
,
'content-type'
:
'application/json'
}
json
=
{
"a"
:
"b"
}
content
=
dumps
(
json
)
def
my_method
(
cls
,
*
args
,
**
kwargs
):
"""dummy method"""
return
DummyResponse
()
def
start_response
(
*
args
,
**
kwargs
):
"""dummy method"""
synnefo
.
start_response
=
start_response
synnefo
.
CycladesNetworkClient
.
my_method
=
my_method
synnefo
.
CycladesComputeClient
.
my_method
=
my_method
@
patch
(
'soi.synnefo.start_response'
)
def
test_call_kamaki_compute
(
start_response
):
"""This is the Synnefo-end of the application"""
environ
=
dict
(
method_name
=
'my_method'
,
service_type
=
'compute'
,
HTTP_X_AUTH_TOKEN
=
'my-token'
)
r
=
synnefo
.
call_kamaki
(
environ
,
start_response
)
assert
r
==
DummyResponse
.
content
@
patch
(
'soi.synnefo.start_response'
)
def
test_call_kamaki_compute_no_body
(
start_response
):
environ
=
dict
(
method_name
=
'my_method'
,
service_type
=
'compute'
,
HTTP_X_AUTH_TOKEN
=
'my-token'
)
DummyResponse
.
json
=
None
DummyResponse
.
content
=
None
r
=
synnefo
.
call_kamaki
(
environ
,
start_response
)
assert
r
==
''
@
patch
(
'soi.synnefo.start_response'
)
def
test_call_kamaki_network
(
start_response
):
environ
=
dict
(
method_name
=
'my_method'
,
service_type
=
'network'
,
HTTP_X_AUTH_TOKEN
=
'my-token'
)
DummyResponse
.
json
=
{
'b'
:
'c'
}
DummyResponse
.
content
=
dumps
(
DummyResponse
.
json
)
r
=
synnefo
.
call_kamaki
(
environ
,
start_response
)
assert
r
==
DummyResponse
.
content
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