Commit 697de735 by Czémán Arnold

dashboard, vm: fix user handling i tests, new Origin type cannot implicit…

dashboard, vm: fix user handling i tests, new Origin type cannot implicit convert to str, fix redirect_chain in 2FA tests, importing vm operation in __init_.py is unnecessary and and brokes the application
parent 252fd315
...@@ -21,7 +21,7 @@ import warnings ...@@ -21,7 +21,7 @@ import warnings
from factory import Factory, Sequence from factory import Factory, Sequence
from mock import patch, MagicMock from mock import patch, MagicMock
from django.contrib.auth.models import User from django.contrib.auth.models import User, AnonymousUser
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.core.signing import TimestampSigner, JSONSerializer, b64_encode from django.core.signing import TimestampSigner, JSONSerializer, b64_encode
from django.http import HttpRequest, Http404, QueryDict from django.http import HttpRequest, Http404, QueryDict
...@@ -629,12 +629,12 @@ def FakeRequestFactory(user=None, **kwargs): ...@@ -629,12 +629,12 @@ def FakeRequestFactory(user=None, **kwargs):
''' '''
if user is None: if user is None:
user = UserFactory()
auth = kwargs.pop('authenticated', True) auth = kwargs.pop('authenticated', True)
user.is_authenticated = lambda: auth user = UserFactory() if auth else AnonymousUser()
user.is_superuser = kwargs.pop('superuser', False) user.is_superuser = kwargs.pop('superuser', False)
if kwargs.pop('has_perms_mock', False): if kwargs.pop('has_perms_mock', False):
user.has_perms = MagicMock(return_value=True) user.has_perms = MagicMock(return_value=True)
if auth:
user.save() user.save()
request = HttpRequest() request = HttpRequest()
......
...@@ -29,22 +29,22 @@ class TemplateSyntaxTestCase(unittest.TestCase): ...@@ -29,22 +29,22 @@ class TemplateSyntaxTestCase(unittest.TestCase):
def test_templates(self): def test_templates(self):
"""Test all templates for syntax errors.""" """Test all templates for syntax errors."""
for loader in Engine.get_default().template_loaders: for loader in Engine.get_default().template_loaders:
print loader print(loader)
self._test_dir(loader.get_template_sources('')) self._test_dir(loader.get_template_sources(''))
def _test_dir(self, dir, path="/"): def _test_dir(self, dir, path="/"):
for i in dir: for i in dir:
i = join(path, i) i = join(path, str(i))
if isfile(i): if isfile(i):
self._test_template(join(path, i)) self._test_template(join(path, i))
elif isdir(i): elif isdir(i):
print "%s:" % i print("%s:" % i)
self._test_dir(listdir(i), i) self._test_dir(listdir(i), i)
def _test_template(self, path): def _test_template(self, path):
print path print(path)
try: try:
Template(open(path).read()).render(Context({})) Template(open(path).read()).render(Context({}))
except (NoReverseMatch, VariableDoesNotExist, KeyError, AttributeError, except (NoReverseMatch, VariableDoesNotExist, KeyError, AttributeError,
ValueError, ) as e: ValueError, ) as e:
print e print(e)
...@@ -1890,9 +1890,9 @@ class TwoFactorTest(LoginMixin, TestCase): ...@@ -1890,9 +1890,9 @@ class TwoFactorTest(LoginMixin, TestCase):
response = c.get("/two-factor-login/", follow=True) response = c.get("/two-factor-login/", follow=True)
self.assertItemsEqual( self.assertItemsEqual(
response.redirect_chain, response.redirect_chain,
[('http://testserver/', 302), [('/', 302),
('http://testserver/dashboard/', 302), ('/dashboard/', 302),
('http://testserver/accounts/login/?next=/dashboard/', 302)] ('/accounts/login/?next=/dashboard/', 302)]
) )
def test_straight_to_2fa_as_user(self): def test_straight_to_2fa_as_user(self):
...@@ -1901,6 +1901,6 @@ class TwoFactorTest(LoginMixin, TestCase): ...@@ -1901,6 +1901,6 @@ class TwoFactorTest(LoginMixin, TestCase):
response = c.get("/two-factor-login/", follow=True) response = c.get("/two-factor-login/", follow=True)
self.assertItemsEqual( self.assertItemsEqual(
response.redirect_chain, response.redirect_chain,
[('http://testserver/', 302), [('/', 302),
('http://testserver/dashboard/', 302)] ('/dashboard/', 302)]
) )
# This import is responsible for running the operations' registration code. # noqa
from . import operations # noqa
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