def test_assign_unsets_other_sides_single_to_multiple_link(self): article1 = LinkedArticle(name='A1') article2 = LinkedArticle(name='A2') author = LinkedAuthor(name='Author', articles=[article1]) article2.author = author article2.author = None self.assertEqual(article2.author, None) self.assertEqual(author.articles, [article1]) self.assertEqual(article2._unlinked_objects['author'], [author]) self.assertEqual(author._unlinked_objects['articles'], [article2]) article1 = LinkedArticle(name='A1') article2 = LinkedArticle(name='A2') author = LinkedAuthor(name='Author') author.articles = [article1, article2] author.articles = [] self.assertEqual(article1.author, None) self.assertEqual(article2.author, None) self.assertEqual(author.articles, []) self.assertEqual(article1._unlinked_objects['author'], [author]) self.assertEqual(article2._unlinked_objects['author'], [author]) self.assertEqual(author._unlinked_objects['articles'], [article1, article2])
def test_assign_sets_other_sides_single_to_multiple_link(self): article1 = LinkedArticle(name='A1') article2 = LinkedArticle(name='A2') author = LinkedAuthor(name='Author', articles=[article1]) article2.author = author self.assertEqual(article2.author, author) self.assertEqual(author.articles, [article1, article2]) article1 = LinkedArticle(name='A1') article2 = LinkedArticle(name='A2') author = LinkedAuthor(name='Author') author.articles = [article1, article2] self.assertEqual(article1.author, author) self.assertEqual(article2.author, author) self.assertEqual(author.articles, [article1, article2])