Пример #1
0
    def test_spawn(self):
        def getObject(commandTest, objKeyStr):
            # A helper function to get a spawned object and
            # check that it exists in the process.
            query = search_object(objKeyStr)
            commandTest.assertIsNotNone(query)
            obj = query[0]
            commandTest.assertIsNotNone(obj)
            return obj

        # Tests "@spawn" without any arguments.
        self.call(building.CmdSpawn(), " ", "Usage: @spawn")

        # Tests "@spawn <prototype_dictionary>" without specifying location.
        self.call(building.CmdSpawn(), \
                  "{'key':'goblin', 'typeclass':'evennia.DefaultCharacter'}", "Spawned goblin")
        goblin = getObject(self, "goblin")

        # Tests that the spawned object's type is a DefaultCharacter.
        self.assertIsInstance(goblin, DefaultCharacter)

        # Tests that the spawned object's location is the same as the caharacter's location, since
        # we did not specify it.
        self.assertEqual(goblin.location, self.char1.location)
        goblin.delete()

        # Test "@spawn <prototype_dictionary>" with a location other than the character's.
        spawnLoc = self.room2
        if spawnLoc == self.char1.location:
            # Just to make sure we use a different location, in case someone changes
            # char1's default location in the future...
            spawnLoc = self.room1

        self.call(building.CmdSpawn(), \
                  "{'prototype':'GOBLIN', 'key':'goblin', 'location':'%s'}" \
                  % spawnLoc.dbref, "Spawned goblin")
        goblin = getObject(self, "goblin")
        self.assertEqual(goblin.location, spawnLoc)
        goblin.delete()

        # Tests "@spawn <prototype_name>"
        self.call(building.CmdSpawn(), "'BALL'", "Spawned Ball")
        ball = getObject(self, "Ball")
        self.assertEqual(ball.location, self.char1.location)
        self.assertIsInstance(ball, DefaultObject)
        ball.delete()

        # Tests "@spawn/noloc ..." without specifying a location.
        # Location should be "None".
        self.call(building.CmdSpawn(), "/noloc 'BALL'", "Spawned Ball")
        ball = getObject(self, "Ball")
        self.assertIsNone(ball.location)
        ball.delete()

        # Tests "@spawn/noloc ...", but DO specify a location.
        # Location should be the specified location.
        self.call(building.CmdSpawn(),  \
                  "/noloc {'prototype':'BALL', 'location':'%s'}" \
                  % spawnLoc.dbref, "Spawned Ball")
        ball = getObject(self, "Ball")
        self.assertEqual(ball.location, spawnLoc)
        ball.delete()

        # test calling spawn with an invalid prototype.
        self.call(building.CmdSpawn(), \
                  "'NO_EXIST'", "No prototype named 'NO_EXIST'")
