Commit c469ad29 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

helpdesk: Fix helpdesk tests

parent 16b81eb7
......@@ -88,6 +88,8 @@ class HelpdeskTests(TestCase):
def setUp(self):
def get_user_mock(request, *args, **kwargs):
request.user_uniq = None
request.user = None
if request.META.get('HTTP_X_AUTH_TOKEN', None) == '0000':
request.user_uniq = 'test'
request.user = {'uniq': 'test', 'auth_token': '0000'}
......@@ -238,9 +240,9 @@ class HelpdeskTests(TestCase):
vms = r.context['vms']
nets = r.context['networks']
self.assertEqual(account, USER2)
self.assertEqual(vms[0].name, "user2 vm2")
self.assertEqual(vms[1].name, "user2 vm1")
self.assertEqual(vms.count(), 2)
self.assertEqual(sorted([vms[0].name, vms[1].name]),
sorted(["user2 vm1", "user2 vm2"]))
self.assertEqual(len(nets), 0)
self.assertEqual(r.context['account_exists'], True)
......@@ -43,9 +43,10 @@ from django.core.urlresolvers import reverse
from urllib import unquote
from snf_django.lib.astakos import get_user
import astakosclient
from snf_django.lib import astakos
from synnefo.db.models import VirtualMachine, NetworkInterface, Network
from astakosclient import AstakosClient
# server actions specific imports
from synnefo.api import servers
......@@ -109,13 +110,13 @@ def helpdesk_user_required(func, permitted_groups=PERMITTED_GROUPS):
raise Http404
token = get_token_from_cookie(request, AUTH_COOKIE_NAME)
get_user(request, settings.ASTAKOS_URL,
fallback_token=token, logger=logger)
astakos.get_user(request, settings.ASTAKOS_URL,
fallback_token=token, logger=logger)
if hasattr(request, 'user') and request.user:
groups = request.user.get('groups', [])
if not groups:
logger.error("Failed to access helpdesk view %r",
logger.error("Failed to access helpdesk view. User: %r",
raise PermissionDenied
......@@ -131,7 +132,7 @@ def helpdesk_user_required(func, permitted_groups=PERMITTED_GROUPS):
raise PermissionDenied
logger.error("Failed to access helpdesk view %r. No authenticated "
"user found.")
"user found.", request.user_uniq)
raise PermissionDenied"User %s accessed helpdesk view (%s)", request.user_uniq,
......@@ -194,16 +195,16 @@ def account(request, search_query):
account = None
search_query = vmid
astakos = AstakosClient(settings.ASTAKOS_URL, retry=2,
use_pool=True, logger=logger)
astakos_client = astakosclient.AstakosClient(settings.ASTAKOS_URL, retry=2,
use_pool=True, logger=logger)
if is_uuid:
account = search_query
account_name = astakos.get_username(auth_token, account)
account_name = astakos_client.get_username(auth_token, account)
if account_exists and not is_uuid:
account_name = search_query
account = astakos.get_uuid(auth_token, account_name)
account = astakos_client.get_uuid(auth_token, account_name)
if not account:
account_exists = 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 to comment