Exemplo n.º 1
0
    def test_retrieve_one(self):
        with locks.authority_of(locks.SYSTEM):
            obj_created = db.Object("foo")
        db.store(obj_created)
        obj_found = db.get(obj_created.uid)
        self.assertEqual(obj_created, obj_found)
        self.assertTrue(obj_created is obj_found)
        self.assertEqual(obj_found.name, "foo")
        self.assertEqual(obj_found.type, "thing")

        found = db.find_all(lambda x: x.uid == obj_created.uid)
        self.assertEqual(len(found), 1)
        self.assertEqual(obj_created, found.pop())

        self.assertEqual(obj_created, db.get(obj_created.uid))
Exemplo n.º 2
0
    def test_retrieve_one(self):
        with locks.authority_of(locks.SYSTEM):
            obj_created = db.Object("foo")
        db.store(obj_created)
        obj_found = db.get(obj_created.uid)
        self.assertEqual(obj_created, obj_found)
        self.assertTrue(obj_created is obj_found)
        self.assertEqual(obj_found.name, "foo")
        self.assertEqual(obj_found.type, "thing")

        found = db.find_all(lambda x: x.uid == obj_created.uid)
        self.assertEqual(len(found), 1)
        self.assertEqual(obj_created, found.pop())

        self.assertEqual(obj_created, db.get(obj_created.uid))
Exemplo n.º 3
0
    def test_update(self):
        with locks.authority_of(locks.SYSTEM):
            obj = db.Object("foo")
            db.store(obj)
            obj.name = "bar"
            db.store(obj)

        obj = db.get(obj.uid)
        self.assertEqual(obj.name, "bar")
        self.assertEqual(obj.type, "thing")
Exemplo n.º 4
0
 def test_open(self):
     with locks.authority_of(self.player):
         destination = db.Room("destination")
     db.store(destination)
     self.assert_response("open north to #{}".format(destination.uid),
                          "Opened north to destination.")
     exit = db.get(destination.uid + 1)
     self.assertTrue(isinstance(exit, db.Exit))
     self.assertIdentical(exit.location, self.lobby)
     self.assertIdentical(exit.destination, destination)
Exemplo n.º 5
0
 def test_open(self):
     with locks.authority_of(self.player):
         destination = db.Room("destination")
     db.store(destination)
     self.assert_response("open north to #{}".format(destination.uid),
                          "Opened north to destination.")
     exit = db.get(destination.uid + 1)
     self.assertTrue(isinstance(exit, db.Exit))
     self.assertIdentical(exit.location, self.lobby)
     self.assertIdentical(exit.destination, destination)
Exemplo n.º 6
0
    def test_update(self):
        with locks.authority_of(locks.SYSTEM):
            obj = db.Object("foo")
            db.store(obj)
            obj.name = "bar"
            db.store(obj)

        obj = db.get(obj.uid)
        self.assertEqual(obj.name, "bar")
        self.assertEqual(obj.type, "thing")
Exemplo n.º 7
0
 def test_dig(self):
     uid = db._nextUid
     self.assert_response("dig", "Enter the room's name (. to cancel):")
     self.assert_response("Room", "Enter the name of the exit into the "
                                  "room, if any (. to cancel):")
     self.assert_response("east", "Enter the name of the exit back, if any "
                                  "(. to cancel):")
     self.assert_response("west", "Dug room #{}, Room.".format(uid))
     room = db.get(uid)
     self.assertEqual(room.type, "room")
     self.assertEqual(room.name, "Room")
Exemplo n.º 8
0
 def test_dig_commas(self):
     uid = db._nextUid
     self.assert_response("dig Room, With, Commas",
                          "Enter the name of the exit "
                          "into the room, if any (. to cancel):")
     self.assert_response("east", "Enter the name of the exit back, if "
                                  "any (. to cancel):")
     self.assert_response("west", "Dug room #{}, Room, With, "
                                  "Commas.".format(uid))
     room = db.get(uid)
     self.assertEqual(room.name, "Room, With, Commas")
Exemplo n.º 9
0
 def test_dig_oneline(self):
     uid = db._nextUid
     self.assert_response("dig Another Room", "Enter the name of the exit "
                                              "into the room, if any "
                                              "(. to cancel):")
     self.assert_response("west", "Enter the name of the exit back, if "
                                  "any (. to cancel):")
     self.assert_response("east", "Dug room #{}, Another Room.".format(uid))
     room = db.get(uid)
     self.assertEqual(room.type, "room")
     self.assertEqual(room.name, "Another Room")