Пример #2
0
    def test_spawn(self):
        def getObject(commandTest, objKeyStr):
            # A helper function to get a spawned object and
            # check that it exists in the process.
            query = search_object(objKeyStr)
            commandTest.assertIsNotNone(query)
            commandTest.assertTrue(bool(query))
            obj = query[0]
            commandTest.assertIsNotNone(obj)
            return obj

        # Tests "spawn" without any arguments.
        self.call(building.CmdSpawn(), " ", "Usage: spawn")

        # Tests "spawn <prototype_dictionary>" without specifying location.

        self.call(
            building.CmdSpawn(),
            "/save {'prototype_key': 'testprot', 'key':'Test Char', "
            "'typeclass':'evennia.objects.objects.DefaultCharacter'}",
            "Saved prototype: testprot",
            inputs=["y"],
        )

        self.call(building.CmdSpawn(), "/search ", "Key ")
        self.call(building.CmdSpawn(), "/search test;test2", "")

        self.call(
            building.CmdSpawn(),
            "/save {'key':'Test Char', "
            "'typeclass':'evennia.objects.objects.DefaultCharacter'}",
            "To save a prototype it must have the 'prototype_key' set.",
        )

        self.call(building.CmdSpawn(), "/list", "Key ")

        self.call(building.CmdSpawn(), "testprot", "Spawned Test Char")
        # Tests that the spawned object's location is the same as the caharacter's location, since
        # we did not specify it.
        testchar = getObject(self, "Test Char")
        self.assertEqual(testchar.location, self.char1.location)
        testchar.delete()

        # Test "spawn <prototype_dictionary>" with a location other than the character's.
        spawnLoc = self.room2
        if spawnLoc == self.char1.location:
            # Just to make sure we use a different location, in case someone changes
            # char1's default location in the future...
            spawnLoc = self.room1

        self.call(
            building.CmdSpawn(),
            "{'prototype_key':'GOBLIN', 'typeclass':'evennia.objects.objects.DefaultCharacter', "
            "'key':'goblin', 'location':'%s'}" % spawnLoc.dbref,
            "Spawned goblin",
        )
        goblin = getObject(self, "goblin")
        # Tests that the spawned object's type is a DefaultCharacter.
        self.assertIsInstance(goblin, DefaultCharacter)
        self.assertEqual(goblin.location, spawnLoc)

        goblin.delete()

        # create prototype
        protlib.create_prototype({
            "key": "Ball",
            "typeclass": "evennia.objects.objects.DefaultCharacter",
            "prototype_key": "testball",
        })

        # Tests "spawn <prototype_name>"
        self.call(building.CmdSpawn(), "testball", "Spawned Ball")

        ball = getObject(self, "Ball")
        self.assertEqual(ball.location, self.char1.location)
        self.assertIsInstance(ball, DefaultObject)
        ball.delete()

        # Tests "spawn/n ..." without specifying a location.
        # Location should be "None".
        self.call(building.CmdSpawn(), "/n 'BALL'",
                  "Spawned Ball")  # /n switch is abbreviated form of /noloc
        ball = getObject(self, "Ball")
        self.assertIsNone(ball.location)
        ball.delete()

        self.call(
            building.CmdSpawn(),
            "/noloc {'prototype_parent':'TESTBALL', 'prototype_key': 'testball', 'location':'%s'}"
            % spawnLoc.dbref,
            "Error: Prototype testball tries to parent itself.",
        )

        # Tests "spawn/noloc ...", but DO specify a location.
        # Location should be the specified location.
        self.call(
            building.CmdSpawn(),
            "/noloc {'prototype_parent':'TESTBALL', 'key': 'Ball', 'prototype_key': 'foo', 'location':'%s'}"
            % spawnLoc.dbref,
            "Spawned Ball",
        )
        ball = getObject(self, "Ball")
        self.assertEqual(ball.location, spawnLoc)
        ball.delete()

        # test calling spawn with an invalid prototype.
        self.call(building.CmdSpawn(), "'NO_EXIST'",
                  "No prototype named 'NO_EXIST'")

        # Test listing commands
        self.call(building.CmdSpawn(), "/list", "Key ")

        # spawn/edit (missing prototype)
        # brings up olc menu
        msg = self.call(building.CmdSpawn(), "/edit")
        assert "Prototype wizard" in msg

        # spawn/edit with valid prototype
        # brings up olc menu loaded with prototype
        msg = self.call(building.CmdSpawn(), "/edit testball")
        assert "Prototype wizard" in msg
        assert hasattr(self.char1.ndb._menutree, "olc_prototype")
        assert (dict == type(self.char1.ndb._menutree.olc_prototype)
                and "prototype_key" in self.char1.ndb._menutree.olc_prototype
                and "key" in self.char1.ndb._menutree.olc_prototype
                and "testball"
                == self.char1.ndb._menutree.olc_prototype["prototype_key"]
                and "Ball" == self.char1.ndb._menutree.olc_prototype["key"])
        assert "Ball" in msg and "testball" in msg

        # spawn/edit with valid prototype (synomym)
        msg = self.call(building.CmdSpawn(), "/edit BALL")
        assert "Prototype wizard" in msg
        assert "Ball" in msg and "testball" in msg

        # spawn/edit with invalid prototype
        msg = self.call(building.CmdSpawn(), "/edit NO_EXISTS",
                        "No prototype 'NO_EXISTS' was found.")

        # spawn/examine (missing prototype)
        # lists all prototypes that exist
        msg = self.call(building.CmdSpawn(), "/examine")
        assert "testball" in msg and "testprot" in msg

        # spawn/examine with valid prototype
        # prints the prototype
        msg = self.call(building.CmdSpawn(), "/examine BALL")
        assert "Ball" in msg and "testball" in msg

        # spawn/examine with invalid prototype
        # shows error
        self.call(building.CmdSpawn(), "/examine NO_EXISTS",
                  "No prototype 'NO_EXISTS' was found.")
Пример #3
0
    def at_cmdset_creation(self):
        "Populates the cmdset"

        # The general commands
        self.add(general.CmdLook())
        self.add(general.CmdMove())
        # self.add(general.CmdHome())
        self.add(general.CmdInventory())
        # self.add(general.CmdPose())
        # self.add(general.CmdNick())
        # self.add(general.CmdSetDesc())
        self.add(general.CmdGet())
        self.add(general.CmdDrop())
        # self.add(general.CmdGive())
        # self.add(general.CmdSay())
        # self.add(general.CmdWhisper())
        # self.add(general.CmdAccess())

        # The help system
        self.add(help.CmdHelp())
        self.add(help.CmdSetHelp())

        # System commands
        self.add(system.CmdPy())
        self.add(system.CmdScripts())
        self.add(system.CmdObjects())
        self.add(system.CmdAccounts())
        self.add(system.CmdService())
        self.add(system.CmdAbout())
        self.add(system.CmdTime())
        self.add(system.CmdServerLoad())
        # self.add(system.CmdPs())
        self.add(system.CmdTickers())

        # Admin commands
        self.add(admin.CmdBoot())
        self.add(admin.CmdBan())
        self.add(admin.CmdUnban())
        self.add(admin.CmdEmit())
        self.add(admin.CmdPerm())
        self.add(admin.CmdWall())
        self.add(admin.CmdForce())

        # Building and world manipulation
        self.add(building.CmdTeleport())
        self.add(building.CmdSetObjAlias())
        self.add(building.CmdListCmdSets())
        self.add(building.CmdWipe())
        self.add(building.CmdSetAttribute())
        self.add(building.CmdName())
        self.add(building.CmdDesc())
        self.add(building.CmdCpAttr())
        self.add(building.CmdMvAttr())
        self.add(building.CmdCopy())
        self.add(building.CmdFind())
        self.add(building.CmdOpen())
        self.add(building.CmdLink())
        self.add(building.CmdUnLink())
        self.add(building.CmdCreate())
        self.add(building.CmdDig())
        self.add(building.CmdTunnel())
        self.add(building.CmdDestroy())
        self.add(building.CmdExamine())
        self.add(building.CmdTypeclass())
        self.add(building.CmdLock())
        self.add(building.CmdScript())
        self.add(building.CmdSetHome())
        self.add(building.CmdTag())
        self.add(building.CmdSpawn())

        # Batchprocessor commands
        self.add(batchprocess.CmdBatchCommands())
        self.add(batchprocess.CmdBatchCode())
