You can now add and remove users for ownership history

This commit is contained in:
Dion Moult
2021-10-01 17:32:58 +10:00
parent fe1e30702a
commit 4697e063af
23 changed files with 336 additions and 27 deletions
+2
View File
@@ -44,6 +44,7 @@ class NewFile:
while bpy.data.objects:
bpy.data.objects.remove(bpy.data.objects[0])
bpy.ops.outliner.orphans_purge(do_local_ids=True, do_linked_ids=True, do_recursive=True)
blenderbim.bim.handler.setDefaultProperties(None)
class NewIfc:
@@ -54,6 +55,7 @@ class NewIfc:
while bpy.data.objects:
bpy.data.objects.remove(bpy.data.objects[0])
bpy.ops.outliner.orphans_purge(do_local_ids=True, do_linked_ids=True, do_recursive=True)
blenderbim.bim.handler.setDefaultProperties(None)
bpy.ops.bim.create_project()
+34 -2
View File
@@ -10,7 +10,7 @@ Scenario: Add person
Scenario: Remove person
Given an empty IFC project
When I press "bim.add_person"
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
And the variable "person" is "{ifc}.by_type('IfcPerson')[-1].id()"
And I press "bim.remove_person(person={person})"
Then nothing happens
@@ -198,6 +198,38 @@ Scenario: Edit organisation
Scenario: Remove organisation
Given an empty IFC project
When I press "bim.add_organisation"
And the variable "organisation" is "{ifc}.by_type('IfcOrganization')[0].id()"
And the variable "organisation" is "{ifc}.by_type('IfcOrganization')[-1].id()"
And I press "bim.remove_organisation(organisation={organisation})"
Then nothing happens
Scenario: Add person and organisation
Given an empty IFC project
When I press "bim.add_person"
And I press "bim.add_organisation"
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
And the variable "organisation" is "{ifc}.by_type('IfcOrganization')[0].id()"
And I press "bim.add_person_and_organisation(person={person}, organisation={organisation})"
Then nothing happens
Scenario: Remove person and organisation
Given an empty IFC project
When I press "bim.add_person"
And I press "bim.add_organisation"
And the variable "person" is "{ifc}.by_type('IfcPerson')[-1].id()"
And the variable "organisation" is "{ifc}.by_type('IfcOrganization')[-1].id()"
And I press "bim.add_person_and_organisation(person={person}, organisation={organisation})"
# Note: these are set to -1 temporarily to prevent crashing due to bug #1747
And the variable "pno" is "{ifc}.by_type('IfcPersonAndOrganization')[-1].id()"
And I press "bim.remove_person_and_organisation(person_and_organisation={pno})"
Then nothing happens
Scenario: Set user
Given an empty IFC project
When I press "bim.add_person"
And I press "bim.add_organisation"
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
And the variable "organisation" is "{ifc}.by_type('IfcOrganization')[0].id()"
And I press "bim.add_person_and_organisation(person={person}, organisation={organisation})"
And the variable "user" is "{ifc}.by_type('IfcPersonAndOrganization')[0].id()"
And I press "bim.set_user(user={user})"
Then nothing happens
+7
View File
@@ -70,6 +70,13 @@ def context_editor():
prophet.verify()
@pytest.fixture
def owner():
prophet = Prophecy(blenderbim.core.tool.Owner)
yield prophet
prophet.verify()
class Prophecy:
def __init__(self, cls):
self.subject = cls
+39 -1
View File
@@ -18,7 +18,7 @@
import blenderbim.core.owner as subject
from test.core.bootstrap import ifc, blender, person_editor, role_editor, address_editor, organisation_editor
from test.core.bootstrap import ifc, blender, person_editor, role_editor, address_editor, organisation_editor, owner
class TestAddPerson:
@@ -181,3 +181,41 @@ class TestEditOrganisation:
ifc.run("owner.edit_organisation", organisation="organisation", attributes="attributes").should_be_called()
organisation_editor.clear_organisation().should_be_called()
subject.edit_organisation(ifc, organisation_editor)
class TestAddPersonAndOrganisation:
def test_run(self, ifc):
ifc.run(
"owner.add_person_and_organisation", person="person", organisation="organisation"
).should_be_called().will_return("person_and_organisation")
assert (
subject.add_person_and_organisation(ifc, person="person", organisation="organisation")
== "person_and_organisation"
)
class TestRemovePersonAndOrganisation:
def test_run(self, ifc, owner):
owner.get_user().should_be_called().will_return("user")
ifc.run(
"owner.remove_person_and_organisation", person_and_organisation="person_and_organisation"
).should_be_called()
subject.remove_person_and_organisation(ifc, owner, person_and_organisation="person_and_organisation")
def test_clearing_the_active_user_if_you_remove_it(self, ifc, owner):
owner.get_user().should_be_called().will_return("user")
owner.clear_user().should_be_called()
ifc.run("owner.remove_person_and_organisation", person_and_organisation="user").should_be_called()
subject.remove_person_and_organisation(ifc, owner, person_and_organisation="user")
class TestSetUser:
def test_run(self, owner):
owner.set_user("person_and_organisation").should_be_called()
subject.set_user(owner, user="person_and_organisation")
class TestGetUser:
def test_run(self, owner):
owner.get_user().should_be_called().will_return("person_and_organisation")
assert subject.get_user(owner) == "person_and_organisation"
+35
View File
@@ -0,0 +1,35 @@
import bpy
import ifcopenshell
import test.bim.bootstrap
import blenderbim.core.tool
import blenderbim.tool as tool
from blenderbim.tool.owner import Owner as subject
class TestImplementsTool(test.bim.bootstrap.NewFile):
def test_run(self):
assert isinstance(subject(), blenderbim.core.tool.owner.Owner)
class TestSetUser(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
user = ifc.createIfcPersonAndOrganization()
subject.set_user(user)
assert bpy.context.scene.BIMOwnerProperties.active_user_id == user.id()
class TestGetUser(test.bim.bootstrap.NewFile):
def test_run(self):
assert subject.get_user() is None
TestSetUser().test_run()
user = tool.Ifc.get().by_type("IfcPersonAndOrganization")[0]
assert subject.get_user() == user
class TestClearUser(test.bim.bootstrap.NewFile):
def test_run(self):
TestSetUser().test_run()
subject.clear_user()
assert bpy.context.scene.BIMOwnerProperties.active_user_id == 0