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
9c6303cc
authored
Nov 18, 2016
by
Simon János
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
getitem and delitem implemented on resource group
parent
c441a1af
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
1 deletions
+42
-1
orchestrator/model/resources.py
+6
-0
tests/test_resources.py
+36
-1
No files found.
orchestrator/model/resources.py
View file @
9c6303cc
...
@@ -130,6 +130,12 @@ class ResourceGroup(Resource):
...
@@ -130,6 +130,12 @@ class ResourceGroup(Resource):
except
InvalidResourceException
:
except
InvalidResourceException
:
del
self
.
__resources
[
resource
.
id
]
del
self
.
__resources
[
resource
.
id
]
def
__getitem__
(
self
,
resource_id
):
return
self
.
__resources
[
resource_id
]
def
__delitem__
(
self
,
resource_id
):
self
.
remove
(
self
[
resource_id
])
@property
@property
def
resources
(
self
):
def
resources
(
self
):
return
list
(
self
.
__resources
.
values
())
return
list
(
self
.
__resources
.
values
())
...
...
tests/test_resources.py
View file @
9c6303cc
from
__future__
import
print_function
import
copy
import
copy
import
json
import
json
from
unittest.case
import
TestCase
from
unittest.case
import
TestCase
...
@@ -208,7 +210,40 @@ class ResourceGroupTest(TestCase):
...
@@ -208,7 +210,40 @@ class ResourceGroupTest(TestCase):
# then
# then
self
.
assertEqual
([],
group
.
resources
)
self
.
assertEqual
([],
group
.
resources
)
# @skip('works same way as resource addition')
def
test_resource_group_del_item_by_id
(
self
):
# given
expected_resource_id
=
'some_resource'
expected_resource
=
Instance
(
id
=
expected_resource_id
)
group
=
ResourceGroup
(
resources
=
[
expected_resource
])
# when
del
group
[
expected_resource_id
]
# then
self
.
assertNotIn
(
expected_resource
,
group
.
resources
)
def
test_resource_group_del_invalid_id
(
self
):
# given
group
=
ResourceGroup
()
# then
with
self
.
assertRaises
(
KeyError
):
del
group
[
'invalid_resource_id'
]
def
test_resource_group_get_item_by_id
(
self
):
# given
expected_resource_id
=
'some_resource'
expected_resource
=
Instance
(
id
=
expected_resource_id
)
group
=
ResourceGroup
(
resources
=
[
expected_resource
])
# when
result
=
group
[
expected_resource_id
]
# then
self
.
assertEqual
(
expected_resource
,
result
)
with
self
.
assertRaises
(
KeyError
):
print
(
group
[
'invalid_resource_id'
])
def
test_resource_group_addition
(
self
):
def
test_resource_group_addition
(
self
):
# given
# given
group1
=
ResourceGroup
()
group1
=
ResourceGroup
()
...
...
Simon János
@kopridar
mentioned in commit
ecd35a12
Nov 18, 2016
mentioned in commit
ecd35a12
mentioned in commit ecd35a12d93c0f522f6133b9b5c68c571a072885
Toggle commit list
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