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
e85add2b
authored
Aug 14, 2019
by
Bodor Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test create_from_instance function
parent
3a808815
Pipeline
#826
canceled with stage
in 0 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
0 deletions
+76
-0
recircle/template/tests/test_models.py
+76
-0
No files found.
recircle/template/tests/test_models.py
0 → 100644
View file @
e85add2b
from
django.test
import
TestCase
from
django.contrib.auth.models
import
User
from
unittest.mock
import
patch
from
template.models
import
ImageTemplate
from
image.models
import
Image
from
instance.models
import
Flavor
,
Lease
,
Instance
from
interface_openstack.interface.vm.resources
import
Flavor
as
RemoteFlavor
class
TemplateModelsTest
(
TestCase
):
@staticmethod
def
create_user
(
name
=
"test_user"
,
email
=
"test_email"
,
password
=
"test_password"
):
return
User
.
objects
.
create_user
(
username
=
name
,
email
=
email
,
password
=
password
)
@staticmethod
def
create_flavor
():
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
):
params
=
{
"name"
:
"test_instance"
,
"description"
:
"test instance description"
,
"access_method"
:
"ssh"
,
"system"
:
"test_system"
,
"time_of_suspend"
:
"2019-05-28 23:59"
,
"time_of_delete"
:
"2019-05-28 23:59"
,
}
flavor
=
self
.
create_flavor
()
lease
=
Lease
.
objects
.
create
(
name
=
"test_lease"
,
description
=
"test lease description"
,
suspend_interval_in_sec
=
100
,
delete_interval_in_sec
=
100
)
owner
=
self
.
create_user
(
"test_instance_user"
,
"instance_user"
,
"test_password"
)
remote_id
=
"123456789"
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
(
'template.models.Image'
)
as
mock_image
:
user
=
self
.
create_user
()
image
=
Image
.
objects
.
create
(
name
=
"test_image"
,
description
=
"test image description"
,
uploaded_by_user
=
False
,
remote_id
=
"123456789"
,
created_by
=
user
)
instance
=
self
.
create_instance
()
description
=
"test template description"
name
=
"test_template"
mock_image
.
create_from_instance
()
mock_image
.
create_from_instance
.
return_value
=
image
template
=
ImageTemplate
.
create_from_instance
(
name
,
description
,
instance
,
user
)
self
.
assertEqual
(
template
.
name
,
name
)
self
.
assertEqual
(
template
.
created_by
,
user
)
self
.
assertEqual
(
template
.
type
,
"I"
)
self
.
assertEqual
(
template
.
description
,
description
)
self
.
assertEqual
(
template
.
lease
,
instance
.
lease
)
self
.
assertEqual
(
template
.
flavor
,
instance
.
flavor
)
self
.
assertIsInstance
(
template
,
ImageTemplate
)
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