def test_destroy_stored_object(): d = Database() o1 = d.create_object() o2 = d.create_object() p = o1.add_property('prop', d.object_class, o2) def inner(): """Actually perform the testing.""" with raises(IsValueError) as exc: d.destroy_object(o2) obj, prop = exc.value.args assert obj is o1 assert prop is p inner() p.type = list p.set([1, 2, o2]) inner() p.type = dict p.set(dict(obj=o2)) inner() p.set(dict(objects=[o1, o2])) inner() p.value = None d.destroy_object(o2) assert o2.id not in d.objects
def test_destroy_object_registered(): d = Database() first = d.create_object() d.register_object('first', first) with raises(ObjectRegisteredError): d.destroy_object(first) assert d.first is first assert d.objects == {first.id: first}
def test_destroy_object(): db = Database() o = db.create_object() db.destroy_object(o) assert db.objects == {} o1 = db.create_object() o2 = db.create_object() db.destroy_object(o2) assert o1.id == 1 assert db.objects == {1: o1} assert db.max_id == 3
def test_destroy_object_with_children(): d = Database() parent = d.create_object() d.create_object(parent) d.create_object(parent) with raises(HasChildrenError) as exc: d.destroy_object(parent) assert exc.value.args[0]is parent for obj in parent.children: obj.remove_parent(parent) d.destroy_object(parent) assert parent.id not in d.objects
def test_destroy_object_with_contents(): d = Database() room = d.create_object() obj_1 = d.create_object() obj_1.location = room obj_2 = d.create_object() obj_2.location = room with raises(HasContentsError) as exc: d.destroy_object(room) assert exc.value.args[0] is room for obj in room.contents: obj.location = None d.destroy_object(room) assert room.id not in d.objects
def test_destroy_object_with_parents(): d = Database() g = d.create_object() p = d.create_object(g) # I know we've done these inheritence tests elsewhere, I just feel more # secure knowing they're in two separate places. assert g.children == [p] assert p.parents == [g] c = d.create_object(p) assert c.parents == [p] assert p.children == [c] d.destroy_object(c) assert not p.children assert g.children == [p]