Commit edec537a by Szeberényi Imre

Merge branch '3-test-cases' into 'master'

Resolve "Test cases"

Closes #3

See merge request !6
parents 4b26d356 967abc7b
...@@ -20,7 +20,7 @@ from django.contrib.auth.models import User, Group, AnonymousUser ...@@ -20,7 +20,7 @@ from django.contrib.auth.models import User, Group, AnonymousUser
from django.db.models import TextField, ForeignKey from django.db.models import TextField, ForeignKey
from ..models import ObjectLevel, AclBase from ..models import ObjectLevel, AclBase
from django.db import models
class TestModel(AclBase): class TestModel(AclBase):
normal_field = TextField() normal_field = TextField()
...@@ -34,7 +34,7 @@ class TestModel(AclBase): ...@@ -34,7 +34,7 @@ class TestModel(AclBase):
class Test2Model(AclBase): class Test2Model(AclBase):
normal2_field = TextField() normal2_field = TextField()
owner = ForeignKey(User, null=True) owner = ForeignKey(User, null=True, on_delete=models.CASCADE)
ACL_LEVELS = ( ACL_LEVELS = (
('one', 'One'), ('one', 'One'),
...@@ -195,9 +195,9 @@ class AclUserTest(TestCase): ...@@ -195,9 +195,9 @@ class AclUserTest(TestCase):
i1.set_level(self.u1, 'alfa') i1.set_level(self.u1, 'alfa')
i2.set_level(self.u1, 'bravo') i2.set_level(self.u1, 'bravo')
i2.set_level(self.u2, 'bravo') i2.set_level(self.u2, 'bravo')
self.assertItemsEqual( self.assertCountEqual(
TestModel.get_objects_with_level('alfa', self.u1), [i1, i2]) TestModel.get_objects_with_level('alfa', self.u1), [i1, i2])
self.assertItemsEqual( self.assertCountEqual(
TestModel.get_objects_with_level('alfa', self.u2), [i2]) TestModel.get_objects_with_level('alfa', self.u2), [i2])
def test_get_objects_with_level_for_superuser(self): def test_get_objects_with_level_for_superuser(self):
...@@ -206,11 +206,11 @@ class AclUserTest(TestCase): ...@@ -206,11 +206,11 @@ class AclUserTest(TestCase):
i1.set_level(self.u1, 'alfa') i1.set_level(self.u1, 'alfa')
i2.set_level(self.us, 'alfa') i2.set_level(self.us, 'alfa')
self.assertItemsEqual( self.assertCountEqual(
TestModel.get_objects_with_level('alfa', self.u1), [i1]) TestModel.get_objects_with_level('alfa', self.u1), [i1])
self.assertItemsEqual( self.assertCountEqual(
TestModel.get_objects_with_level('alfa', self.us), [i1, i2]) TestModel.get_objects_with_level('alfa', self.us), [i1, i2])
self.assertItemsEqual( self.assertCountEqual(
TestModel.get_objects_with_level('alfa', self.us, TestModel.get_objects_with_level('alfa', self.us,
disregard_superuser=True), [i2]) disregard_superuser=True), [i2])
...@@ -220,7 +220,7 @@ class AclUserTest(TestCase): ...@@ -220,7 +220,7 @@ class AclUserTest(TestCase):
i1.set_level(self.g1, 'alfa') i1.set_level(self.g1, 'alfa')
i2.set_level(self.g1, 'bravo') i2.set_level(self.g1, 'bravo')
i2.set_level(self.u1, 'bravo') i2.set_level(self.u1, 'bravo')
self.assertItemsEqual( self.assertCountEqual(
TestModel.get_objects_with_level('alfa', self.u1), [i1, i2]) TestModel.get_objects_with_level('alfa', self.u1), [i1, i2])
def test_get_objects_with_group_level(self): def test_get_objects_with_group_level(self):
...@@ -229,9 +229,9 @@ class AclUserTest(TestCase): ...@@ -229,9 +229,9 @@ class AclUserTest(TestCase):
i1.set_level(self.g1, 'alfa') i1.set_level(self.g1, 'alfa')
i2.set_level(self.g1, 'bravo') i2.set_level(self.g1, 'bravo')
i2.set_level(self.g2, 'bravo') i2.set_level(self.g2, 'bravo')
self.assertItemsEqual( self.assertCountEqual(
TestModel.get_objects_with_group_level('alfa', self.g1), [i1, i2]) TestModel.get_objects_with_group_level('alfa', self.g1), [i1, i2])
self.assertItemsEqual( self.assertCountEqual(
TestModel.get_objects_with_group_level('alfa', self.g2), [i2]) TestModel.get_objects_with_group_level('alfa', self.g2), [i2])
def test_owner(self): def test_owner(self):
......
...@@ -540,13 +540,13 @@ def fetch_human_exception(exception, user=None): ...@@ -540,13 +540,13 @@ def fetch_human_exception(exception, user=None):
>>> r = humanize_exception("foo", Exception()) >>> r = humanize_exception("foo", Exception())
>>> fetch_human_exception(r, User()) >>> fetch_human_exception(r, User())
u'foo' 'foo'
>>> fetch_human_exception(r).get_text(User()) >>> fetch_human_exception(r).get_text(User())
u'foo' 'foo'
>>> fetch_human_exception(Exception(), User()) >>> fetch_human_exception(Exception(), User())
u'Unknown error' 'Unknown error'
>>> fetch_human_exception(PermissionDenied(), User()) >>> fetch_human_exception(PermissionDenied(), User())
u'Permission Denied' 'Permission Denied'
""" """
if not isinstance(exception, HumanReadableException): if not isinstance(exception, HumanReadableException):
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License along # You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>. # with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from mock import patch from unittest.mock import patch
class MockCeleryMixin(object): class MockCeleryMixin(object):
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
from collections import deque from collections import deque
from django.test import TestCase from django.test import TestCase
from mock import MagicMock from unittest.mock import MagicMock
from .celery_mock import MockCeleryMixin from .celery_mock import MockCeleryMixin
from .models import TestClass from .models import TestClass
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License along # You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>. # 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 from django.test import TestCase
......
...@@ -19,7 +19,7 @@ import unittest ...@@ -19,7 +19,7 @@ import unittest
import warnings import warnings
from factory import Factory, Sequence 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.contrib.auth.models import User, AnonymousUser
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
...@@ -501,7 +501,7 @@ class RenewViewTest(unittest.TestCase): ...@@ -501,7 +501,7 @@ class RenewViewTest(unittest.TestCase):
inst._meta.object_name = "Instance" inst._meta.object_name = "Instance"
inst.renew = Instance._ops['renew'](inst) inst.renew = Instance._ops['renew'](inst)
inst.renew.async = MagicMock() 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] key = view.get_token_url(inst, user).split('?')[1].split('=')[1]
request = FakeRequestFactory(GET={'k': key}, authenticated=False) request = FakeRequestFactory(GET={'k': key}, authenticated=False)
...@@ -658,8 +658,10 @@ def FakeRequestFactory(user=None, **kwargs): ...@@ -658,8 +658,10 @@ def FakeRequestFactory(user=None, **kwargs):
class UserFactory(Factory): class UserFactory(Factory):
''' using the excellent factory_boy library ''' ''' using the excellent factory_boy library '''
FACTORY_FOR = User class Meta:
username = Sequence(lambda i: 'test%d' % i) model = User
username = Sequence(lambda i: 'test{}'.format(i))
first_name = 'John' first_name = 'John'
last_name = 'Doe' last_name = 'Doe'
email = Sequence(lambda i: 'test%d@example.com' % i) email = Sequence(lambda i: 'test{}@example.com'.format(i))
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>. # with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
import unittest import unittest
from mock import patch, MagicMock from unittest.mock import patch, MagicMock
from django.contrib.auth.models import User from django.contrib.auth.models import User
......
...@@ -33,7 +33,7 @@ from circle.vm.operations import (WakeUpOperation, AddInterfaceOperation, ...@@ -33,7 +33,7 @@ from circle.vm.operations import (WakeUpOperation, AddInterfaceOperation,
DeployOperation, RenameOperation) DeployOperation, RenameOperation)
from ..models import Profile from ..models import Profile
from circle.firewall.models import Vlan, Host, VlanGroup from circle.firewall.models import Vlan, Host, VlanGroup
from mock import Mock, patch from unittest.mock import Mock, patch
from simplesshkey.models import UserKey from simplesshkey.models import UserKey
import django.conf import django.conf
......
...@@ -60,7 +60,7 @@ def connect_command_template_validator(value): ...@@ -60,7 +60,7 @@ def connect_command_template_validator(value):
>>> try: connect_command_template_validator("%(host)s %s") >>> try: connect_command_template_validator("%(host)s %s")
... except ValidationError as e: print(e) ... except ValidationError as e: print(e)
... ...
[u'Invalid template string.'] ['Invalid template string.']
""" """
try: try:
......
...@@ -35,7 +35,7 @@ except NameError: ...@@ -35,7 +35,7 @@ except NameError:
def highlight(field, q, none_wo_match=True): def highlight(field, q, none_wo_match=True):
""" """
>>> highlight('<b>Akkount Krokodil', 'kro', False) >>> highlight('<b>Akkount Krokodil', 'kro', False)
u'&lt;b&gt;Akkount <span class="autocomplete-hl">Kro</span>kodil' '&lt;b&gt;Akkount <span class="autocomplete-hl">Kro</span>kodil'
""" """
if not field: if not field:
......
...@@ -251,7 +251,7 @@ class UnsubscribeFormView(SuccessMessageMixin, UpdateView): ...@@ -251,7 +251,7 @@ class UnsubscribeFormView(SuccessMessageMixin, UpdateView):
success_message = _("Successfully modified subscription.") success_message = _("Successfully modified subscription.")
def get_success_url(self): def get_success_url(self):
if self.request.user.is_authenticated(): if self.request.user.is_authenticated:
return super(UnsubscribeFormView, self).get_success_url() return super(UnsubscribeFormView, self).get_success_url()
else: else:
return self.request.path return self.request.path
......
...@@ -76,7 +76,7 @@ class RedirectToLoginMixin(AccessMixin): ...@@ -76,7 +76,7 @@ class RedirectToLoginMixin(AccessMixin):
return super(RedirectToLoginMixin, self).dispatch( return super(RedirectToLoginMixin, self).dispatch(
request, *args, **kwargs) request, *args, **kwargs)
except self.redirect_exception_classes: 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(), return redirect_to_login(request.get_full_path(),
self.get_login_url(), self.get_login_url(),
self.get_redirect_field_name()) self.get_redirect_field_name())
...@@ -142,16 +142,16 @@ class FilterMixin(object): ...@@ -142,16 +142,16 @@ class FilterMixin(object):
>>> f = FilterMixin() >>> f = FilterMixin()
>>> o = list(f._parse_get({'s': "hello"}).items()) >>> o = list(f._parse_get({'s': "hello"}).items())
>>> sorted(o) # doctest: +ELLIPSIS >>> sorted(o) # doctest: +ELLIPSIS
[(u'name', u'hello'), (...)] [('name', 'hello'), (...)]
>>> o = list(f._parse_get({'s': "name:hello owner:test"}).items()) >>> o = list(f._parse_get({'s': "name:hello owner:test"}).items())
>>> sorted(o) # doctest: +ELLIPSIS >>> 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()) >>> o = list(f._parse_get({'s': "name:hello ws node:node 3 oh"}).items())
>>> sorted(o) # doctest: +ELLIPSIS >>> 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()) >>> o = list(f._parse_get({'s': "!hello:szia"}).items())
>>> sorted(o) # doctest: +ELLIPSIS >>> sorted(o) # doctest: +ELLIPSIS
[(u'!hello', u'szia'), (...)] [('!hello', 'szia'), (...)]
""" """
s = GET_dict.get("s") s = GET_dict.get("s")
fake = GET_dict.copy() fake = GET_dict.copy()
......
...@@ -286,19 +286,19 @@ def val_ipv6_template(value): ...@@ -286,19 +286,19 @@ def val_ipv6_template(value):
>>> val_ipv6_template("::%(a)x:%(c)d:%(d)d") >>> val_ipv6_template("::%(a)x:%(c)d:%(d)d")
Traceback (most recent call last): 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: Detects valid templates building invalid ips:
>>> val_ipv6_template("xxx::%(a)d:%(b)d:%(c)d:%(d)d") >>> val_ipv6_template("xxx::%(a)d:%(b)d:%(c)d:%(d)d")
Traceback (most recent call last): 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: Also IPv4-compatible addresses are invalid:
>>> val_ipv6_template("::%(a)02x%(b)02x:%(c)d:%(d)d") >>> val_ipv6_template("::%(a)02x%(b)02x:%(c)d:%(d)d")
Traceback (most recent call last): 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)} tpl = {ascii_letters[i]: 255 for i in range(4)}
try: try:
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License along # You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>. # with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from mock import patch from unittest.mock import patch
from netaddr import IPSet, AddrFormatError from netaddr import IPSet, AddrFormatError
import django.conf import django.conf
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
from django.test import TestCase from django.test import TestCase
from django.test.client import Client from django.test.client import Client
from django.contrib.auth.models import User, Group 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 common.tests.celery_mock import MockCeleryMixin
from dashboard.tests.test_views import LoginMixin from dashboard.tests.test_views import LoginMixin
......
...@@ -19,7 +19,7 @@ from django.test import TestCase ...@@ -19,7 +19,7 @@ from django.test import TestCase
from django.test.client import Client from django.test.client import Client
from django.contrib.auth.models import User, Permission 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 from common.tests.celery_mock import MockCeleryMixin
......
...@@ -19,7 +19,7 @@ from datetime import timedelta ...@@ -19,7 +19,7 @@ from datetime import timedelta
from django.test import TestCase from django.test import TestCase
from django.utils import timezone from django.utils import timezone
from mock import MagicMock from unittest.mock import MagicMock
from ..models import Disk, DataStore from ..models import Disk, DataStore
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>. # with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime from datetime import datetime
from mock import Mock, MagicMock, patch, call from unittest.mock import Mock, MagicMock, patch, call
import types import types
from celery.contrib.abortable import AbortableAsyncResult from celery.contrib.abortable import AbortableAsyncResult
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>. # with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from django.test import TestCase 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 common.operations import operation_registry_name as op_reg_name
from vm.models import Instance, InstanceActivity, Node from vm.models import Instance, InstanceActivity, Node
......
...@@ -51,3 +51,6 @@ lxml==4.7.1 ...@@ -51,3 +51,6 @@ lxml==4.7.1
python-memcached==1.59 python-memcached==1.59
enum34==1.1.10 enum34==1.1.10
ipaddress==1.0.23 ipaddress==1.0.23
django-nose==1.4.7
nose-exclude==0.5.0
factory_boy==3.2.1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment