summaryrefslogtreecommitdiff
path: root/tests/db_functions
diff options
context:
space:
mode:
authorNick Pope <nick.pope@flightdataservices.com>2020-07-16 23:32:46 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-10-02 06:58:03 +0200
commit06c5d3fafc6aeb96387148726713b611aeba7fa1 (patch)
tree80a366cad2aa8caf22062d6eb5f4487c36a000e2 /tests/db_functions
parentf87b0ecd37e64e7a019d472de37d0789a8790f1f (diff)
downloaddjango-06c5d3fafc6aeb96387148726713b611aeba7fa1.tar.gz
Fixed #32060 -- Added Random database function.
Diffstat (limited to 'tests/db_functions')
-rw-r--r--tests/db_functions/math/test_random.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/db_functions/math/test_random.py b/tests/db_functions/math/test_random.py
new file mode 100644
index 0000000000..6bcf49baf9
--- /dev/null
+++ b/tests/db_functions/math/test_random.py
@@ -0,0 +1,13 @@
+from django.db.models.functions import Random
+from django.test import TestCase
+
+from ..models import FloatModel
+
+
+class RandomTests(TestCase):
+ def test(self):
+ FloatModel.objects.create()
+ obj = FloatModel.objects.annotate(random=Random()).first()
+ self.assertIsInstance(obj.random, float)
+ self.assertGreaterEqual(obj.random, 0)
+ self.assertLess(obj.random, 1)