mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-17 19:09:07 +00:00
Removing a person no longer has the potential to leave files in an invalid state
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class TestRemovePerson(test.bootstrap.IFC4):
|
||||
def test_removing_a_person(self):
|
||||
person = self.file.createIfcPerson()
|
||||
ifcopenshell.api.run("owner.remove_person", self.file, person=person)
|
||||
assert len(self.file.by_type("IfcPerson")) == 0
|
||||
|
||||
def test_removing_roles_and_addresses_only_used_by_the_person(self):
|
||||
role = self.file.createIfcActorRole()
|
||||
address = self.file.createIfcPostalAddress()
|
||||
person = self.file.createIfcPerson()
|
||||
person.Roles = [role]
|
||||
person.Addresses = [address]
|
||||
ifcopenshell.api.run("owner.remove_person", self.file, person=person)
|
||||
assert len(self.file.by_type("IfcPerson")) == 0
|
||||
assert len(self.file.by_type("IfcActorRole")) == 0
|
||||
assert len(self.file.by_type("IfcPostalAddress")) == 0
|
||||
|
||||
def test_not_removing_roles_and_addresses_used_elsewhere(self):
|
||||
role = self.file.createIfcActorRole()
|
||||
address = self.file.createIfcPostalAddress()
|
||||
person = self.file.createIfcPerson()
|
||||
person2 = self.file.createIfcPerson()
|
||||
person.Roles = [role]
|
||||
person.Addresses = [address]
|
||||
person2.Roles = [role]
|
||||
person2.Addresses = [address]
|
||||
ifcopenshell.api.run("owner.remove_person", self.file, person=person)
|
||||
assert len(self.file.by_type("IfcPerson")) == 1
|
||||
assert len(self.file.by_type("IfcActorRole")) == 1
|
||||
assert len(self.file.by_type("IfcPostalAddress")) == 1
|
||||
|
||||
def test_ensuring_work_controls_should_not_be_left_in_an_invalid_set_cardinality(self):
|
||||
person = self.file.createIfcPerson()
|
||||
work_control = self.file.createIfcWorkControl(Creators=[person])
|
||||
ifcopenshell.api.run("owner.remove_person", self.file, person=person)
|
||||
assert work_control.Creators is None
|
||||
|
||||
def test_ensuring_inventory_should_not_be_left_in_an_invalid_set_cardinality(self):
|
||||
person = self.file.createIfcPerson()
|
||||
inventory = self.file.createIfcInventory(ResponsiblePersons=[person])
|
||||
ifcopenshell.api.run("owner.remove_person", self.file, person=person)
|
||||
assert inventory.ResponsiblePersons is None
|
||||
|
||||
def test_deleting_person_and_organisations(self):
|
||||
person = self.file.createIfcPerson()
|
||||
self.file.createIfcPersonAndOrganization(ThePerson=person)
|
||||
ifcopenshell.api.run("owner.remove_person", self.file, person=person)
|
||||
assert len(self.file.by_type("IfcPersonAndOrganization")) == 0
|
||||
|
||||
def test_deleting_actors(self):
|
||||
person = self.file.createIfcPerson()
|
||||
self.file.createIfcActor(GlobalId=ifcopenshell.guid.new(), TheActor=person)
|
||||
ifcopenshell.api.run("owner.remove_person", self.file, person=person)
|
||||
assert len(self.file.by_type("IfcActor")) == 0
|
||||
|
||||
def test_ensuring_document_information_should_not_be_left_in_an_invalid_set_cardinality(self):
|
||||
person = self.file.createIfcPerson()
|
||||
document_information = self.file.createIfcDocumentInformation(Editors=[person])
|
||||
ifcopenshell.api.run("owner.remove_person", self.file, person=person)
|
||||
assert document_information.Editors is None
|
||||
|
||||
def test_deleting_resource_approval_relationships(self):
|
||||
person = self.file.createIfcPerson()
|
||||
self.file.createIfcResourceApprovalRelationship(RelatedResourceObjects=[person])
|
||||
ifcopenshell.api.run("owner.remove_person", self.file, person=person)
|
||||
assert len(self.file.by_type("IfcResourceApprovalRelationship")) == 0
|
||||
|
||||
def test_deleting_resource_constraint_relationships(self):
|
||||
person = self.file.createIfcPerson()
|
||||
self.file.createIfcResourceConstraintRelationship(RelatedResourceObjects=[person])
|
||||
ifcopenshell.api.run("owner.remove_person", self.file, person=person)
|
||||
assert len(self.file.by_type("IfcResourceConstraintRelationship")) == 0
|
||||
|
||||
def test_deleting_external_reference_relationships(self):
|
||||
person = self.file.createIfcPerson()
|
||||
self.file.createIfcExternalReferenceRelationship(RelatedResourceObjects=[person])
|
||||
ifcopenshell.api.run("owner.remove_person", self.file, person=person)
|
||||
assert len(self.file.by_type("IfcExternalReferenceRelationship")) == 0
|
||||
Reference in New Issue
Block a user