Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
RECIRCLE
/
portal
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
11
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3421dbd8
authored
Aug 14, 2019
by
Bodor Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update tests
parent
b1fc3c9d
Pipeline
#827
passed with stage
in 1 minute 23 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
12 deletions
+23
-12
recircle/image/tests/test_models_unit.py
+23
-12
No files found.
recircle/image/tests/test_models_unit.py
View file @
3421dbd8
...
...
@@ -10,6 +10,7 @@ from instance.models import Lease
from
interface_openstack.interface.image.image
import
Image
as
RemoteImage
from
interface_openstack.interface.vm.resources
import
Flavor
as
RemoteFlavor
from
template.models
import
ImageTemplate
class
ImageModelsTest
(
TestCase
):
...
...
@@ -19,11 +20,10 @@ class ImageModelsTest(TestCase):
@staticmethod
def
create_flavor
():
with
patch
(
'instance.models.OSVirtualMachineManager'
)
as
mock_interface
:
mock_interface
.
create_flavor
()
mock_interface
.
return_value
.
create_flavor
.
return_value
=
RemoteFlavor
(
"123456789"
,
"test_flavor"
,
2
,
1
,
1
)
with
patch
(
'instance.models.interface'
)
as
mock_interface
:
mock_interface
.
create_flavor
.
return_value
=
RemoteFlavor
(
"123456789"
,
"test_flavor"
,
2
,
1
,
1
)
return
Flavor
.
create
(
"test_flavor"
,
"test flavor description"
,
2
,
1
,
1
,
2
)
def
create_instance
(
self
):
...
...
@@ -40,7 +40,18 @@ class ImageModelsTest(TestCase):
suspend_interval_in_sec
=
100
,
delete_interval_in_sec
=
100
)
owner
=
self
.
create_user
(
"test_instance_user"
,
"instance_user"
,
"test_password"
)
remote_id
=
"123456789"
return
Instance
.
create
(
lease
,
owner
,
flavor
,
remote_id
,
params
)
image
=
Image
.
objects
.
create
(
name
=
"test_image"
,
description
=
"test image description"
,
uploaded_by_user
=
True
,
remote_id
=
"123456789123456789"
,
created_by
=
owner
)
template
=
ImageTemplate
.
objects
.
create
(
name
=
"test_template"
,
description
=
"test descripton"
,
image
=
image
,
lease
=
lease
,
flavor
=
flavor
,
created_by
=
owner
,
type
=
'U'
)
return
Instance
.
create
(
lease
=
lease
,
owner
=
owner
,
flavor
=
flavor
,
remote_id
=
remote_id
,
template
=
template
,
params
=
params
)
def
test_create_from_instance
(
self
):
with
patch
(
...
...
@@ -49,24 +60,25 @@ class ImageModelsTest(TestCase):
mock_interface
.
create_image
()
mock_interface
.
return_value
.
create_image
.
return_value
=
RemoteImage
(
"123456789"
,
"987654321"
,
"qcow2"
)
"qcow2"
,
"200000"
)
user
=
self
.
create_user
()
instance
=
self
.
create_instance
()
description
=
"test image description"
image
=
Image
.
create_from_instance
(
user
,
instance
,
description
)
self
.
assertEqual
(
image
.
name
,
"987654321"
)
self
.
assertEqual
(
image
.
remote_id
,
"123456789"
)
self
.
assertEqual
(
image
.
created_by
,
user
)
self
.
assertEqual
(
image
.
created_by
_id
,
user
.
id
)
self
.
assertEqual
(
image
.
uploaded_by_user
,
False
)
self
.
assertEqual
(
image
.
description
,
description
)
self
.
assertIsInstance
(
image
,
Image
)
def
test_create_from_user
(
self
):
with
patch
(
'image.models.OpenstackImageManager'
)
as
mock_interface
:
mock_interface
.
upload_file
()
mock_interface
.
return_value
.
upload_file
.
return_value
=
RemoteImage
(
"123456789"
,
"987654321"
,
"qcow2"
)
"qcow2"
,
"200000"
)
description
=
"test image description"
file_format
=
"qcow2"
image_file
=
Mock
()
...
...
@@ -76,7 +88,6 @@ class ImageModelsTest(TestCase):
image
=
Image
.
create_from_user
(
description
,
file_format
,
image_file
,
name
,
user
)
self
.
assertEqual
(
image
.
name
,
name
)
self
.
assertEqual
(
image
.
remote_id
,
"123456789"
)
self
.
assertEqual
(
image
.
created_by
,
user
)
self
.
assertEqual
(
image
.
created_by
_id
,
user
.
id
)
self
.
assertEqual
(
image
.
uploaded_by_user
,
True
)
self
.
assertEqual
(
image
.
description
,
description
)
self
.
assertIsInstance
(
image
,
Image
)
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