From 6a04f63c3eadc164f75c6719b362949014f889da Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Hertzog?= <hertzog@debian.org>
Date: Fri, 5 Sep 2014 11:20:08 +0200
Subject: [PATCH 2/2] Fix test case for Django 1.7's addition of an id
 attribute to radio widgets

As documented on
https://docs.djangoproject.com/en/1.7/ref/forms/widgets/#radioselect
Django 1.7 now adds id attribute to the radio fields. The test case
must be adapted to cope with this.
---
 tests/__init__.py              | 12 ++++++++++++
 tests/fixtures/basic.html      |  6 +++---
 tests/fixtures/horizontal.html |  6 +++---
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/tests/__init__.py b/tests/__init__.py
index 4533d82..979c2a4 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,5 +1,6 @@
 import os
 import sys
+import re
 
 os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.test_settings'
 
@@ -41,6 +42,13 @@ class ExampleForm(forms.Form):
 class BootstrapTemplateTagTests(TestCase):
     def setUp(self):
         call_command('syncdb', interactive=False)
+        self.maxDiff = None
+
+    @classmethod
+    def drop_radio_id_with_old_django(cls, content):
+        if django.VERSION < (1, 7):
+            return re.sub(r' id="id_radio_choice_\d"', '', content)
+        return content
 
     def test_basic_form(self):
         form = ExampleForm()
@@ -51,6 +59,8 @@ class BootstrapTemplateTagTests(TestCase):
         with open(os.path.join(TEST_DIR, tpl)) as f:
             content = f.read()
 
+        content = self.drop_radio_id_with_old_django(content)
+
         self.assertHTMLEqual(html, content)
 
     def test_horizontal_form(self):
@@ -62,4 +72,6 @@ class BootstrapTemplateTagTests(TestCase):
         with open(os.path.join(TEST_DIR, tpl)) as f:
             content = f.read()
 
+        content = self.drop_radio_id_with_old_django(content)
+
         self.assertHTMLEqual(html, content)
diff --git a/tests/fixtures/basic.html b/tests/fixtures/basic.html
index 322806e..636dfe7 100644
--- a/tests/fixtures/basic.html
+++ b/tests/fixtures/basic.html
@@ -56,21 +56,21 @@
             
                 <div class="radio">
                     <label>
-                        <input name="radio_choice" type="radio" value="0" />
+                        <input id="id_radio_choice_0" name="radio_choice" type="radio" value="0" />
                         Zero
                     </label>
                 </div>
             
                 <div class="radio">
                     <label>
-                        <input name="radio_choice" type="radio" value="1" />
+                        <input id="id_radio_choice_1" name="radio_choice" type="radio" value="1" />
                         One
                     </label>
                 </div>
             
                 <div class="radio">
                     <label>
-                        <input name="radio_choice" type="radio" value="2" />
+                        <input id="id_radio_choice_2" name="radio_choice" type="radio" value="2" />
                         Two
                     </label>
                 </div>
diff --git a/tests/fixtures/horizontal.html b/tests/fixtures/horizontal.html
index b255d51..e49ee15 100644
--- a/tests/fixtures/horizontal.html
+++ b/tests/fixtures/horizontal.html
@@ -56,21 +56,21 @@
             
                 <div class="radio">
                     <label>
-                        <input name="radio_choice" type="radio" value="0" />
+                        <input id="id_radio_choice_0" name="radio_choice" type="radio" value="0" />
                         Zero
                     </label>
                 </div>
             
                 <div class="radio">
                     <label>
-                        <input name="radio_choice" type="radio" value="1" />
+                        <input id="id_radio_choice_1" name="radio_choice" type="radio" value="1" />
                         One
                     </label>
                 </div>
             
                 <div class="radio">
                     <label>
-                        <input name="radio_choice" type="radio" value="2" />
+                        <input id="id_radio_choice_2" name="radio_choice" type="radio" value="2" />
                         Two
                     </label>
                 </div>
-- 
2.1.0

