Commit 7739d371 by Szeberényi Imre

Merge branch 'testcases' into 'master'

Testcases-Janos

See merge request !11
parents 7dc0aee0 40e7df8a
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
import re import re
import logging import logging
import sha import hashlib
from django.conf import settings from django.conf import settings
from djangosaml2.backends import Saml2Backend as Saml2BackendBase from djangosaml2.backends import Saml2Backend as Saml2BackendBase
...@@ -43,8 +43,6 @@ class Saml2Backend(Saml2BackendBase): ...@@ -43,8 +43,6 @@ class Saml2Backend(Saml2BackendBase):
match = match.group() match = match.group()
return '+%04x' % ord(match) return '+%04x' % ord(match)
if isinstance(main_attribute, str):
main_attribute = main_attribute.decode('UTF-8')
assert isinstance(main_attribute, str) assert isinstance(main_attribute, str)
attr = re.sub(r'[^\w.@-]', replace, main_attribute) attr = re.sub(r'[^\w.@-]', replace, main_attribute)
max_length = settings.SAML_MAIN_ATTRIBUTE_MAX_LENGTH max_length = settings.SAML_MAIN_ATTRIBUTE_MAX_LENGTH
......
...@@ -202,7 +202,7 @@ class Operation(object): ...@@ -202,7 +202,7 @@ class Operation(object):
return self.activity_name return self.activity_name
except AttributeError: except AttributeError:
try: try:
return self.name._proxy____args[0] # ewww! return self.name # ewww!
except AttributeError: except AttributeError:
raise ImproperlyConfigured( raise ImproperlyConfigured(
"Set Operation.activity_name to an ugettext_nooped " "Set Operation.activity_name to an ugettext_nooped "
......
...@@ -34,7 +34,7 @@ class OperationTestCase(TestCase): ...@@ -34,7 +34,7 @@ class OperationTestCase(TestCase):
with patch.object(Operation, 'check_precond'): with patch.object(Operation, 'check_precond'):
with patch.object(Operation, 'create_activity') as create_act: with patch.object(Operation, 'create_activity') as create_act:
try: try:
op.async(system=True) op._async(system=True)
except AbortEx: except AbortEx:
self.assertTrue(create_act.called) self.assertTrue(create_act.called)
......
...@@ -45,10 +45,10 @@ def handler500(request): ...@@ -45,10 +45,10 @@ def handler500(request):
logger.exception("unhandled exception") logger.exception("unhandled exception")
ctx = get_context(request, exception) ctx = get_context(request, exception)
try: try:
resp = render("500.html", ctx, resp = render(request,"500.html", ctx,
RequestContext(request).flatten()) RequestContext(request).flatten())
except: except:
resp = render("500.html", ctx) resp = render(request,"500.html", ctx)
resp.status_code = 500 resp.status_code = 500
return resp return resp
...@@ -56,6 +56,6 @@ def handler500(request): ...@@ -56,6 +56,6 @@ def handler500(request):
def handler403(request, *args, **argv): def handler403(request, *args, **argv):
cls, exception, traceback = exc_info() cls, exception, traceback = exc_info()
ctx = get_context(request, exception) ctx = get_context(request, exception)
resp = render("403.html", ctx) resp = render(request,"403.html", ctx)
resp.status_code = 403 resp.status_code = 403
return resp(request) return resp
[ [
{ {
"pk": 1, "pk": 1,
"model": "sites.site",
"fields": {
"domain": "example.com",
"name": "example.com"
}
},
{
"pk": 1,
"model": "vm.lease", "model": "vm.lease",
"fields": { "fields": {
"suspend_interval_seconds": 18000, "suspend_interval_seconds": 18000,
......
...@@ -46,8 +46,8 @@ from django.forms.widgets import TextInput, HiddenInput ...@@ -46,8 +46,8 @@ from django.forms.widgets import TextInput, HiddenInput
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.utils.html import escape, format_html from django.utils.html import escape, format_html
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy from django.utils.text import format_lazy
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import gettext_lazy as _
from simplesshkey.models import UserKey from simplesshkey.models import UserKey
from sizefield.widgets import FileSizeWidget from sizefield.widgets import FileSizeWidget
...@@ -62,7 +62,7 @@ from vm.models import ( ...@@ -62,7 +62,7 @@ from vm.models import (
from .models import Profile, GroupProfile, Message from .models import Profile, GroupProfile, Message
from .validators import domain_validator, meta_data_validator, user_data_validator 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) for l in LANGUAGES)
priority_choices = ( priority_choices = (
...@@ -1103,7 +1103,7 @@ class VmPortRemoveForm(OperationForm): ...@@ -1103,7 +1103,7 @@ class VmPortRemoveForm(OperationForm):
class VmPortAddForm(OperationForm): class VmPortAddForm(OperationForm):
port = forms.IntegerField(required=True, label=_('Port'), port = forms.IntegerField(required=True, label=_('Port'),
min_value=1, max_value=65535) 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')) required=True, label=_('Protocol'))
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
...@@ -1303,7 +1303,7 @@ class TraitForm(forms.ModelForm): ...@@ -1303,7 +1303,7 @@ class TraitForm(forms.ModelForm):
class MyProfileForm(forms.ModelForm): class MyProfileForm(forms.ModelForm):
preferred_language = forms.ChoiceField( preferred_language = forms.ChoiceField(
initial=LANGUAGES_WITH_CODE, choices=LANGUAGES_WITH_CODE,
label=_("Preferred language"), label=_("Preferred language"),
) )
......
...@@ -28,6 +28,7 @@ from django.http import HttpRequest, Http404, QueryDict ...@@ -28,6 +28,7 @@ from django.http import HttpRequest, Http404, QueryDict
from django.utils import baseconv from django.utils import baseconv
from ..models import Profile from ..models import Profile
from vm.models import Node
from ..views import InstanceActivityDetail, InstanceActivity from ..views import InstanceActivityDetail, InstanceActivity
from ..views import vm_ops, vm_mass_ops, Instance, UnsubscribeFormView from ..views import vm_ops, vm_mass_ops, Instance, UnsubscribeFormView
from ..views import AclUpdateView from ..views import AclUpdateView
...@@ -35,11 +36,13 @@ from .. import views ...@@ -35,11 +36,13 @@ from .. import views
class QuerySet(list): class QuerySet(list):
model = MagicMock() model = Node
def get(self, *args, **kwargs): def get(self, *args, **kwargs):
return self.pop() return self.pop()
def all(self):
return self
class ViewUserTestCase(unittest.TestCase): class ViewUserTestCase(unittest.TestCase):
...@@ -165,14 +168,14 @@ class VmOperationViewTestCase(unittest.TestCase): ...@@ -165,14 +168,14 @@ class VmOperationViewTestCase(unittest.TestCase):
inst = MagicMock(spec=Instance) inst = MagicMock(spec=Instance)
inst._meta.object_name = "Instance" inst._meta.object_name = "Instance"
inst.migrate = Instance._ops['migrate'](inst) inst.migrate = Instance._ops['migrate'](inst)
inst.migrate.async = MagicMock() inst.migrate._async = MagicMock()
inst.has_level.return_value = True inst.has_level.return_value = True
form_kwargs.return_value = { form_kwargs.return_value = {
'default': 100, 'choices': QuerySet([node])} 'default': 100, 'choices': QuerySet([node])}
go.return_value = inst go.return_value = inst
assert view.as_view()(request, pk=1234)['location'] assert view.as_view()(request, pk=1234)['location']
assert not msg.error.called 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) to_node=node, live_migration=True, user=request.user)
def test_migrate_failed(self): def test_migrate_failed(self):
...@@ -186,14 +189,14 @@ class VmOperationViewTestCase(unittest.TestCase): ...@@ -186,14 +189,14 @@ class VmOperationViewTestCase(unittest.TestCase):
inst = MagicMock(spec=Instance) inst = MagicMock(spec=Instance)
inst._meta.object_name = "Instance" inst._meta.object_name = "Instance"
inst.migrate = Instance._ops['migrate'](inst) inst.migrate = Instance._ops['migrate'](inst)
inst.migrate.async = MagicMock() inst.migrate._async = MagicMock()
inst.migrate.async.side_effect = Exception inst.migrate._async.side_effect = Exception
inst.has_level.return_value = True inst.has_level.return_value = True
form_kwargs.return_value = { form_kwargs.return_value = {
'default': 100, 'choices': QuerySet([node])} 'default': 100, 'choices': QuerySet([node])}
go.return_value = inst go.return_value = inst
assert view.as_view()(request, pk=1234)['location'] assert view.as_view()(request, pk=1234)['location']
assert inst.migrate.async.called assert inst.migrate._async.called
assert msg.error.called assert msg.error.called
def test_migrate_wo_permission(self): def test_migrate_wo_permission(self):
...@@ -206,14 +209,14 @@ class VmOperationViewTestCase(unittest.TestCase): ...@@ -206,14 +209,14 @@ class VmOperationViewTestCase(unittest.TestCase):
inst = MagicMock(spec=Instance) inst = MagicMock(spec=Instance)
inst._meta.object_name = "Instance" inst._meta.object_name = "Instance"
inst.migrate = Instance._ops['migrate'](inst) inst.migrate = Instance._ops['migrate'](inst)
inst.migrate.async = MagicMock() inst.migrate._async = MagicMock()
inst.has_level.return_value = True inst.has_level.return_value = True
form_kwargs.return_value = { form_kwargs.return_value = {
'default': 100, 'choices': QuerySet([node])} 'default': 100, 'choices': QuerySet([node])}
go.return_value = inst go.return_value = inst
with self.assertRaises(PermissionDenied): with self.assertRaises(PermissionDenied):
assert view.as_view()(request, pk=1234)['location'] 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): def test_migrate_template(self):
"""check if GET dialog's template can be rendered""" """check if GET dialog's template can be rendered"""
...@@ -239,7 +242,7 @@ class VmOperationViewTestCase(unittest.TestCase): ...@@ -239,7 +242,7 @@ class VmOperationViewTestCase(unittest.TestCase):
inst.name = "asd" inst.name = "asd"
inst._meta.object_name = "Instance" inst._meta.object_name = "Instance"
inst.save_as_template = Instance._ops['save_as_template'](inst) 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 inst.has_level.return_value = True
go.return_value = inst go.return_value = inst
assert view.as_view()(request, pk=1234) assert view.as_view()(request, pk=1234)
...@@ -256,7 +259,7 @@ class VmOperationViewTestCase(unittest.TestCase): ...@@ -256,7 +259,7 @@ class VmOperationViewTestCase(unittest.TestCase):
inst.name = "asd" inst.name = "asd"
inst._meta.object_name = "Instance" inst._meta.object_name = "Instance"
inst.save_as_template = Instance._ops['save_as_template'](inst) 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 inst.has_level.return_value = True
go.return_value = inst go.return_value = inst
assert view.as_view()(request, pk=1234)['location'] assert view.as_view()(request, pk=1234)['location']
...@@ -329,7 +332,7 @@ class VmMassOperationViewTestCase(unittest.TestCase): ...@@ -329,7 +332,7 @@ class VmMassOperationViewTestCase(unittest.TestCase):
inst = MagicMock(spec=Instance) inst = MagicMock(spec=Instance)
inst._meta.object_name = "Instance" inst._meta.object_name = "Instance"
inst.migrate = Instance._ops['migrate'](inst) inst.migrate = Instance._ops['migrate'](inst)
inst.migrate.async = MagicMock() inst.migrate._async = MagicMock()
inst.has_level.return_value = True inst.has_level.return_value = True
go.return_value = [inst] go.return_value = [inst]
assert view.as_view()(request, pk=1234)['location'] assert view.as_view()(request, pk=1234)['location']
...@@ -408,13 +411,13 @@ class RenewViewTest(unittest.TestCase): ...@@ -408,13 +411,13 @@ class RenewViewTest(unittest.TestCase):
inst._meta.object_name = "Instance" inst._meta.object_name = "Instance"
inst.lease = MagicMock(pk=99) inst.lease = MagicMock(pk=99)
inst.renew = Instance._ops['renew'](inst) inst.renew = Instance._ops['renew'](inst)
inst.renew.async = MagicMock() inst.renew._async = MagicMock()
inst.has_level.return_value = True inst.has_level.return_value = True
go.return_value = inst go.return_value = inst
assert view.as_view()(request, pk=1234) assert view.as_view()(request, pk=1234)
assert not msg.error.called assert not msg.error.called
assert inst.renew.async.called_with(user=request.user, lease=None) assert inst.renew._async.called_with(user=request.user, lease=None)
assert inst.renew.async.return_value.get.called assert inst.renew._async.return_value.get.called
# success would redirect # success would redirect
def test_renew_by_owner_w_param(self): def test_renew_by_owner_w_param(self):
...@@ -427,7 +430,7 @@ class RenewViewTest(unittest.TestCase): ...@@ -427,7 +430,7 @@ class RenewViewTest(unittest.TestCase):
inst._meta.object_name = "Instance" inst._meta.object_name = "Instance"
inst.lease = MagicMock(pk=99) inst.lease = MagicMock(pk=99)
inst.renew = Instance._ops['renew'](inst) inst.renew = Instance._ops['renew'](inst)
inst.renew.async = MagicMock() inst.renew._async = MagicMock()
inst.has_level.return_value = True inst.has_level.return_value = True
go.return_value = inst go.return_value = inst
assert view.as_view()(request, pk=1234) assert view.as_view()(request, pk=1234)
...@@ -441,7 +444,7 @@ class RenewViewTest(unittest.TestCase): ...@@ -441,7 +444,7 @@ class RenewViewTest(unittest.TestCase):
inst = MagicMock(spec=Instance) inst = MagicMock(spec=Instance)
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.return_value = False inst.has_level.return_value = False
go.return_value = inst go.return_value = inst
self.assertIn('login', self.assertIn('login',
...@@ -455,7 +458,7 @@ class RenewViewTest(unittest.TestCase): ...@@ -455,7 +458,7 @@ class RenewViewTest(unittest.TestCase):
inst = MagicMock(spec=Instance) inst = MagicMock(spec=Instance)
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.return_value = False inst.has_level.return_value = False
go.return_value = inst go.return_value = inst
with self.assertRaises(PermissionDenied): with self.assertRaises(PermissionDenied):
...@@ -470,7 +473,7 @@ class RenewViewTest(unittest.TestCase): ...@@ -470,7 +473,7 @@ class RenewViewTest(unittest.TestCase):
inst._meta.object_name = "Instance" inst._meta.object_name = "Instance"
inst.lease = MagicMock(pk=99) inst.lease = MagicMock(pk=99)
inst.renew = Instance._ops['renew'](inst) inst.renew = Instance._ops['renew'](inst)
inst.renew.async = MagicMock() inst.renew._async = MagicMock()
inst.has_level.return_value = False inst.has_level.return_value = False
go.return_value = inst go.return_value = inst
with self.assertRaises(PermissionDenied): with self.assertRaises(PermissionDenied):
...@@ -481,8 +484,9 @@ class RenewViewTest(unittest.TestCase): ...@@ -481,8 +484,9 @@ class RenewViewTest(unittest.TestCase):
view = vm_ops['renew'] view = vm_ops['renew']
inst = MagicMock(spec=Instance, pk=11) inst = MagicMock(spec=Instance, pk=11)
inst._meta.object_name = "Instance" inst._meta.object_name = "Instance"
inst.lease = MagicMock(pk=99)
inst.renew = Instance._ops['renew'](inst) 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] key = view.get_token_url(inst, user).split('?')[1].split('=')[1]
request = FakeRequestFactory(GET={'k': key}) # other user! request = FakeRequestFactory(GET={'k': key}) # other user!
...@@ -499,8 +503,9 @@ class RenewViewTest(unittest.TestCase): ...@@ -499,8 +503,9 @@ class RenewViewTest(unittest.TestCase):
view = vm_ops['renew'] view = vm_ops['renew']
inst = MagicMock(spec=Instance, pk=11) inst = MagicMock(spec=Instance, pk=11)
inst._meta.object_name = "Instance" inst._meta.object_name = "Instance"
inst.lease = MagicMock(pk=99)
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)
...@@ -536,7 +541,7 @@ class RenewViewTest(unittest.TestCase): ...@@ -536,7 +541,7 @@ class RenewViewTest(unittest.TestCase):
inst = MagicMock(spec=Instance, pk=11) inst = MagicMock(spec=Instance, pk=11)
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.return_value = False inst.has_level.return_value = False
key = view.get_token_url(inst, user).split('?')[1].split('=')[1] key = view.get_token_url(inst, user).split('?')[1].split('=')[1]
with patch('dashboard.views.signing.loads') as loader, \ with patch('dashboard.views.signing.loads') as loader, \
......
...@@ -485,7 +485,7 @@ class Vlan(AclBase, models.Model): ...@@ -485,7 +485,7 @@ class Vlan(AclBase, models.Model):
mask = int(IPAddress(tpl % {"a": 1, "b": 1, "c": 1, "d": 1})) mask = int(IPAddress(tpl % {"a": 1, "b": 1, "c": 1, "d": 1}))
prefixlen = 128 prefixlen = 128
while mask % 2 == 0: while mask % 2 == 0:
mask /= 2 mask //= 2
prefixlen -= 1 prefixlen -= 1
return (tpl, prefixlen) return (tpl, prefixlen)
......
...@@ -35,7 +35,7 @@ from django.core.exceptions import PermissionDenied, SuspiciousOperation ...@@ -35,7 +35,7 @@ from django.core.exceptions import PermissionDenied, SuspiciousOperation
from django.urls import reverse from django.urls import reverse
from django.db.models import Q from django.db.models import Q
from django.utils import timezone 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 re import search
from sizefield.utils import filesizeformat from sizefield.utils import filesizeformat
......
...@@ -241,8 +241,7 @@ class InstanceActivityTestCase(TestCase): ...@@ -241,8 +241,7 @@ class InstanceActivityTestCase(TestCase):
original_create = InstanceActivity.create original_create = InstanceActivity.create
mocked_create = types.MethodType(original_create.__func__, mocked_create = types.MethodType(original_create.__func__,
mock_instance_activity_cls, mock_instance_activity_cls)
original_create.__self__.__class__)
try: try:
mocked_create('test', instance, readable_name="test", mocked_create('test', instance, readable_name="test",
concurrency_check=False) concurrency_check=False)
......
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