Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
5
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
7739d371
authored
Aug 16, 2022
by
Szeberényi Imre
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'testcases' into 'master'
Testcases-Janos See merge request
!11
parents
7dc0aee0
40e7df8a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
70 additions
and
72 deletions
+70
-72
circle/common/backends.py
+1
-3
circle/common/operations.py
+1
-1
circle/common/tests/test_operations.py
+1
-1
circle/common/views.py
+4
-4
circle/dashboard/fixtures/test-vm-fixture.json
+0
-8
circle/dashboard/forms.py
+5
-5
circle/dashboard/tests/test_mockedviews.py
+26
-21
circle/dashboard/tests/test_views.py
+29
-25
circle/firewall/models.py
+1
-1
circle/vm/operations.py
+1
-1
circle/vm/tests/test_models.py
+1
-2
No files found.
circle/common/backends.py
View file @
7739d371
...
...
@@ -18,7 +18,7 @@
import
re
import
logging
import
sha
import
hashlib
from
django.conf
import
settings
from
djangosaml2.backends
import
Saml2Backend
as
Saml2BackendBase
...
...
@@ -43,8 +43,6 @@ class Saml2Backend(Saml2BackendBase):
match
=
match
.
group
()
return
'+
%04
x'
%
ord
(
match
)
if
isinstance
(
main_attribute
,
str
):
main_attribute
=
main_attribute
.
decode
(
'UTF-8'
)
assert
isinstance
(
main_attribute
,
str
)
attr
=
re
.
sub
(
r'[^\w.@-]'
,
replace
,
main_attribute
)
max_length
=
settings
.
SAML_MAIN_ATTRIBUTE_MAX_LENGTH
...
...
circle/common/operations.py
View file @
7739d371
...
...
@@ -202,7 +202,7 @@ class Operation(object):
return
self
.
activity_name
except
AttributeError
:
try
:
return
self
.
name
.
_proxy____args
[
0
]
# ewww!
return
self
.
name
# ewww!
except
AttributeError
:
raise
ImproperlyConfigured
(
"Set Operation.activity_name to an ugettext_nooped "
...
...
circle/common/tests/test_operations.py
View file @
7739d371
...
...
@@ -34,7 +34,7 @@ class OperationTestCase(TestCase):
with
patch
.
object
(
Operation
,
'check_precond'
):
with
patch
.
object
(
Operation
,
'create_activity'
)
as
create_act
:
try
:
op
.
async
(
system
=
True
)
op
.
_
async
(
system
=
True
)
except
AbortEx
:
self
.
assertTrue
(
create_act
.
called
)
...
...
circle/common/views.py
View file @
7739d371
...
...
@@ -45,10 +45,10 @@ def handler500(request):
logger
.
exception
(
"unhandled exception"
)
ctx
=
get_context
(
request
,
exception
)
try
:
resp
=
render
(
"500.html"
,
ctx
,
resp
=
render
(
request
,
"500.html"
,
ctx
,
RequestContext
(
request
)
.
flatten
())
except
:
resp
=
render
(
"500.html"
,
ctx
)
resp
=
render
(
request
,
"500.html"
,
ctx
)
resp
.
status_code
=
500
return
resp
...
...
@@ -56,6 +56,6 @@ def handler500(request):
def
handler403
(
request
,
*
args
,
**
argv
):
cls
,
exception
,
traceback
=
exc_info
()
ctx
=
get_context
(
request
,
exception
)
resp
=
render
(
"403.html"
,
ctx
)
resp
=
render
(
request
,
"403.html"
,
ctx
)
resp
.
status_code
=
403
return
resp
(
request
)
return
resp
circle/dashboard/fixtures/test-vm-fixture.json
View file @
7739d371
[
{
"pk"
:
1
,
"model"
:
"sites.site"
,
"fields"
:
{
"domain"
:
"example.com"
,
"name"
:
"example.com"
}
},
{
"pk"
:
1
,
"model"
:
"vm.lease"
,
"fields"
:
{
"suspend_interval_seconds"
:
18000
,
...
...
circle/dashboard/forms.py
View file @
7739d371
...
...
@@ -46,8 +46,8 @@ from django.forms.widgets import TextInput, HiddenInput
from
django.template.loader
import
render_to_string
from
django.utils.html
import
escape
,
format_html
from
django.utils.safestring
import
mark_safe
from
django.utils.t
ranslation
import
ugettex
t_lazy
from
django.utils.translation
import
u
gettext_lazy
as
_
from
django.utils.t
ext
import
forma
t_lazy
from
django.utils.translation
import
gettext_lazy
as
_
from
simplesshkey.models
import
UserKey
from
sizefield.widgets
import
FileSizeWidget
...
...
@@ -62,7 +62,7 @@ from vm.models import (
from
.models
import
Profile
,
GroupProfile
,
Message
from
.validators
import
domain_validator
,
meta_data_validator
,
user_data_validator
LANGUAGES_WITH_CODE
=
((
l
[
0
],
ugettext_lazy
(
l
[
1
],
" ("
,
l
[
0
],
")"
))
LANGUAGES_WITH_CODE
=
((
l
[
0
],
format_lazy
(
"{} ({})"
,
l
[
1
],
l
[
0
]
))
for
l
in
LANGUAGES
)
priority_choices
=
(
...
...
@@ -1103,7 +1103,7 @@ class VmPortRemoveForm(OperationForm):
class
VmPortAddForm
(
OperationForm
):
port
=
forms
.
IntegerField
(
required
=
True
,
label
=
_
(
'Port'
),
min_value
=
1
,
max_value
=
65535
)
proto
=
forms
.
ChoiceField
(
initial
=
((
'tcp'
,
'tcp'
),
(
'udp'
,
'udp'
)),
proto
=
forms
.
ChoiceField
(
choices
=
((
'tcp'
,
'tcp'
),
(
'udp'
,
'udp'
)),
required
=
True
,
label
=
_
(
'Protocol'
))
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -1303,7 +1303,7 @@ class TraitForm(forms.ModelForm):
class
MyProfileForm
(
forms
.
ModelForm
):
preferred_language
=
forms
.
ChoiceField
(
initial
=
LANGUAGES_WITH_CODE
,
choices
=
LANGUAGES_WITH_CODE
,
label
=
_
(
"Preferred language"
),
)
...
...
circle/dashboard/tests/test_mockedviews.py
View file @
7739d371
...
...
@@ -28,6 +28,7 @@ from django.http import HttpRequest, Http404, QueryDict
from
django.utils
import
baseconv
from
..models
import
Profile
from
vm.models
import
Node
from
..views
import
InstanceActivityDetail
,
InstanceActivity
from
..views
import
vm_ops
,
vm_mass_ops
,
Instance
,
UnsubscribeFormView
from
..views
import
AclUpdateView
...
...
@@ -35,11 +36,13 @@ from .. import views
class
QuerySet
(
list
):
model
=
MagicMock
()
model
=
Node
def
get
(
self
,
*
args
,
**
kwargs
):
return
self
.
pop
()
def
all
(
self
):
return
self
class
ViewUserTestCase
(
unittest
.
TestCase
):
...
...
@@ -165,14 +168,14 @@ class VmOperationViewTestCase(unittest.TestCase):
inst
=
MagicMock
(
spec
=
Instance
)
inst
.
_meta
.
object_name
=
"Instance"
inst
.
migrate
=
Instance
.
_ops
[
'migrate'
](
inst
)
inst
.
migrate
.
async
=
MagicMock
()
inst
.
migrate
.
_
async
=
MagicMock
()
inst
.
has_level
.
return_value
=
True
form_kwargs
.
return_value
=
{
'default'
:
100
,
'choices'
:
QuerySet
([
node
])}
go
.
return_value
=
inst
assert
view
.
as_view
()(
request
,
pk
=
1234
)[
'location'
]
assert
not
msg
.
error
.
called
inst
.
migrate
.
async
.
assert_called_once_with
(
inst
.
migrate
.
_
async
.
assert_called_once_with
(
to_node
=
node
,
live_migration
=
True
,
user
=
request
.
user
)
def
test_migrate_failed
(
self
):
...
...
@@ -186,14 +189,14 @@ class VmOperationViewTestCase(unittest.TestCase):
inst
=
MagicMock
(
spec
=
Instance
)
inst
.
_meta
.
object_name
=
"Instance"
inst
.
migrate
=
Instance
.
_ops
[
'migrate'
](
inst
)
inst
.
migrate
.
async
=
MagicMock
()
inst
.
migrate
.
async
.
side_effect
=
Exception
inst
.
migrate
.
_
async
=
MagicMock
()
inst
.
migrate
.
_
async
.
side_effect
=
Exception
inst
.
has_level
.
return_value
=
True
form_kwargs
.
return_value
=
{
'default'
:
100
,
'choices'
:
QuerySet
([
node
])}
go
.
return_value
=
inst
assert
view
.
as_view
()(
request
,
pk
=
1234
)[
'location'
]
assert
inst
.
migrate
.
async
.
called
assert
inst
.
migrate
.
_
async
.
called
assert
msg
.
error
.
called
def
test_migrate_wo_permission
(
self
):
...
...
@@ -206,14 +209,14 @@ class VmOperationViewTestCase(unittest.TestCase):
inst
=
MagicMock
(
spec
=
Instance
)
inst
.
_meta
.
object_name
=
"Instance"
inst
.
migrate
=
Instance
.
_ops
[
'migrate'
](
inst
)
inst
.
migrate
.
async
=
MagicMock
()
inst
.
migrate
.
_
async
=
MagicMock
()
inst
.
has_level
.
return_value
=
True
form_kwargs
.
return_value
=
{
'default'
:
100
,
'choices'
:
QuerySet
([
node
])}
go
.
return_value
=
inst
with
self
.
assertRaises
(
PermissionDenied
):
assert
view
.
as_view
()(
request
,
pk
=
1234
)[
'location'
]
assert
not
inst
.
migrate
.
async
.
called
assert
not
inst
.
migrate
.
_
async
.
called
def
test_migrate_template
(
self
):
"""check if GET dialog's template can be rendered"""
...
...
@@ -239,7 +242,7 @@ class VmOperationViewTestCase(unittest.TestCase):
inst
.
name
=
"asd"
inst
.
_meta
.
object_name
=
"Instance"
inst
.
save_as_template
=
Instance
.
_ops
[
'save_as_template'
](
inst
)
inst
.
save_as_template
.
async
=
MagicMock
()
inst
.
save_as_template
.
_
async
=
MagicMock
()
inst
.
has_level
.
return_value
=
True
go
.
return_value
=
inst
assert
view
.
as_view
()(
request
,
pk
=
1234
)
...
...
@@ -256,7 +259,7 @@ class VmOperationViewTestCase(unittest.TestCase):
inst
.
name
=
"asd"
inst
.
_meta
.
object_name
=
"Instance"
inst
.
save_as_template
=
Instance
.
_ops
[
'save_as_template'
](
inst
)
inst
.
save_as_template
.
async
=
MagicMock
()
inst
.
save_as_template
.
_
async
=
MagicMock
()
inst
.
has_level
.
return_value
=
True
go
.
return_value
=
inst
assert
view
.
as_view
()(
request
,
pk
=
1234
)[
'location'
]
...
...
@@ -329,7 +332,7 @@ class VmMassOperationViewTestCase(unittest.TestCase):
inst
=
MagicMock
(
spec
=
Instance
)
inst
.
_meta
.
object_name
=
"Instance"
inst
.
migrate
=
Instance
.
_ops
[
'migrate'
](
inst
)
inst
.
migrate
.
async
=
MagicMock
()
inst
.
migrate
.
_
async
=
MagicMock
()
inst
.
has_level
.
return_value
=
True
go
.
return_value
=
[
inst
]
assert
view
.
as_view
()(
request
,
pk
=
1234
)[
'location'
]
...
...
@@ -408,13 +411,13 @@ class RenewViewTest(unittest.TestCase):
inst
.
_meta
.
object_name
=
"Instance"
inst
.
lease
=
MagicMock
(
pk
=
99
)
inst
.
renew
=
Instance
.
_ops
[
'renew'
](
inst
)
inst
.
renew
.
async
=
MagicMock
()
inst
.
renew
.
_
async
=
MagicMock
()
inst
.
has_level
.
return_value
=
True
go
.
return_value
=
inst
assert
view
.
as_view
()(
request
,
pk
=
1234
)
assert
not
msg
.
error
.
called
assert
inst
.
renew
.
async
.
called_with
(
user
=
request
.
user
,
lease
=
None
)
assert
inst
.
renew
.
async
.
return_value
.
get
.
called
assert
inst
.
renew
.
_
async
.
called_with
(
user
=
request
.
user
,
lease
=
None
)
assert
inst
.
renew
.
_
async
.
return_value
.
get
.
called
# success would redirect
def
test_renew_by_owner_w_param
(
self
):
...
...
@@ -427,7 +430,7 @@ class RenewViewTest(unittest.TestCase):
inst
.
_meta
.
object_name
=
"Instance"
inst
.
lease
=
MagicMock
(
pk
=
99
)
inst
.
renew
=
Instance
.
_ops
[
'renew'
](
inst
)
inst
.
renew
.
async
=
MagicMock
()
inst
.
renew
.
_
async
=
MagicMock
()
inst
.
has_level
.
return_value
=
True
go
.
return_value
=
inst
assert
view
.
as_view
()(
request
,
pk
=
1234
)
...
...
@@ -441,7 +444,7 @@ class RenewViewTest(unittest.TestCase):
inst
=
MagicMock
(
spec
=
Instance
)
inst
.
_meta
.
object_name
=
"Instance"
inst
.
renew
=
Instance
.
_ops
[
'renew'
](
inst
)
inst
.
renew
.
async
=
MagicMock
()
inst
.
renew
.
_
async
=
MagicMock
()
inst
.
has_level
.
return_value
=
False
go
.
return_value
=
inst
self
.
assertIn
(
'login'
,
...
...
@@ -455,7 +458,7 @@ class RenewViewTest(unittest.TestCase):
inst
=
MagicMock
(
spec
=
Instance
)
inst
.
_meta
.
object_name
=
"Instance"
inst
.
renew
=
Instance
.
_ops
[
'renew'
](
inst
)
inst
.
renew
.
async
=
MagicMock
()
inst
.
renew
.
_
async
=
MagicMock
()
inst
.
has_level
.
return_value
=
False
go
.
return_value
=
inst
with
self
.
assertRaises
(
PermissionDenied
):
...
...
@@ -470,7 +473,7 @@ class RenewViewTest(unittest.TestCase):
inst
.
_meta
.
object_name
=
"Instance"
inst
.
lease
=
MagicMock
(
pk
=
99
)
inst
.
renew
=
Instance
.
_ops
[
'renew'
](
inst
)
inst
.
renew
.
async
=
MagicMock
()
inst
.
renew
.
_
async
=
MagicMock
()
inst
.
has_level
.
return_value
=
False
go
.
return_value
=
inst
with
self
.
assertRaises
(
PermissionDenied
):
...
...
@@ -481,8 +484,9 @@ class RenewViewTest(unittest.TestCase):
view
=
vm_ops
[
'renew'
]
inst
=
MagicMock
(
spec
=
Instance
,
pk
=
11
)
inst
.
_meta
.
object_name
=
"Instance"
inst
.
lease
=
MagicMock
(
pk
=
99
)
inst
.
renew
=
Instance
.
_ops
[
'renew'
](
inst
)
inst
.
renew
.
async
=
MagicMock
()
inst
.
renew
.
_
async
=
MagicMock
()
key
=
view
.
get_token_url
(
inst
,
user
)
.
split
(
'?'
)[
1
]
.
split
(
'='
)[
1
]
request
=
FakeRequestFactory
(
GET
=
{
'k'
:
key
})
# other user!
...
...
@@ -499,8 +503,9 @@ class RenewViewTest(unittest.TestCase):
view
=
vm_ops
[
'renew'
]
inst
=
MagicMock
(
spec
=
Instance
,
pk
=
11
)
inst
.
_meta
.
object_name
=
"Instance"
inst
.
lease
=
MagicMock
(
pk
=
99
)
inst
.
renew
=
Instance
.
_ops
[
'renew'
](
inst
)
inst
.
renew
.
async
=
MagicMock
()
inst
.
renew
.
_
async
=
MagicMock
()
inst
.
has_level
=
lambda
user
,
level
:
user
.
is_authenticated
key
=
view
.
get_token_url
(
inst
,
user
)
.
split
(
'?'
)[
1
]
.
split
(
'='
)[
1
]
request
=
FakeRequestFactory
(
GET
=
{
'k'
:
key
},
authenticated
=
False
)
...
...
@@ -536,7 +541,7 @@ class RenewViewTest(unittest.TestCase):
inst
=
MagicMock
(
spec
=
Instance
,
pk
=
11
)
inst
.
_meta
.
object_name
=
"Instance"
inst
.
renew
=
Instance
.
_ops
[
'renew'
](
inst
)
inst
.
renew
.
async
=
MagicMock
()
inst
.
renew
.
_
async
=
MagicMock
()
inst
.
has_level
.
return_value
=
False
key
=
view
.
get_token_url
(
inst
,
user
)
.
split
(
'?'
)[
1
]
.
split
(
'='
)[
1
]
with
patch
(
'dashboard.views.signing.loads'
)
as
loader
,
\
...
...
circle/dashboard/tests/test_views.py
View file @
7739d371
This diff is collapsed.
Click to expand it.
circle/firewall/models.py
View file @
7739d371
...
...
@@ -485,7 +485,7 @@ class Vlan(AclBase, models.Model):
mask
=
int
(
IPAddress
(
tpl
%
{
"a"
:
1
,
"b"
:
1
,
"c"
:
1
,
"d"
:
1
}))
prefixlen
=
128
while
mask
%
2
==
0
:
mask
/=
2
mask
/
/
=
2
prefixlen
-=
1
return
(
tpl
,
prefixlen
)
...
...
circle/vm/operations.py
View file @
7739d371
...
...
@@ -35,7 +35,7 @@ from django.core.exceptions import PermissionDenied, SuspiciousOperation
from
django.urls
import
reverse
from
django.db.models
import
Q
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext
_lazy
as
_
,
ugettext_noop
from
django.utils.translation
import
ugettext
as
_
,
ugettext_noop
from
re
import
search
from
sizefield.utils
import
filesizeformat
...
...
circle/vm/tests/test_models.py
View file @
7739d371
...
...
@@ -241,8 +241,7 @@ class InstanceActivityTestCase(TestCase):
original_create
=
InstanceActivity
.
create
mocked_create
=
types
.
MethodType
(
original_create
.
__func__
,
mock_instance_activity_cls
,
original_create
.
__self__
.
__class__
)
mock_instance_activity_cls
)
try
:
mocked_create
(
'test'
,
instance
,
readable_name
=
"test"
,
concurrency_check
=
False
)
...
...
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