Ticket #17463: 17463.diff
File 17463.diff, 6.7 KB (added by , 13 years ago) |
---|
-
tests/modeltests/timezones/tests.py
22 22 from django.test.utils import override_settings 23 23 from django.utils import timezone 24 24 from django.utils.tzinfo import FixedOffset 25 from django.utils.unittest import skipIf 25 from django.utils.unittest import skipIf, skipUnless 26 26 27 27 from .forms import EventForm, EventSplitForm, EventModelForm 28 28 from .models import Event, MaybeEvent, Timestamp … … 43 43 TZ_SUPPORT = hasattr(time, 'tzset') 44 44 45 45 46 # On OSes that don't provide tzset (Windows), we can't rely on the timezone 47 # set in the environment. The following decorator will be used to skip tests 48 # that don't enforce their own timezone (with timezone.override or equivalent). 49 requires_tz_support = skipUnless(TZ_SUPPORT, 50 "This test relies on the ability to run a program in an arbitrary " 51 "time zone, but your operating system isn't able to do that.") 52 53 46 54 class BaseDateTimeTests(TestCase): 47 55 48 56 @classmethod … … 238 246 #@override_settings(USE_TZ=True) 239 247 class NewDatabaseTests(BaseDateTimeTests): 240 248 249 @requires_tz_support 241 250 @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6") 242 251 def test_naive_datetime(self): 243 252 dt = datetime.datetime(2011, 9, 1, 13, 20, 30) … … 251 260 # naive datetimes are interpreted in local time 252 261 self.assertEqual(event.dt, dt.replace(tzinfo=EAT)) 253 262 263 @requires_tz_support 254 264 @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6") 255 265 @skipUnlessDBFeature('supports_microsecond_precision') 256 266 def test_naive_datetime_with_microsecond(self): … … 265 275 # naive datetimes are interpreted in local time 266 276 self.assertEqual(event.dt, dt.replace(tzinfo=EAT)) 267 277 278 @requires_tz_support 268 279 @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6") 269 280 @skipIfDBFeature('supports_microsecond_precision') 270 281 def test_naive_datetime_with_microsecond_unsupported(self): … … 347 358 self.assertEqual(Event.objects.filter(dt__in=(prev, dt, next)).count(), 1) 348 359 self.assertEqual(Event.objects.filter(dt__range=(prev, next)).count(), 1) 349 360 361 @requires_tz_support 350 362 @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6") 351 363 def test_query_filter_with_naive_datetime(self): 352 364 dt = datetime.datetime(2011, 9, 1, 12, 20, 30, tzinfo=EAT) … … 567 579 #@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True) 568 580 class TemplateTests(BaseDateTimeTests): 569 581 582 @requires_tz_support 570 583 def test_localtime_templatetag_and_filters(self): 571 584 """ 572 585 Test the {% localtime %} templatetag and related filters. … … 686 699 ctx = Context({'dt': datetime.datetime(2011, 9, 1, 13, 20, 30), 'tz': 'not a tz'}) 687 700 self.assertEqual(tpl.render(ctx), "") 688 701 702 @requires_tz_support 689 703 def test_timezone_templatetag(self): 690 704 """ 691 705 Test the {% timezone %} templatetag. … … 725 739 with self.assertRaises(ValueError if pytz is None else pytz.UnknownTimeZoneError): 726 740 Template("{% load tz %}{% timezone tz %}{% endtimezone %}").render(Context({'tz': 'foobar'})) 727 741 742 @skipIf(sys.platform.startswith('win'), "Windows uses non-standard and local-dependant time zone names") 728 743 def test_get_current_timezone_templatetag(self): 729 744 """ 730 745 Test the {% get_current_timezone %} templatetag. … … 757 772 with self.assertRaises(TemplateSyntaxError): 758 773 Template("{% load tz %}{% get_current_timezone %}").render() 759 774 775 @skipIf(sys.platform.startswith('win'), "Windows uses non-standard and local-dependant time zone names") 760 776 def test_tz_template_context_processor(self): 761 777 """ 762 778 Test the django.core.context_processors.tz template context processor. … … 765 781 self.assertEqual(tpl.render(Context()), "") 766 782 self.assertEqual(tpl.render(RequestContext(HttpRequest())), "Africa/Nairobi" if pytz else "EAT") 767 783 784 @requires_tz_support 768 785 def test_date_and_time_template_filters(self): 769 786 tpl = Template("{{ dt|date:'Y-m-d' }} at {{ dt|time:'H:i:s' }}") 770 787 ctx = Context({'dt': datetime.datetime(2011, 9, 1, 20, 20, 20, tzinfo=UTC)}) … … 790 807 self.assertTrue(tpl.render(ctx).startswith("2011")) 791 808 timezone._localtime = None 792 809 810 @requires_tz_support 793 811 def test_now_template_tag_uses_current_time_zone(self): 794 812 # Regression for #17343 795 813 tpl = Template("{% now \"O\" %}") … … 838 856 #@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True) 839 857 class NewFormsTests(BaseDateTimeTests): 840 858 859 @requires_tz_support 841 860 def test_form(self): 842 861 form = EventForm({'dt': u'2011-09-01 13:20:30'}) 843 862 self.assertTrue(form.is_valid()) … … 867 886 [u"2011-10-30 02:30:00 couldn't be interpreted in time zone " 868 887 u"Europe/Paris; it may be ambiguous or it may not exist."]) 869 888 889 @requires_tz_support 870 890 def test_split_form(self): 871 891 form = EventSplitForm({'dt_0': u'2011-09-01', 'dt_1': u'13:20:30'}) 872 892 self.assertTrue(form.is_valid()) 873 893 self.assertEqual(form.cleaned_data['dt'], datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC)) 874 894 895 @requires_tz_support 875 896 def test_model_form(self): 876 897 EventModelForm({'dt': u'2011-09-01 13:20:30'}).save() 877 898 e = Event.objects.get() … … 888 909 def setUp(self): 889 910 self.client.login(username='super', password='secret') 890 911 912 @requires_tz_support 891 913 def test_changelist(self): 892 914 e = Event.objects.create(dt=datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC)) 893 915 response = self.client.get(reverse('admin:timezones_event_changelist')) … … 899 921 response = self.client.get(reverse('admin:timezones_event_changelist')) 900 922 self.assertContains(response, e.dt.astimezone(ICT).isoformat()) 901 923 924 @requires_tz_support 902 925 def test_change_editable(self): 903 926 e = Event.objects.create(dt=datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC)) 904 927 response = self.client.get(reverse('admin:timezones_event_change', args=(e.pk,))) … … 912 935 self.assertContains(response, e.dt.astimezone(ICT).date().isoformat()) 913 936 self.assertContains(response, e.dt.astimezone(ICT).time().isoformat()) 914 937 938 @requires_tz_support 915 939 def test_change_readonly(self): 916 940 Timestamp.objects.create() 917 941 # re-fetch the object for backends that lose microseconds (MySQL)