Exemplo n.º 10
0
 def parseImpl(self, instring, loc, doActions=True):
     try:
         result = self.pattern.parseString(instring[loc:])
         if not result.uid.isdigit():
             raise pyp.ParseException(instring, loc, self.errmsg, self)
         uid = int(result.uid)
         return loc + len(result.uid) + 1, db.get(uid)
     except pyp.ParseException:
         # Nope! Raise ours instead.
         raise pyp.ParseException(instring, loc, self.errmsg, self)
     except KeyError:
         raise NoSuchUidError("#{}".format(result.uid), loc, self.errmsg,
                              self)
Exemplo n.º 11
0
 def parseImpl(self, instring, loc, doActions=True):
     try:
         result = self.pattern.parseString(instring[loc:])
         if not result.uid.isdigit():
             raise pyp.ParseException(instring, loc, self.errmsg, self)
         uid = int(result.uid)
         return loc + len(result.uid) + 1, db.get(uid)
     except pyp.ParseException:
         # Nope! Raise ours instead.
         raise pyp.ParseException(instring, loc, self.errmsg, self)
     except KeyError:
         raise NoSuchUidError("#{}".format(result.uid), loc, self.errmsg,
                              self)
Exemplo n.º 12
0
 def test_dig_commas(self):
     uid = db._nextUid
     self.assert_response(
         "dig Room, With, Commas", "Enter the name of the exit "
         "into the room, if any (. to cancel):")
     self.assert_response(
         "east", "Enter the name of the exit back, if "
         "any (. to cancel):")
     self.assert_response(
         "west", "Dug room #{}, Room, With, "
         "Commas.".format(uid))
     room = db.get(uid)
     self.assertEqual(room.name, "Room, With, Commas")
Exemplo n.º 13
0
 def test_dig_oneline(self):
     uid = db._nextUid
     self.assert_response(
         "dig Another Room", "Enter the name of the exit "
         "into the room, if any "
         "(. to cancel):")
     self.assert_response(
         "west", "Enter the name of the exit back, if "
         "any (. to cancel):")
     self.assert_response("east", "Dug room #{}, Another Room.".format(uid))
     room = db.get(uid)
     self.assertEqual(room.type, "room")
     self.assertEqual(room.name, "Another Room")
Exemplo n.º 14
0
 def test_dig(self):
     uid = db._nextUid
     self.assert_response("dig", "Enter the room's name (. to cancel):")
     self.assert_response(
         "Room", "Enter the name of the exit into the "
         "room, if any (. to cancel):")
     self.assert_response(
         "east", "Enter the name of the exit back, if any "
         "(. to cancel):")
     self.assert_response("west", "Dug room #{}, Room.".format(uid))
     room = db.get(uid)
     self.assertEqual(room.type, "room")
     self.assertEqual(room.name, "Room")
Exemplo n.º 15
0
 def test_dig_noexits(self):
     uid = db._nextUid
     self.assert_response("dig Room", "Enter the name of the exit into the "
                                      "room, if any (. to cancel):")
     self.assert_response("", "Enter the name of the exit back, if "
                                  "any (. to cancel):")
     self.assert_response("", "Dug room #{}, Room.".format(uid))
     room = db.get(uid)
     self.assertEqual(room.type, "room")
     self.assertEqual(room.name, "Room")
     exits = db.find_all(lambda x: x.type == "exit" and 
                                   (x.location is room or
                                    x.destination is room))
     self.assertEqual(exits, set())
Exemplo n.º 16
0
 def test_dig_noexits(self):
     uid = db._nextUid
     self.assert_response(
         "dig Room", "Enter the name of the exit into the "
         "room, if any (. to cancel):")
     self.assert_response(
         "", "Enter the name of the exit back, if "
         "any (. to cancel):")
     self.assert_response("", "Dug room #{}, Room.".format(uid))
     room = db.get(uid)
     self.assertEqual(room.type, "room")
     self.assertEqual(room.name, "Room")
     exits = db.find_all(lambda x: x.type == "exit" and
                         (x.location is room or x.destination is room))
     self.assertEqual(exits, set())