diff --git a/tests/regressiontests/m2m_regress/models.py b/tests/regressiontests/m2m_regress/models.py
index 5453d39..8e0b00d 100644
a
|
b
|
class User(models.Model):
|
57 | 57 | name = models.CharField(max_length=30) |
58 | 58 | friends = models.ManyToManyField(auth.User) |
59 | 59 | |
| 60 | # Assigning an integer as the value of an m2m related attribute should not |
| 61 | # clear all relationships. |
| 62 | |
| 63 | class Platform(models.Model): |
| 64 | name = models.CharField(max_length=25) |
| 65 | tags = models.ManyToManyField(Tag) |
| 66 | |
60 | 67 | __test__ = {"regressions": """ |
61 | 68 | # Multiple m2m references to the same model or a different model must be |
62 | 69 | # distinguished when accessing the relations through an instance attribute. |
diff --git a/tests/regressiontests/m2m_regress/tests.py b/tests/regressiontests/m2m_regress/tests.py
new file mode 100644
index 0000000..cb85e47
-
|
+
|
|
| 1 | from django.test import TestCase |
| 2 | |
| 3 | from regressiontests.m2m_regress.models import Platform, Tag |
| 4 | |
| 5 | class M2MAssignmentTests(TestCase): |
| 6 | """ |
| 7 | Assigning nonsense to an m2m attribute shouldn't lose data. |
| 8 | |
| 9 | """ |
| 10 | def setUp(self): |
| 11 | self.platform = Platform.objects.create(name='BSD') |
| 12 | self.platform.tags = [Tag.objects.create(name='Net'), |
| 13 | Tag.objects.create(name='Free')] |
| 14 | |
| 15 | def test_assigning_integer(self): |
| 16 | try: |
| 17 | self.platform.tags = 7 |
| 18 | except TypeError: |
| 19 | pass |
| 20 | else: |
| 21 | self.fail("Assignment of integer to m2m attribute should have raised TypeError") |
| 22 | # ensure we're getting actual data from the database, not anything cached |
| 23 | platform = Platform.objects.get(pk=self.platform.pk) |
| 24 | self.assertEqual(sorted(t.name for t in platform.tags.all()), |
| 25 | ['Free', 'Net']) |