'Test catalog addition, listing, deletion, and merge.'

def test_changes(self):

    self.db.add_catalog(u'new_cat', vos_catalog.VOSCatalog.create(u'new_cat', u'new_url'))
    self.db.add_catalog_by_url(u'bar', u'bar.foo', allow_duplicate_url=True)
    assert (self.db.list_catalogs() == [u'bar', u'foo', u'new_cat'])
    assert (self.db.list_catalogs(pattern=u'f') == [u'foo'])
    assert (self.db.list_catalogs_by_url() == [u'bar.foo', u'new_url'])
    assert (self.db.list_catalogs_by_url(pattern=u'r.f') == [u'bar.foo'])
    with pytest.raises(DuplicateCatalogName):
        self.db.add_catalog(u'foo', vos_catalog.VOSCatalog.create(u'my_title', u'my_url'))
    with pytest.raises(DuplicateCatalogURL):
        self.db.add_catalog(u'foo3', vos_catalog.VOSCatalog.create(u'foo3', u'bar.foo'))
    self.db.delete_catalog_by_url(u'bar.foo')
    assert (self.db.list_catalogs() == [u'new_cat'])
    assert (self.db.list_catalogs_by_url() == [u'new_url'])
    assert (self.db._url_keys[u'bar.foo'] == [])
    other_db = vos_catalog.VOSDatabase.create_empty()
    other_db.add_catalog(u'o_cat', vos_catalog.VOSCatalog.create(u'o_title', u'o_url'))
    other_db.add_catalog(u'o_cat2', vos_catalog.VOSCatalog.create(u'o_title2', u'o_url2'))
    new_db = self.db.merge(other_db)
    assert (new_db.list_catalogs() == [u'new_cat', u'o_cat', u'o_cat2'])
    assert (new_db.list_catalogs_by_url() == [u'new_url', u'o_url', u'o_url2'])
    assert (self.db.list_catalogs() == [u'new_cat'])
    assert (self.db.list_catalogs_by_url() == [u'new_url'])
    assert (other_db.list_catalogs() == [u'o_cat', u'o_cat2'])
    assert (other_db.list_catalogs_by_url() == [u'o_url', u'o_url2'])
