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
edec537a
authored
Jun 27, 2022
by
Szeberényi Imre
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '3-test-cases' into 'master'
Resolve "Test cases" Closes
#3
See merge request
!6
parents
4b26d356
967abc7b
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
46 additions
and
41 deletions
+46
-41
circle/acl/tests/test_acl.py
+10
-10
circle/common/models.py
+4
-4
circle/common/tests/celery_mock.py
+1
-1
circle/common/tests/test_models.py
+1
-1
circle/common/tests/test_operations.py
+1
-1
circle/dashboard/tests/test_mockedviews.py
+7
-5
circle/dashboard/tests/test_periodic_task.py
+1
-1
circle/dashboard/tests/test_views.py
+1
-1
circle/dashboard/validators.py
+1
-1
circle/dashboard/views/autocomplete.py
+1
-1
circle/dashboard/views/user.py
+1
-1
circle/dashboard/views/util.py
+5
-5
circle/firewall/fields.py
+3
-3
circle/firewall/tests/test_firewall.py
+1
-1
circle/network/tests/test_views.py
+1
-1
circle/request/tests.py
+1
-1
circle/storage/tests/test_models.py
+1
-1
circle/vm/tests/test_models.py
+1
-1
circle/vm/tests/test_operations.py
+1
-1
requirements/base.txt
+3
-0
No files found.
circle/acl/tests/test_acl.py
View file @
edec537a
...
...
@@ -20,7 +20,7 @@ from django.contrib.auth.models import User, Group, AnonymousUser
from
django.db.models
import
TextField
,
ForeignKey
from
..models
import
ObjectLevel
,
AclBase
from
django.db
import
models
class
TestModel
(
AclBase
):
normal_field
=
TextField
()
...
...
@@ -34,7 +34,7 @@ class TestModel(AclBase):
class
Test2Model
(
AclBase
):
normal2_field
=
TextField
()
owner
=
ForeignKey
(
User
,
null
=
True
)
owner
=
ForeignKey
(
User
,
null
=
True
,
on_delete
=
models
.
CASCADE
)
ACL_LEVELS
=
(
(
'one'
,
'One'
),
...
...
@@ -195,9 +195,9 @@ class AclUserTest(TestCase):
i1
.
set_level
(
self
.
u1
,
'alfa'
)
i2
.
set_level
(
self
.
u1
,
'bravo'
)
i2
.
set_level
(
self
.
u2
,
'bravo'
)
self
.
assert
Items
Equal
(
self
.
assert
Count
Equal
(
TestModel
.
get_objects_with_level
(
'alfa'
,
self
.
u1
),
[
i1
,
i2
])
self
.
assert
Items
Equal
(
self
.
assert
Count
Equal
(
TestModel
.
get_objects_with_level
(
'alfa'
,
self
.
u2
),
[
i2
])
def
test_get_objects_with_level_for_superuser
(
self
):
...
...
@@ -206,11 +206,11 @@ class AclUserTest(TestCase):
i1
.
set_level
(
self
.
u1
,
'alfa'
)
i2
.
set_level
(
self
.
us
,
'alfa'
)
self
.
assert
Items
Equal
(
self
.
assert
Count
Equal
(
TestModel
.
get_objects_with_level
(
'alfa'
,
self
.
u1
),
[
i1
])
self
.
assert
Items
Equal
(
self
.
assert
Count
Equal
(
TestModel
.
get_objects_with_level
(
'alfa'
,
self
.
us
),
[
i1
,
i2
])
self
.
assert
Items
Equal
(
self
.
assert
Count
Equal
(
TestModel
.
get_objects_with_level
(
'alfa'
,
self
.
us
,
disregard_superuser
=
True
),
[
i2
])
...
...
@@ -220,7 +220,7 @@ class AclUserTest(TestCase):
i1
.
set_level
(
self
.
g1
,
'alfa'
)
i2
.
set_level
(
self
.
g1
,
'bravo'
)
i2
.
set_level
(
self
.
u1
,
'bravo'
)
self
.
assert
Items
Equal
(
self
.
assert
Count
Equal
(
TestModel
.
get_objects_with_level
(
'alfa'
,
self
.
u1
),
[
i1
,
i2
])
def
test_get_objects_with_group_level
(
self
):
...
...
@@ -229,9 +229,9 @@ class AclUserTest(TestCase):
i1
.
set_level
(
self
.
g1
,
'alfa'
)
i2
.
set_level
(
self
.
g1
,
'bravo'
)
i2
.
set_level
(
self
.
g2
,
'bravo'
)
self
.
assert
Items
Equal
(
self
.
assert
Count
Equal
(
TestModel
.
get_objects_with_group_level
(
'alfa'
,
self
.
g1
),
[
i1
,
i2
])
self
.
assert
Items
Equal
(
self
.
assert
Count
Equal
(
TestModel
.
get_objects_with_group_level
(
'alfa'
,
self
.
g2
),
[
i2
])
def
test_owner
(
self
):
...
...
circle/common/models.py
View file @
edec537a
...
...
@@ -540,13 +540,13 @@ def fetch_human_exception(exception, user=None):
>>> r = humanize_exception("foo", Exception())
>>> fetch_human_exception(r, User())
u
'foo'
'foo'
>>> fetch_human_exception(r).get_text(User())
u
'foo'
'foo'
>>> fetch_human_exception(Exception(), User())
u
'Unknown error'
'Unknown error'
>>> fetch_human_exception(PermissionDenied(), User())
u
'Permission Denied'
'Permission Denied'
"""
if
not
isinstance
(
exception
,
HumanReadableException
):
...
...
circle/common/tests/celery_mock.py
View file @
edec537a
...
...
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from
mock
import
patch
from
unittest.
mock
import
patch
class
MockCeleryMixin
(
object
):
...
...
circle/common/tests/test_models.py
View file @
edec537a
...
...
@@ -18,7 +18,7 @@
from
collections
import
deque
from
django.test
import
TestCase
from
mock
import
MagicMock
from
unittest.
mock
import
MagicMock
from
.celery_mock
import
MockCeleryMixin
from
.models
import
TestClass
...
...
circle/common/tests/test_operations.py
View file @
edec537a
...
...
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from
mock
import
MagicMock
,
patch
from
unittest.
mock
import
MagicMock
,
patch
from
django.test
import
TestCase
...
...
circle/dashboard/tests/test_mockedviews.py
View file @
edec537a
...
...
@@ -19,7 +19,7 @@ import unittest
import
warnings
from
factory
import
Factory
,
Sequence
from
mock
import
patch
,
MagicMock
from
unittest.
mock
import
patch
,
MagicMock
from
django.contrib.auth.models
import
User
,
AnonymousUser
from
django.core.exceptions
import
PermissionDenied
...
...
@@ -501,7 +501,7 @@ class RenewViewTest(unittest.TestCase):
inst
.
_meta
.
object_name
=
"Instance"
inst
.
renew
=
Instance
.
_ops
[
'renew'
](
inst
)
inst
.
renew
.
async
=
MagicMock
()
inst
.
has_level
=
lambda
user
,
level
:
user
.
is_authenticated
()
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
)
...
...
@@ -658,8 +658,10 @@ def FakeRequestFactory(user=None, **kwargs):
class
UserFactory
(
Factory
):
''' using the excellent factory_boy library '''
FACTORY_FOR
=
User
username
=
Sequence
(
lambda
i
:
'test
%
d'
%
i
)
class
Meta
:
model
=
User
username
=
Sequence
(
lambda
i
:
'test{}'
.
format
(
i
))
first_name
=
'John'
last_name
=
'Doe'
email
=
Sequence
(
lambda
i
:
'test
%
d@example.com'
%
i
)
email
=
Sequence
(
lambda
i
:
'test{}@example.com'
.
format
(
i
))
circle/dashboard/tests/test_periodic_task.py
View file @
edec537a
...
...
@@ -16,7 +16,7 @@
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
import
unittest
from
mock
import
patch
,
MagicMock
from
unittest.
mock
import
patch
,
MagicMock
from
django.contrib.auth.models
import
User
...
...
circle/dashboard/tests/test_views.py
View file @
edec537a
...
...
@@ -33,7 +33,7 @@ from circle.vm.operations import (WakeUpOperation, AddInterfaceOperation,
DeployOperation
,
RenameOperation
)
from
..models
import
Profile
from
circle.firewall.models
import
Vlan
,
Host
,
VlanGroup
from
mock
import
Mock
,
patch
from
unittest.
mock
import
Mock
,
patch
from
simplesshkey.models
import
UserKey
import
django.conf
...
...
circle/dashboard/validators.py
View file @
edec537a
...
...
@@ -60,7 +60,7 @@ def connect_command_template_validator(value):
>>> try: connect_command_template_validator("
%(host)
s
%
s")
... except ValidationError as e: print(e)
...
[
u
'Invalid template string.']
['Invalid template string.']
"""
try
:
...
...
circle/dashboard/views/autocomplete.py
View file @
edec537a
...
...
@@ -35,7 +35,7 @@ except NameError:
def
highlight
(
field
,
q
,
none_wo_match
=
True
):
"""
>>> highlight('<b>Akkount Krokodil', 'kro', False)
u
'<b>Akkount <span class="autocomplete-hl">Kro</span>kodil'
'<b>Akkount <span class="autocomplete-hl">Kro</span>kodil'
"""
if
not
field
:
...
...
circle/dashboard/views/user.py
View file @
edec537a
...
...
@@ -251,7 +251,7 @@ class UnsubscribeFormView(SuccessMessageMixin, UpdateView):
success_message
=
_
(
"Successfully modified subscription."
)
def
get_success_url
(
self
):
if
self
.
request
.
user
.
is_authenticated
()
:
if
self
.
request
.
user
.
is_authenticated
:
return
super
(
UnsubscribeFormView
,
self
)
.
get_success_url
()
else
:
return
self
.
request
.
path
...
...
circle/dashboard/views/util.py
View file @
edec537a
...
...
@@ -76,7 +76,7 @@ class RedirectToLoginMixin(AccessMixin):
return
super
(
RedirectToLoginMixin
,
self
)
.
dispatch
(
request
,
*
args
,
**
kwargs
)
except
self
.
redirect_exception_classes
:
if
not
request
.
user
.
is_authenticated
()
:
if
not
request
.
user
.
is_authenticated
:
return
redirect_to_login
(
request
.
get_full_path
(),
self
.
get_login_url
(),
self
.
get_redirect_field_name
())
...
...
@@ -142,16 +142,16 @@ class FilterMixin(object):
>>> f = FilterMixin()
>>> o = list(f._parse_get({'s': "hello"}).items())
>>> sorted(o) # doctest: +ELLIPSIS
[(
u'name', u
'hello'), (...)]
[(
'name',
'hello'), (...)]
>>> o = list(f._parse_get({'s': "name:hello owner:test"}).items())
>>> sorted(o) # doctest: +ELLIPSIS
[(
u'name', u'hello'), (u'owner', u
'test'), (...)]
[(
'name', 'hello'), ('owner',
'test'), (...)]
>>> o = list(f._parse_get({'s': "name:hello ws node:node 3 oh"}).items())
>>> sorted(o) # doctest: +ELLIPSIS
[(
u'name', u'hello ws'), (u'node', u
'node 3 oh'), (...)]
[(
'name', 'hello ws'), ('node',
'node 3 oh'), (...)]
>>> o = list(f._parse_get({'s': "!hello:szia"}).items())
>>> sorted(o) # doctest: +ELLIPSIS
[(
u'!hello', u
'szia'), (...)]
[(
'!hello',
'szia'), (...)]
"""
s
=
GET_dict
.
get
(
"s"
)
fake
=
GET_dict
.
copy
()
...
...
circle/firewall/fields.py
View file @
edec537a
...
...
@@ -286,19 +286,19 @@ def val_ipv6_template(value):
>>> val_ipv6_template("::
%(a)
x:
%(c)
d:
%(d)
d")
Traceback (most recent call last):
...
ValidationError: [u
"template doesn't use parameter b"]
django.core.exceptions.ValidationError: [
"template doesn't use parameter b"]
Detects valid templates building invalid ips:
>>> val_ipv6_template("xxx::
%(a)
d:
%(b)
d:
%(c)
d:
%(d)
d")
Traceback (most recent call last):
...
ValidationError: [u
'template renders invalid IPv6 address']
django.core.exceptions.ValidationError: [
'template renders invalid IPv6 address']
Also IPv4-compatible addresses are invalid:
>>> val_ipv6_template("::
%(a)02
x
%(b)02
x:
%(c)
d:
%(d)
d")
Traceback (most recent call last):
...
ValidationError: [u
'template results in IPv4 address']
django.core.exceptions.ValidationError: [
'template results in IPv4 address']
"""
tpl
=
{
ascii_letters
[
i
]:
255
for
i
in
range
(
4
)}
try
:
...
...
circle/firewall/tests/test_firewall.py
View file @
edec537a
...
...
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from
mock
import
patch
from
unittest.
mock
import
patch
from
netaddr
import
IPSet
,
AddrFormatError
import
django.conf
...
...
circle/network/tests/test_views.py
View file @
edec537a
...
...
@@ -18,7 +18,7 @@
from
django.test
import
TestCase
from
django.test.client
import
Client
from
django.contrib.auth.models
import
User
,
Group
from
mock
import
Mock
from
unittest.
mock
import
Mock
from
common.tests.celery_mock
import
MockCeleryMixin
from
dashboard.tests.test_views
import
LoginMixin
...
...
circle/request/tests.py
View file @
edec537a
...
...
@@ -19,7 +19,7 @@ from django.test import TestCase
from
django.test.client
import
Client
from
django.contrib.auth.models
import
User
,
Permission
from
mock
import
Mock
,
patch
from
unittest.
mock
import
Mock
,
patch
from
common.tests.celery_mock
import
MockCeleryMixin
...
...
circle/storage/tests/test_models.py
View file @
edec537a
...
...
@@ -19,7 +19,7 @@ from datetime import timedelta
from
django.test
import
TestCase
from
django.utils
import
timezone
from
mock
import
MagicMock
from
unittest.
mock
import
MagicMock
from
..models
import
Disk
,
DataStore
...
...
circle/vm/tests/test_models.py
View file @
edec537a
...
...
@@ -16,7 +16,7 @@
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from
datetime
import
datetime
from
mock
import
Mock
,
MagicMock
,
patch
,
call
from
unittest.
mock
import
Mock
,
MagicMock
,
patch
,
call
import
types
from
celery.contrib.abortable
import
AbortableAsyncResult
...
...
circle/vm/tests/test_operations.py
View file @
edec537a
...
...
@@ -16,7 +16,7 @@
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from
django.test
import
TestCase
from
mock
import
MagicMock
from
unittest.
mock
import
MagicMock
from
common.operations
import
operation_registry_name
as
op_reg_name
from
vm.models
import
Instance
,
InstanceActivity
,
Node
...
...
requirements/base.txt
View file @
edec537a
...
...
@@ -51,3 +51,6 @@ lxml==4.7.1
python-memcached==1.59
enum34==1.1.10
ipaddress==1.0.23
django-nose==1.4.7
nose-exclude==0.5.0
factory_boy==3.2.1
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