from django.test import TestCase
from django.core.urlresolvers import reverse

# from devilry_developer.testhelpers.corebuilder import SubjectBuilder
from devilry_developer.testhelpers.corebuilder import UserBuilder
from devilry_developer.testhelpers.soupselect import cssFind
from devilry_developer.testhelpers.soupselect import cssGet
from devilry_developer.testhelpers.soupselect import cssExists
from devilry_developer.testhelpers.login import LoginTestCaseMixin



class TestFrontpage(TestCase, LoginTestCaseMixin):
    def setUp(self):
        self.url = reverse('devilry_frontpage')
        self.testuser = UserBuilder('testuser').user

    def test_not_authenticated(self):
        response = self.client.get(self.url)
        self.assertEquals(response.status_code, 302)

    def test_authenticated(self):
        response = self.get_as(self.testuser, self.url)
        self.assertEquals(response.status_code, 200)
    
    def test_helplinks(self):
        html = self.get_as(self.testuser, self.url).content
        self.assertTrue(cssExists(html, '#devilry_frontpage_helplinks'))
        self.assertEquals(
            cssGet(html, '#devilry_frontpage_helplinks ul li a').text.strip(),
            'Official Devilry documentation')

    def test_changelanguage(self):
        html = self.get_as(self.testuser, self.url).content
        self.assertTrue(cssExists(html, '#devilry_frontpage_languageselect #devilry_change_language_form'))
@@ -393,16 +393,82 @@
 sExists%0A
+# from devilry_developer.testhelpers.soupselect import prettyhtml%0A
 from dev
@@ -700,13 +700,8 @@
 er')
-.user
 %0A%0A  
@@ -905,32 +905,37 @@
 as(self.testuser
+.user
 , self.url)%0A    
@@ -1050,32 +1050,37 @@
 as(self.testuser
+.user
 , self.url).cont
@@ -1326,30 +1326,731 @@
 est_
-changelanguage(self):%0A
+languageselect(self):%0A        self.testuser.update_profile(%0A            languagecode='en'%0A        )%0A        with self.settings(LANGUAGES=%5B('en', 'English'), ('nb', 'Norwegian')%5D):%0A            html = self.get_as(self.testuser.user, self.url).content%0A            self.assertTrue(cssExists(html,%0A                '#devilry_frontpage_languageselect #devilry_change_language_form'))%0A            self.assertEquals(%0A                cssGet(html, '#devilry_change_language_form option%5Bvalue=%22en%22%5D')%5B'selected'%5D,%0A                'selected')%0A%0A    def test_languageselect_no_current_language(self):%0A        with self.settings(%0A                LANGUAGES=%5B('en', 'English'), ('nb', 'Norwegian')%5D,%0A                LANGUAGE_CODE='nb'):%0A    
     
@@ -2081,24 +2081,29 @@
 elf.testuser
+.user
 , self.url).
@@ -2102,32 +2102,36 @@
 lf.url).content%0A
+    
         self.ass
@@ -2145,32 +2145,48 @@
 (cssExists(html,
+%0A               
  '#devilry_front
@@ -2217,28 +2217,181 @@
 ilry_change_language_form'))
+%0A            self.assertEquals(%0A                cssGet(html, '#devilry_change_language_form option%5Bvalue=%22nb%22%5D')%5B'selected'%5D,%0A                'selected')

Test langauage select rendering.