Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    def setUp(self):
        self.engine = base.engine('sqlite://', echo=False)
        self.Session = base.create_sessionmaker(self.engine)
        base.Base.metadata.create_all(self.engine)

        all_components = {}
        all_components.update(db_components)
        all_components.update(db_room_components)

        self.component_object = DBComponentSource(all_components)
        self.component_manager = ComponentManager([self.component_object])
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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()
Exemplo n.º 5
0
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
Exemplo n.º 6
0
class Test(unittest.TestCase):
    def setUp(self):
        self.engine = base.engine('sqlite://', echo=False)
        self.Session = base.create_sessionmaker(self.engine)
        base.Base.metadata.create_all(self.engine)

        all_components = {}
        all_components.update(db_components)
        all_components.update(db_room_components)

        self.component_object = DBComponentSource(all_components)
        self.component_manager = ComponentManager([self.component_object])

    def tearDown(self):
        base.Base.metadata.drop_all(self.engine)
        pass

    def testCreateDBtable(self):
        session = self.Session()
        self.component_object.set_session(session)

        e = self.component_manager.create_entity({})
        self.component_manager.add_component_to_object("location", e.id, None)

        session.commit()
        session.close()

    def testGetComponent(self):
        session = self.Session()
        self.component_object.set_session(session)
        e = self.component_manager.create_entity({})
        self.component_manager.add_component_to_object("temperature", e.id,
                                                       {"temperature": 50})

        temperature = self.component_manager.get_component(e.id, "temperature")
        self.assertEqual(temperature.temperature, 50)
        session.commit()
        session.close()

    def testGetEntitiesForComponent(self):
        session = self.Session()
        self.component_object.set_session(session)
        e = self.component_manager.create_entity({})
        self.component_manager.add_component_to_object("temperature", e.id,
                                                       {"temperature": 50})

        entities = self.component_manager.get_entities_for_component(
            "temperature")
        print(entities)
        self.assertEqual(entities[0], e.id)

        session.commit()
        session.close()
Exemplo n.º 7
0
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()
Exemplo n.º 8
0
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)