Пример #4
0
    def test_spawn(self):
        def getObject(commandTest, objKeyStr):
            # A helper function to get a spawned object and
            # check that it exists in the process.
            query = search_object(objKeyStr)
            commandTest.assertIsNotNone(query)
            commandTest.assertTrue(bool(query))
            obj = query[0]
            commandTest.assertIsNotNone(obj)
            return obj

        # Tests "@spawn" without any arguments.
        self.call(building.CmdSpawn(), " ", "Usage: @spawn")

        # Tests "@spawn <prototype_dictionary>" without specifying location.

        self.call(building.CmdSpawn(),
                  "/save {'prototype_key': 'testprot', 'key':'Test Char', "
                  "'typeclass':'evennia.objects.objects.DefaultCharacter'}",
                  "Saved prototype: testprot",
                  inputs=['y'])

        self.call(building.CmdSpawn(), "/list", "Key ")

        self.call(building.CmdSpawn(), 'testprot', "Spawned Test Char")
        # Tests that the spawned object's location is the same as the caharacter's location, since
        # we did not specify it.
        testchar = getObject(self, "Test Char")
        self.assertEqual(testchar.location, self.char1.location)
        testchar.delete()

        # Test "@spawn <prototype_dictionary>" with a location other than the character's.
        spawnLoc = self.room2
        if spawnLoc == self.char1.location:
            # Just to make sure we use a different location, in case someone changes
            # char1's default location in the future...
            spawnLoc = self.room1

        self.call(
            building.CmdSpawn(),
            "{'prototype_key':'GOBLIN', 'typeclass':'evennia.objects.objects.DefaultCharacter', "
            "'key':'goblin', 'location':'%s'}" % spawnLoc.dbref,
            "Spawned goblin")
        goblin = getObject(self, "goblin")
        # Tests that the spawned object's type is a DefaultCharacter.
        self.assertIsInstance(goblin, DefaultCharacter)
        self.assertEqual(goblin.location, spawnLoc)

        goblin.delete()

        # create prototype
        protlib.create_prototype(
            **{
                'key': 'Ball',
                'typeclass': 'evennia.objects.objects.DefaultCharacter',
                'prototype_key': 'testball'
            })

        # Tests "@spawn <prototype_name>"
        self.call(building.CmdSpawn(), "testball", "Spawned Ball")

        ball = getObject(self, "Ball")
        self.assertEqual(ball.location, self.char1.location)
        self.assertIsInstance(ball, DefaultObject)
        ball.delete()

        # Tests "@spawn/n ..." without specifying a location.
        # Location should be "None".
        self.call(building.CmdSpawn(), "/n 'BALL'",
                  "Spawned Ball")  # /n switch is abbreviated form of /noloc
        ball = getObject(self, "Ball")
        self.assertIsNone(ball.location)
        ball.delete()

        self.call(
            building.CmdSpawn(),
            "/noloc {'prototype_parent':'TESTBALL', 'prototype_key': 'testball', 'location':'%s'}"
            % spawnLoc.dbref,
            "Error: Prototype testball tries to parent itself.")

        # Tests "@spawn/noloc ...", but DO specify a location.
        # Location should be the specified location.
        self.call(
            building.CmdSpawn(),
            "/noloc {'prototype_parent':'TESTBALL', 'key': 'Ball', 'prototype_key': 'foo', 'location':'%s'}"
            % spawnLoc.dbref, "Spawned Ball")
        ball = getObject(self, "Ball")
        self.assertEqual(ball.location, spawnLoc)
        ball.delete()

        # test calling spawn with an invalid prototype.
        self.call(building.CmdSpawn(), "'NO_EXIST'",
                  "No prototype named 'NO_EXIST'")

        # Test listing commands
        self.call(building.CmdSpawn(), "/list", "Key ")