'Test that the m2m_changed signal has a correct database arg (#13552)'

def test_database_arg_m2m(self):

    receiver = DatabaseReceiver()
    signals.m2m_changed.connect(receiver=receiver)
    b = Book.objects.create(title='Pro    Django', published=datetime.date(2008, 12, 16))
    p = Person.objects.create(name='Marty    Alchin')
    b.authors.add(p)
    self.assertEqual(receiver._database, DEFAULT_DB_ALIAS)
    self._write_to_other()
    b.authors.add(p)
    self._write_to_default()
    self.assertEqual(receiver._database, 'other')
    b.authors.remove(p)
    self.assertEqual(receiver._database, DEFAULT_DB_ALIAS)
    self._write_to_other()
    b.authors.remove(p)
    self._write_to_default()
    self.assertEqual(receiver._database, 'other')
    p.book_set.add(b)
    self.assertEqual(receiver._database, DEFAULT_DB_ALIAS)
    self._write_to_other()
    p.book_set.add(b)
    self._write_to_default()
    self.assertEqual(receiver._database, 'other')
    b.authors.clear()
    self.assertEqual(receiver._database, DEFAULT_DB_ALIAS)
    self._write_to_other()
    b.authors.clear()
    self._write_to_default()
    self.assertEqual(receiver._database, 'other')
