Esempio n. 1
0
    def test_add(self):
        x = self.klass()

        # not a class type
        self.assertRaises(TypeError, x.addClassKey, chr, '')
        # not a subclass of db.Model/db.Expando
        self.assertRaises(TypeError, x.addClassKey, Spam, '')
        # wrong type for key
        self.assertRaises(TypeError, x.addClassKey, test_models.PetModel, 3)

        x = self.klass()
        pm1 = test_models.PetModel(type='cat', name='Jessica')
        pm2 = test_models.PetModel(type='dog', name='Sam')
        pe1 = test_models.PetExpando(type='cat', name='Toby')

        self.assertEqual(x, {})

        x.addClassKey(test_models.PetModel, 'foo', pm1)
        self.assertEqual(x, {test_models.PetModel: {'foo': pm1}})
        x.addClassKey(test_models.PetModel, 'bar', pm2)
        self.assertEqual(x, {test_models.PetModel: {'foo': pm1, 'bar': pm2}})
        x.addClassKey(test_models.PetExpando, 'baz', pe1)
        self.assertEqual(x, {
            test_models.PetModel: {'foo': pm1, 'bar': pm2},
            test_models.PetExpando: {'baz': pe1}
        })
Esempio n. 2
0
    def setUp(self):
        BaseTestCase.setUp(self)

        self.alias = adapter_db.DataStoreClassAlias(test_models.PetModel, 'foo.bar')

        self.jessica = test_models.PetModel(name='Jessica', type='cat')
        self.jessica_expando = test_models.PetExpando(name='Jessica', type='cat')
        self.jessica_expando.foo = 'bar'

        self.addCleanup(self.deleteEntity, self.jessica)
        self.addCleanup(self.deleteEntity, self.jessica_expando)
Esempio n. 3
0
    def setUp(self):
        BaseTestCase.setUp(self)

        self.jessica = test_models.PetModel(name='Jessica', type='cat')
        self.jessica.birthdate = datetime.date(1986, 10, 2)
        self.jessica.weight_in_pounds = 5
        self.jessica.spayed_or_neutered = False

        self.put(self.jessica)

        self.jessica2 = db.get(self.jessica.key())

        self.assertNotIdentical(self.jessica,self.jessica2)
        self.assertEqual(str(self.jessica.key()), str(self.jessica2.key()))