diff options
| author | MichaĆ Modzelewski <michal.modzelewski@gmail.com> | 2015-01-02 02:39:31 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-01-12 18:15:34 -0500 |
| commit | 65246de7b1d70d25831ab394c4f4a75813f629fe (patch) | |
| tree | 618c5f030f9a77d240dc59b132dd1e152baca116 /tests/expressions | |
| parent | aa8ee6a5731b37b73635e7605521fb1a54a5c10d (diff) | |
Fixed #24031 -- Added CASE expressions to the ORM.
Diffstat (limited to 'tests/expressions')
| -rw-r--r-- | tests/expressions/models.py | 16 | ||||
| -rw-r--r-- | tests/expressions/tests.py | 17 |
2 files changed, 31 insertions, 2 deletions
diff --git a/tests/expressions/models.py b/tests/expressions/models.py index 53eb54ec48..69de52c308 100644 --- a/tests/expressions/models.py +++ b/tests/expressions/models.py @@ -56,3 +56,19 @@ class Experiment(models.Model): def duration(self): return self.end - self.start + + +@python_2_unicode_compatible +class Time(models.Model): + time = models.TimeField(null=True) + + def __str__(self): + return "%s" % self.time + + +@python_2_unicode_compatible +class UUID(models.Model): + uuid = models.UUIDField(null=True) + + def __str__(self): + return "%s" % self.uuid diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py index 8165a496dc..3c508b8520 100644 --- a/tests/expressions/tests.py +++ b/tests/expressions/tests.py @@ -2,15 +2,16 @@ from __future__ import unicode_literals from copy import deepcopy import datetime +import uuid from django.core.exceptions import FieldError from django.db import connection, transaction, DatabaseError -from django.db.models import F, Value +from django.db.models import F, Value, TimeField, UUIDField from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature from django.test.utils import Approximate from django.utils import six -from .models import Company, Employee, Number, Experiment +from .models import Company, Employee, Number, Experiment, Time, UUID class BasicExpressionsTests(TestCase): @@ -799,3 +800,15 @@ class FTimeDeltaTests(TestCase): over_estimate = [e.name for e in Experiment.objects.filter(estimated_time__lt=F('end') - F('start'))] self.assertEqual(over_estimate, ['e4']) + + +class ValueTests(TestCase): + def test_update_TimeField_using_Value(self): + Time.objects.create() + Time.objects.update(time=Value(datetime.time(1), output_field=TimeField())) + self.assertEqual(Time.objects.get().time, datetime.time(1)) + + def test_update_UUIDField_using_Value(self): + UUID.objects.create() + UUID.objects.update(uuid=Value(uuid.UUID('12345678901234567890123456789012'), output_field=UUIDField())) + self.assertEqual(UUID.objects.get().uuid, uuid.UUID('12345678901234567890123456789012')) |
