Ejemplo n.º 1
0
    def testCmp(self):
        #Test Compaison function
        item1 = models.Room(id=1,
                            name="Test Room",
                            roomTypeId = 1)

        item2 = models.Room(id=1,
                            name="Test Room",
                            roomTypeId = 1)

        self.assertEqual(item1, item2)

        #Order On Name
        item2.name = "A_Test"
        self.assertGreater(item1, item2)

        item2.name = "Z_Test"
        self.assertLess(item1, item2)

        item2.name = item1.name
        item2.roomTypeId = 0
        self.assertGreater(item1, item2)

        item2.roomTypeId = 2
        self.assertLess(item1, item2)
Ejemplo n.º 2
0
    def testAssociations(self):
        #"""Test if backrefs and foriegn keys work correctly"""
        session = self.session

        roomtype = models.RoomType(name = "Foo Type")
        session.add(roomtype)
        session.flush()

        room = models.Room(name = "Test Room",
                           roomTypeId = roomtype.id)

        session.add(room)
        session.flush()

        session.commit()

        #And then do the check the backrefs etc
        qryroom = session.query(models.Room).filter_by(name="Test Room").first()


        self.assertEqual(room,qryroom)

        #Check the Ids match
        qrytype = qryroom.roomTypeId

        self.assertEqual(qrytype, roomtype.id)

        #And check on the backrefs
        qrytype = qryroom.roomType
        self.assertEqual(qrytype,roomtype)
Ejemplo n.º 3
0
    def testNEQ(self):
        item1 = models.Room(id=1,
                            name="Test Room",
                            roomTypeId = 1)
        item2 = models.Room(id=1,
                            name="Test Room",
                            roomTypeId = 1)

        self.assertEqual(item1, item2)

        item2.name = "FOO"
        self.assertNotEqual(item1, item2)
        self.assertReallyNotEqual(item1, item2)

        item2.name = item1.name
        item2.roomTypeId = 2
Ejemplo n.º 4
0
    def testEq(self):
        #"""Test for Equality"""
        item1 = models.Room(id=1,
                            name="Test Room",
                            roomTypeId = 1)
        item2 = models.Room(id=1,
                            name="Test Room",
                            roomTypeId = 1)

        self.assertEqual(item1, item2)
        self.assertReallyEqual(item1, item2)

        #Not massivly botherered about Id at the moment
        item2.id = 5
        self.assertEqual(item1, item2)
        self.assertReallyEqual(item1, item2)
Ejemplo n.º 5
0
 def _serialobj(self):
     """Helper Method to provde an object to serialise"""
     theItem = models.Room(id=1,
                           name="Test Room",
                           roomTypeId = 1)
     return theItem