Permalink
Browse files

move tests to its own "app" allowing for custom models and added one …

…test using model
  • Loading branch information...
1 parent 9ab81a8 commit ff41b600f56dacc3e4bfe3e6e15782d90c8f9aaf @brosner committed Mar 20, 2010
@@ -0,0 +1,2 @@
+# the sad reality of Django app testing. not naming this module "tests"
+# because of possible collision of other apps that do a similar thing.
@@ -0,0 +1,9 @@
+from django.db import models
+
+from timezones.fields import TimeZoneField
+
+
+
+class Profile(models.Model):
+ name = models.CharField(max_length=100)
+ timezone = TimeZoneField()
@@ -1,10 +1,13 @@
+import re
+
from datetime import datetime
from django import forms
from django.conf import settings
from django.test import TestCase
import timezones.forms
+import timezones.timezones_tests.models as test_models
from timezones.utils import localtime_for_timezone, adjust_datetime_to_timezone
@@ -42,26 +45,37 @@ def test_adjust_datetime_to_timezone(self):
class TimeZoneFieldTestCase(TimeZoneTestCase):
- def test_clean_required(self):
+ def test_forms_clean_required(self):
f = timezones.forms.TimeZoneField()
self.assertEqual(
repr(f.clean("US/Eastern")),
"<DstTzInfo 'US/Eastern' EST-1 day, 19:00:00 STD>"
)
self.assertRaises(forms.ValidationError, f.clean, "")
- def test_clean_not_required(self):
+ def test_forms_clean_not_required(self):
f = timezones.forms.TimeZoneField(required=False)
self.assertEqual(
repr(f.clean("US/Eastern")),
"<DstTzInfo 'US/Eastern' EST-1 day, 19:00:00 STD>"
)
self.assertEqual(f.clean(""), "")
+
+ def test_models_as_a_form(self):
+ class ProfileForm(forms.ModelForm):
+ class Meta:
+ model = test_models.Profile
+ form = ProfileForm()
+ rendered = form.as_p()
+ self.assert_(
+ bool(re.search(r'<option value="[\w/]+">\([A-Z]+(?:\+|\-)\d{4}\)\s[\w/]+</option>', rendered)),
+ "Did not find pattern in rendered form"
+ )
class LocalizedDateTimeFieldTestCase(TimeZoneTestCase):
- def test_clean_required(self):
+ def test_forms_clean_required(self):
# the default case where no timezone is given explicitly. uses settings.TIME_ZONE.
f = timezones.forms.LocalizedDateTimeField()
self.assertEqual(
@@ -70,7 +84,7 @@ def test_clean_required(self):
)
self.assertRaises(forms.ValidationError, f.clean, "")
- def test_clean_required(self):
+ def test_forms_clean_required(self):
# the default case where no timezone is given explicitly. uses settings.TIME_ZONE.
f = timezones.forms.LocalizedDateTimeField(required=False)
self.assertEqual(

0 comments on commit ff41b60

Please sign in to comment.