# -*- coding: utf-8 -*-
from django.core.urlresolvers import reverse
from hvad.test_utils.context_managers import LanguageOverride
from hvad.test_utils.testcase import NaniTestCase
from hvad.test_utils.request_factory import RequestFactory
from hvad.test_utils.project.app.models import Normal
from hvad.views import TranslatableUpdateView

class ViewsTest(NaniTestCase):
    def setUp(self):
        with LanguageOverride("en"):
            self.object = Normal.objects.language().create(shared_field="test", translated_field="translated test")

            self.rf = RequestFactory()
            self.request = self.rf.post('/url/')

    def test_update_view_get(self):
        with LanguageOverride("en"):
            response = self.client.get(reverse('update_normal', args=[self.object.id]))
            self.assertTrue(response.status_code== 200)

            response = self.client.get(reverse('update_normal_slug', kwargs={'slug': self.object.shared_field}))
            self.assertTrue(response.status_code == 200)

            response = self.client.get(reverse('update_normal', args=[self.object.id]) + "?%s=da" % TranslatableUpdateView.query_language_key)
            self.assertTrue(response.status_code == 200)

            response = self.client.get(reverse('update_normal', args=[self.object.id * 100]) + "?%s=da" % TranslatableUpdateView.query_language_key)
            self.assertTrue(response.status_code == 404)

    def test_update_view_post(self):
        with LanguageOverride("en"):
            translated_string = u"some english translation"
            response = self.client.post(reverse('update_normal', args=[self.object.id]),
                                                data={
                                                    'shared_field': 'some value',
                                                    'translated_field': translated_string,
                                                })
            self.assertTrue(response.status_code == 302)
            obj = Normal.objects.language().filter(pk=self.object.id).get()
            self.assertTrue(obj.translated_field == translated_string)


            translated_string = u"svenne banan æøå"
            response = self.client.post(reverse('update_normal', args=[self.object.id]) + "?%s=da" % TranslatableUpdateView.query_language_key,data={
                                                    'shared_field': 'some value',
                                                    'translated_field': translated_string,
                                                })
            self.assertTrue(response.status_code, 200)
            obj = Normal.objects.language("da").filter(pk=self.object.id).get()
            self.assertTrue(obj.translated_field == translated_string)

@@ -805,36 +805,37 @@
      self.assert
-True
+Equal
 (response.status
@@ -839,18 +839,17 @@
 tus_code
-==
+,
  200)%0A%0A 
@@ -975,36 +975,37 @@
      self.assert
-True
+Equal
 (response.status
@@ -1001,35 +1001,33 @@
 onse.status_code
- ==
+,
  200)%0A%0A         
@@ -1175,36 +1175,37 @@
      self.assert
-True
+Equal
 (response.status
@@ -1209,19 +1209,17 @@
 tus_code
- ==
+,
  200)%0A%0A 
@@ -1381,36 +1381,37 @@
      self.assert
-True
+Equal
 (response.status
@@ -1415,19 +1415,17 @@
 tus_code
- ==
+,
  404)%0A%0A 
@@ -1573,36 +1573,14 @@
     
-response = self.client.post(
+url = 
 reve
@@ -1622,17 +1622,16 @@
 ect.id%5D)
-,
 %0A       
@@ -1635,36 +1635,49 @@
         
-                    
+response = self.client.post(url,%0A
         
@@ -1715,40 +1715,8 @@
     
-              
-                  
 'sha
@@ -1745,40 +1745,8 @@
 e',%0A
-                                
     
@@ -1804,40 +1804,8 @@
 ng,%0A
-                                
     
@@ -1834,36 +1834,37 @@
      self.assert
-True
+Equal
 (response.status
@@ -1868,19 +1868,17 @@
 tus_code
- ==
+,
  302)%0A  
@@ -1966,36 +1966,37 @@
      self.assert
-True
+Equal
 (obj.translated_
@@ -1992,35 +1992,33 @@
 translated_field
- ==
+,
  translated_stri
@@ -2022,17 +2022,16 @@
 tring)%0A%0A
-%0A
         
@@ -2118,55 +2118,28 @@
 ost(
-reverse('update_normal', args=%5Bself.object.id%5D)
+%0A                url
  + %22
@@ -2190,31 +2190,17 @@
 age_key,
-data=%7B%0A        
+%0A
         
@@ -2203,32 +2203,31 @@
             
-        
+data=%7B%0A
             
@@ -2268,40 +2268,8 @@
 e',%0A
-                                
     
@@ -2327,40 +2327,8 @@
 ng,%0A
-                                
     
@@ -2365,20 +2365,21 @@
 f.assert
-True
+Equal
 (respons
@@ -2393,19 +2393,19 @@
 s_code, 
-200
+302
 )%0A      
@@ -2505,12 +2505,13 @@
 sert
-True
+Equal
 (obj
@@ -2531,11 +2531,9 @@
 ield
- ==
+,
  tra
@@ -2528,28 +2528,29 @@
 d_field, translated_string)%0A
+%0A

Use assertEqual in tests instead of assertTrue.