from __future__ import absolute_import, print_function, unicode_literals

from django.core.urlresolvers import reverse
from rest_framework.test import APITestCase

from kolibri.auth.test.test_api import FacilityFactory

from kolibri.auth.test.helpers import create_superuser, provision_device

DUMMY_PASSWORD = "password"

class KolibriTagNavigationTestCase(APITestCase):

    def test_redirect_to_setup_wizard(self):
        response = self.client.get("/")
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.get("location"), reverse('kolibri:setupwizardplugin:setupwizard'))

    def test_redirect_root_to_user_if_not_logged_in(self):
        provision_device()
        response = self.client.get("/")
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.get("location"), reverse('kolibri:user:user'))

    def test_redirect_root_to_learn_if_logged_in(self):
        facility = FacilityFactory.create()
        do = create_superuser(facility)
        provision_device()
        self.client.login(username=do.username, password=DUMMY_PASSWORD)
        response = self.client.get("/")
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.get("location"), reverse('kolibri:learnplugin:learn'))

@@ -35,25 +35,69 @@
 port
-, print_function,
+%0Afrom __future__ import print_function%0Afrom __future__ import
  uni
@@ -228,40 +228,39 @@
 est.
-test_api import FacilityFactory%0A
+helpers import create_superuser
 %0Afro
@@ -298,42 +298,79 @@
 ort 
-create_superuser, provision_device
+provision_device%0Afrom kolibri.auth.test.test_api import FacilityFactory
 %0A%0ADU
@@ -570,35 +570,35 @@
 se.status_code, 
-302
+200
 )%0A        self.a
@@ -595,50 +595,13 @@
     
-self.assertEqual(response.get(%22location%22),
+url =
  rev
@@ -645,16 +645,134 @@
 wizard')
+%0A        self.assertTrue('%3Cmeta http-equiv=%22refresh%22 content=%220;URL=%5C'%7Burl%7D%5C'%22 /%3E'.format(url=url) in response.content
 )%0A%0A    d

Update KolibriTagNavigationTestCase to handle new redirect method