diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-02-21 10:52:51 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-21 10:52:51 +0100 |
| commit | 9ff18c08c32cf54d3c3a7a9e459d44711adba30f (patch) | |
| tree | d244a2f0133ddeabbc879b3dc65b31a4b0603d03 /tests/db_functions/text | |
| parent | 21ff23bfeb4014bceaa3df27677fb68409c0634d (diff) | |
| download | django-9ff18c08c32cf54d3c3a7a9e459d44711adba30f.tar.gz | |
Refs #28643 -- Added MD5 database function.
Thanks Tim Graham, Nick Pope and Simon Charette for reviews.
Diffstat (limited to 'tests/db_functions/text')
| -rw-r--r-- | tests/db_functions/text/test_md5.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/db_functions/text/test_md5.py b/tests/db_functions/text/test_md5.py new file mode 100644 index 0000000000..931f80ba2c --- /dev/null +++ b/tests/db_functions/text/test_md5.py @@ -0,0 +1,41 @@ +from django.db import connection +from django.db.models import CharField +from django.db.models.functions import MD5 +from django.test import TestCase +from django.test.utils import register_lookup + +from ..models import Author + + +class MD5Tests(TestCase): + @classmethod + def setUpTestData(cls): + Author.objects.bulk_create([ + Author(alias='John Smith'), + Author(alias='Jordan Élena'), + Author(alias='皇帝'), + Author(alias=''), + Author(alias=None), + ]) + + def test_basic(self): + authors = Author.objects.annotate( + md5_alias=MD5('alias'), + ).values_list('md5_alias', flat=True).order_by('pk') + self.assertSequenceEqual( + authors, + [ + '6117323d2cabbc17d44c2b44587f682c', + 'ca6d48f6772000141e66591aee49d56c', + 'bf2c13bc1154e3d2e7df848cbc8be73d', + 'd41d8cd98f00b204e9800998ecf8427e', + 'd41d8cd98f00b204e9800998ecf8427e' if connection.features.interprets_empty_strings_as_nulls else None, + ], + ) + + def test_transform(self): + with register_lookup(CharField, MD5): + authors = Author.objects.filter( + alias__md5='6117323d2cabbc17d44c2b44587f682c', + ).values_list('alias', flat=True) + self.assertSequenceEqual(authors, ['John Smith']) |
