def setUp(self): self.engine = base.engine('sqlite:///:memory:') self.Session = base.create_sessionmaker(self.engine) base.Base.metadata.create_all(self.engine) all_db_components = {} all_db_components.update(db_components) all_db_components.update(db_room_components) all_components = {} all_components.update(components) all_components.update(room_components) self.component_object = ArrayComponentSource(all_components) self.db_component_object = DBComponentSource( all_db_components, self.Session()) self.comp_manager = ComponentManager( [self.db_component_object, self.component_object]) self.node_factory = NodeFactoryDB(self.comp_manager) starting_room = self.node_factory.create_new_node({"container": {}}) self.avatar_factory = AvatarFactory(self.node_factory, self.comp_manager, data={ "starting_room": starting_room.id, "starting_location": "temp", "player_id": "temp"}) self.account_utils = account.AccountUtils(self.avatar_factory) self.session = self.Session() self.db_component_object.set_session(self.session)
def setup_objects(all_db_components, all_components, session): object_db = DBComponentSource(all_db_components, session) object_array = ArrayComponentSource(all_components) component_manager = ComponentManager([object_array]) db_component_manager = ComponentManager([object_db, object_array]) node_factory = NodeFactoryDB(component_manager) db_node_factory = NodeFactoryDB(db_component_manager) player_factory = PlayerFactory(component_manager) default_room = "6cb2fa80-ddb1-47bb-b980-31b01d97add5" avatar_factory = AvatarFactory(db_node_factory, db_component_manager, { "starting_room": default_room, "player_id": 0 }) account_utils = AccountUtils(avatar_factory) return avatar_factory, node_factory, db_node_factory, object_db, player_factory, account_utils
def __init__(self, Session): all_components = {} all_components.update(components) self.component_object = DBComponentSource(all_components) self.comp_manager = ComponentManager([self.component_object], Session) self.node_factory = NodeFactoryDB(all_components, Session)
def setUp(self): self.engine = base.engine('sqlite://', echo=True) self.Session = base.create_sessionmaker(self.engine) base.Base.metadata.create_all(self.engine) all_db_components = {} all_db_components.update(db_components) all_db_components.update(db_room_components) all_components = {} all_components.update(components) all_components.update(room_components) self.array_component = ArrayComponentSource(all_components) self.component_object = DBComponentSource(all_db_components) self.comp_manager = ComponentManager( [self.component_object, self.array_component]) self.node_factory = NodeFactoryDB(self.comp_manager) self.session = self.Session() self.component_object.set_session(self.session) self.chair1 = self.comp_manager.create_entity({ "names": {"name": "chair1"}, "type": {"type": "chair1"}, "network_messages": None }) self.chair2 = self.comp_manager.create_entity({ "names": {"name": "chair1"}, "type": {"type": "chair1"}, "creating": {'new_name': 'foo', 'format': 'bar'} }) self.chair3 = self.comp_manager.create_entity({ "names": {"name": "chair1"}, "type": {"type": "chair1"}, "network_messages": None }) room_factory = RoomFactory(self.comp_manager) self.test_room = room_factory.create_room("test", 0, 20, 20, 20) self.session.commit()
class Test(unittest.TestCase): def setUp(self): self.engine = base.engine('sqlite:///:memory:') self.Session = base.create_sessionmaker(self.engine) base.Base.metadata.create_all(self.engine) all_db_components = {} all_db_components.update(db_components) all_db_components.update(db_room_components) all_components = {} all_components.update(components) all_components.update(room_components) self.component_object = ArrayComponentSource(all_components) self.db_component_object = DBComponentSource( all_db_components, self.Session()) self.comp_manager = ComponentManager( [self.db_component_object, self.component_object]) self.node_factory = NodeFactoryDB(self.comp_manager) starting_room = self.node_factory.create_new_node({"container": {}}) self.avatar_factory = AvatarFactory(self.node_factory, self.comp_manager, data={ "starting_room": starting_room.id, "starting_location": "temp", "player_id": "temp"}) self.account_utils = account.AccountUtils(self.avatar_factory) self.session = self.Session() self.db_component_object.set_session(self.session) def tearDown(self): self.session.commit() self.session.close() base.Base.metadata.drop_all(self.engine) pass def testCreate(self): session = self.Session() self.account_utils.make_account( "foo", "bar", "*****@*****.**", session) session.close() def testCreateAvatar(self): session = self.Session() acc = self.account_utils.make_account( "test", "test1", "*****@*****.**", session) data = {} self.account_utils.create_new_avatar_for_account(acc.id, data, session) self.account_utils.create_new_avatar_for_account(acc.id, data, session) session.add(acc) for assoc in acc.avatars: print(assoc.avatar.id) session.close() def testGetAvatar(self): session = self.Session() acc = self.account_utils.make_account( "test", "test2", "*****@*****.**", session) self.account_utils.create_new_avatar_for_account(acc.id, {}, session) self.account_utils.create_new_avatar_for_account(acc.id, {}, session) print(self.account_utils.get_avatars_for_account(acc, session)) session.close()
def setUp(self): self.components = { "test_component0": TestComponent0, "test_component1": TestComponent1, "test_component2": TestComponent2, "test_component3": TestComponent3, "test_component4": TestComponent4, "test_component5": TestComponent5, } self.component_source = ArrayComponentSource(self.components) self.component_manager = ComponentManager([self.component_source]) # all components self.test_entity1 = self.component_manager.create_entity({ "test_component0": { "some_string": "E1C0" }, "test_component1": { "some_string": "E1C1" }, "test_component2": { "some_string": "E1C2" }, "test_component3": { "some_string": "E1C3" }, "test_component4": { "some_string": "E1C4" }, }) # no components self.test_entity2 = self.component_manager.create_entity({}) # even components self.test_entity3 = self.component_manager.create_entity({ "test_component0": { "some_string": "E3C0" }, "test_component2": { "some_string": "E3C2" }, "test_component4": { "some_string": "E3C4" }, }) # odd components self.test_entity4 = self.component_manager.create_entity({ "test_component1": { "some_string": "E4C1" }, "test_component3": { "some_string": "E4C3" }, }) # copy of entity1 to make sure that they stay distinct self.test_entity5 = self.component_manager.create_entity({ "test_component0": { "some_string": "E5C0" }, "test_component1": { "some_string": "E5C1" }, "test_component2": { "some_string": "E5C2" }, "test_component3": { "some_string": "E5C3" }, "test_component4": { "some_string": "E5C4" }, }) self.node_factory = NodeFactoryDB(self.component_manager)
class Test(unittest.TestCase): def setUp(self): self.components = { "test_component0": TestComponent0, "test_component1": TestComponent1, "test_component2": TestComponent2, "test_component3": TestComponent3, "test_component4": TestComponent4, "test_component5": TestComponent5, } self.component_source = ArrayComponentSource(self.components) self.component_manager = ComponentManager([self.component_source]) # all components self.test_entity1 = self.component_manager.create_entity({ "test_component0": { "some_string": "E1C0" }, "test_component1": { "some_string": "E1C1" }, "test_component2": { "some_string": "E1C2" }, "test_component3": { "some_string": "E1C3" }, "test_component4": { "some_string": "E1C4" }, }) # no components self.test_entity2 = self.component_manager.create_entity({}) # even components self.test_entity3 = self.component_manager.create_entity({ "test_component0": { "some_string": "E3C0" }, "test_component2": { "some_string": "E3C2" }, "test_component4": { "some_string": "E3C4" }, }) # odd components self.test_entity4 = self.component_manager.create_entity({ "test_component1": { "some_string": "E4C1" }, "test_component3": { "some_string": "E4C3" }, }) # copy of entity1 to make sure that they stay distinct self.test_entity5 = self.component_manager.create_entity({ "test_component0": { "some_string": "E5C0" }, "test_component1": { "some_string": "E5C1" }, "test_component2": { "some_string": "E5C2" }, "test_component3": { "some_string": "E5C3" }, "test_component4": { "some_string": "E5C4" }, }) self.node_factory = NodeFactoryDB(self.component_manager) def tearDown(self): pass def testCreateNodesOneComponent(self): node_list = self.node_factory.create_node_list(["test_component2"]) # We got the right number of nodes self.assertEqual(len(node_list), 3) # And node 2 isn't in it id_list = [node.id for node in node_list] self.assertFalse(self.test_entity2.id in id_list) # And neither is 4 self.assertFalse(self.test_entity4.id in id_list) # But 5 is self.assertTrue(self.test_entity5.id in id_list) for node in node_list: # And it has the right component objects self.assertTrue(node.test_component2) # But not any of the others with self.assertRaises(AttributeError): print(node.test_component1) print(node.test_component3) print(node.test_component4) print(node.test_component5) def testCreateNodesTwoComponents(self): node_list = self.node_factory.create_node_list( ["test_component0", "test_component1"]) # We got the right number of nodes # Only 1 and 5 should pass self.assertEqual(len(node_list), 2) # And node 2 isn't in it id_list = [node.id for node in node_list] self.assertFalse(self.test_entity2.id in id_list) # And neither is 3 or 4 self.assertFalse(self.test_entity3.id in id_list) self.assertFalse(self.test_entity4.id in id_list) # But 1 and 5 are self.assertTrue(self.test_entity1.id in id_list) self.assertTrue(self.test_entity5.id in id_list) # And they have the right component objects for node in node_list: self.assertIsNotNone(node.test_component0) self.assertIsNotNone(node.test_component1) # But not any of the others with self.assertRaises(AttributeError): print(node.test_component2) print(node.test_component3) print(node.test_component4) def testComponentNotExists(self): with self.assertRaises(AttributeError): self.node_factory.create_node_list(["test_component6"]) def testComponentNotOnAnyEntity(self): node_list = self.node_factory.create_node_list(["test_component5"]) self.assertEqual([], node_list) def test_optional_component(self): node_list = self.node_factory.create_node_list( ["test_component1", "test_component3"], optional=["test_component2"]) # We got the right number of nodes # Only 1 and 5 should pass self.assertEqual(len(node_list), 3) # And node 2, 3 isn't in it id_list = [node.id for node in node_list] self.assertFalse(self.test_entity2.id in id_list) self.assertFalse(self.test_entity3.id in id_list) # But 1, 4 and 5 are self.assertTrue(self.test_entity1.id in id_list) self.assertTrue(self.test_entity5.id in id_list) self.assertTrue(self.test_entity4.id in id_list) # And they have the right component objects for node in node_list: self.assertIsNotNone(node.test_component1) self.assertIsNotNone(node.test_component3) # But not any of the others with self.assertRaises(AttributeError): print(node.test_component0) print(node.test_component4) # Get all of the nodes with optional component test_component_2 id_list_2 = [node.id for node in node_list.subset(["test_component2"])] print(id_list_2) # 1 and 5 qualify but 4 doesn't self.assertTrue(self.test_entity1.id in id_list_2) self.assertTrue(self.test_entity5.id in id_list_2) self.assertFalse(self.test_entity4.id in id_list_2) def testOptional(self): names = self.node_factory.create_node_list( ["test_component2"], optional=["test_component1"]) print(names) self.assertEqual(len(names), 3) self.assertEqual(len(names.subset(["test_component1"])), 2)
class Test(unittest.TestCase): def setUp(self): self.engine = base.engine('sqlite://', echo=True) self.Session = base.create_sessionmaker(self.engine) base.Base.metadata.create_all(self.engine) all_db_components = {} all_db_components.update(db_components) all_db_components.update(db_room_components) all_components = {} all_components.update(components) all_components.update(room_components) self.array_component = ArrayComponentSource(all_components) self.component_object = DBComponentSource(all_db_components) self.comp_manager = ComponentManager( [self.component_object, self.array_component]) self.node_factory = NodeFactoryDB(self.comp_manager) self.session = self.Session() self.component_object.set_session(self.session) self.chair1 = self.comp_manager.create_entity({ "names": {"name": "chair1"}, "type": {"type": "chair1"}, "network_messages": None }) self.chair2 = self.comp_manager.create_entity({ "names": {"name": "chair1"}, "type": {"type": "chair1"}, "creating": {'new_name': 'foo', 'format': 'bar'} }) self.chair3 = self.comp_manager.create_entity({ "names": {"name": "chair1"}, "type": {"type": "chair1"}, "network_messages": None }) room_factory = RoomFactory(self.comp_manager) self.test_room = room_factory.create_room("test", 0, 20, 20, 20) self.session.commit() def tearDown(self): self.session.commit() self.session.close() base.Base.metadata.drop_all(self.engine) pass def testCreate(self): names = self.node_factory.create_node_list(["names"]) print(names) self.assertEqual(len(names), 4) names = self.node_factory.create_node_list(["names", "creating"]) self.assertEqual(len(names), 1) print(names) def testRoom(self): print("------------TEST ROOM--------------") room = self.node_factory.create_node(self.test_room, ["names"]) print(room.names.name) self.assertEqual(room.names.name, "test") print("--------END TEST ROOM--------------") def testOptional(self): names = self.node_factory.create_node_list( ["names"], optional=["creating"]) print(names) self.assertEqual(len(names), 4) self.assertEqual(len(names.subset(["creating"])), 1)