Skip to content

Commit

Permalink
autoscale: encoding service_url
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsmedina committed Jul 30, 2015
1 parent 92de2b8 commit 5082c79
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions autoscale/tests.py
Expand Up @@ -3,6 +3,9 @@

from mock import patch

import os
import urllib


class IndexTestCase(TestCase):
@patch("auth.views.token_is_valid")
Expand All @@ -15,3 +18,21 @@ def test_index(self, token_is_valid):

response = self.client.get(reverse("autoscale"))
self.assertTemplateUsed(response, "autoscale/index.html")

@patch("auth.views.token_is_valid")
def test_service_url(self, token_is_valid):
token_is_valid.return_value = True

autoscale_dashboard_url = "http://localhost:123"
os.environ["AUTOSCALE_DASHBOARD_URL"] = autoscale_dashboard_url
session_engine = "django.contrib.sessions.backends.file"
token = "token/+12faslfkl12"

with self.settings(SESSION_ENGINE=session_engine):
session = self.client.session
session['tsuru_token'] = "beare {}".format(token)
session.save()

response = self.client.get(reverse("autoscale"))
expected = "{}?TSURU_TOKEN={}".format(autoscale_dashboard_url, urllib.quote(token))
self.assertEqual(response.context_data["service_url"], expected)
2 changes: 2 additions & 0 deletions autoscale/views.py
Expand Up @@ -3,6 +3,7 @@
from auth.views import LoginRequiredMixin

import os
import urllib


class Index(LoginRequiredMixin, TemplateView):
Expand All @@ -11,6 +12,7 @@ class Index(LoginRequiredMixin, TemplateView):
def get_context_data(self, *args, **kwargs):
context = super(Index, self).get_context_data(*args, **kwargs)
token = self.request.session.get('tsuru_token').split(' ')[1]
token = urllib.quote(token)
service_url = "{}?TSURU_TOKEN={}".format(os.environ.get("AUTOSCALE_DASHBOARD_URL"), token)
context["service_url"] = service_url
return context

0 comments on commit 5082c79

Please sign in to comment.