From 6aff90c1bab96163db06b75a4fdefa47714ed585 Mon Sep 17 00:00:00 2001
From: Luke Plant <L.Plant.98@cantab.net>
Date: Sat, 4 Feb 2006 18:28:12 +0000
Subject: [PATCH] magic-removal: Added (failing) tests for m2m .add() (the
 'other' end) and m2m .remove() and .clear()

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2267 bcc190cf-cafb-0310-a4f2-bffc1f526a37
---
 tests/modeltests/many_to_many/models.py | 57 +++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/tests/modeltests/many_to_many/models.py b/tests/modeltests/many_to_many/models.py
index 064cea176e..ef1bf8d4cc 100644
--- a/tests/modeltests/many_to_many/models.py
+++ b/tests/modeltests/many_to_many/models.py
@@ -103,4 +103,61 @@ API_TESTS = """
 [Django lets you build Web apps easily]
 >>> p1.article_set.order_by('headline')
 [Django lets you build Web apps easily]
+
+# Adding via the 'other' end of an m2m
+>>> a4 = Article(headline='NASA finds intelligent life on Earth')
+>>> a4.save()
+>>> p2.article_set.add(a4)
+>>> p2.article_set.all()
+[NASA finds intelligent life on Earth]
+>>> a4.publications.all()
+[Science News]
+
+# Adding via the other end using keywords
+>>> a5 = p1.article_set.add(headline='Oxygen-free diet works wonders')
+>>> p2.article_set.all().order_by('headline')
+[NASA finds intelligent life on Earth, Oxygen-free diet works wonders]
+>>> a5.publications.all()
+[Science News]
+
+# Removing publication from an article:
+>>> a4.publications.remove(p2)
+>>> p2.article_set.all().order_by('headline')
+[Oxygen-free diet works wonders]
+>>> a4.publications.all()
+[]
+
+# And from the other end
+>>> p2.article_set.remove(a5)
+>>> p2.article_set.order_by('headline')
+[]
+>>> a5.publications.all()
+[]
+
+# You can clear the whole lot:
+# (put some back first)
+>>> p2.article_set.add(a4, a5)
+>>> a4.publications.add(p3)
+>>> a4.publications.order_by('title')
+[Science News, Science Weekly]
+>>> p2.article_set.clear()
+>>> p2.article_set.all()
+[]
+>>> a4.publications.all()
+[Science Weekly]
+
+# And you can clear from the other end
+>>> p2.article_set.add(a4, a5)
+>>> p2.article_set.all().order_by('headline')
+[NASA finds intelligent life on Earth, Oxygen-free diet works wonders]
+>>> a4.publications.order_by('title')
+[Science News, Science Weekly]
+>>> a4.publications.clear()
+>>> a4.publications.all()
+[]
+>>> p2.article_set.all().order_by('headline')
+[Oxygen-free diet works wonders]
+
+
+
 """