diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2014-06-07 17:04:58 -0700 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2014-06-07 17:05:51 -0700 |
| commit | 6fd455adfcc85f6bd390bce784a1b5dfe5d610ea (patch) | |
| tree | bbde7ef48977f036461e15a68addc9a3dcdd261e /tests | |
| parent | 250e2b422b4da93f38cd61319b9b3c9f422e6ede (diff) | |
Fixed #22436: More careful checking on method ref'ce serialization
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_writer.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index 2628388656..925a9d6538 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import datetime import os import tokenize +import unittest from django.core.validators import RegexValidator, EmailValidator from django.db import models, migrations @@ -16,6 +17,12 @@ from django.utils.translation import ugettext_lazy as _ from django.utils.timezone import get_default_timezone +class TestModel1(object): + def upload_to(self): + return "somewhere dynamic" + thing = models.FileField(upload_to=upload_to) + + class WriterTests(TestCase): """ Tests the migration writer (makes migration files from Migration instances) @@ -137,6 +144,26 @@ class WriterTests(TestCase): self.assertSerializedEqual(one_item_tuple) self.assertSerializedEqual(many_items_tuple) + @unittest.skipUnless(six.PY2, "Only applies on Python 2") + def test_serialize_direct_function_reference(self): + """ + Ticket #22436: You cannot use a function straight from its body + (e.g. define the method and use it in the same body) + """ + with self.assertRaises(ValueError): + self.serialize_round_trip(TestModel1.thing) + + def test_serialize_local_function_reference(self): + """ + Neither py2 or py3 can serialize a reference in a local scope. + """ + class TestModel2(object): + def upload_to(self): + return "somewhere dynamic" + thing = models.FileField(upload_to=upload_to) + with self.assertRaises(ValueError): + self.serialize_round_trip(TestModel2.thing) + def test_simple_migration(self): """ Tests serializing a simple migration. |
