Пример #1
0
    def test_add_new_field(self):
        self.car.save()

        class Hybrid(objects.Car):
            fuels = orm.List(type=objects.Property)

        hybrid_car = Hybrid(id=self.car._id)
        # This test will work if you call save upon loading (if new field was added)
        # Otherwise it will write the object as {'0': {'name': 'Ethanol', value: 'E85'}, '1': {.......}}
        #hybrid_car.save()

        p0 = objects.Property()
        p0.name = "Ethanol"
        p0.value = "E85"
        hybrid_car.fuels.append(p0)

        p1 = objects.Property()
        p1.name = "Battery"
        p1.value = "240 Volts"
        hybrid_car.fuels.append(p1)

        hybrid_car.save()

        loaded_hybrid = Hybrid(id=self.car._id)
        self.assertEqual(loaded_hybrid.fuels[0].name, hybrid_car.fuels[0].name)
        self.assertEqual(loaded_hybrid.fuels[0].value,
                         hybrid_car.fuels[0].value)
Пример #2
0
    def test_lists_of_type(self):
        p0 = objects.Property()
        p0.name = "Type"
        p0.value = "Lumber"

        p1 = objects.Property()
        p1.name = "Type"
        p1.value = "Camping gear"

        p2 = objects.Property()
        p2.name = "Type"
        p2.value = "Sledgehammer"

        self.car.properties.append(p0)
        self.car.save()

        car = objects.Car.find_one(id=self.car._id)
        self.assertEqual(len(car.properties), len(self.car.properties))

        self.car.properties.append(p1)
        self.car.save()
        car = objects.Car.find_one(id=self.car._id)
        self.assertEqual(len(car.properties), len(self.car.properties))

        self.car.properties.delete('properties', 1)
        self.car.save()
        car = objects.Car(id=self.car._id)
        self.assertEqual(len(car.properties), len(self.car.properties))
Пример #3
0
    def call(self, machine):
        variable = machine.readBytePC()
        ret = parseVariable(machine, variable)

        propertyAddress = self.argVals[0].load()

        if propertyAddress == 0:
            machine.printDebug('GetPropLen 0', ret)
            ret.store(0)
        else:
            prop = objects.Property(machine, propertyAddress)
            machine.printDebug('GetPropLen', prop, prop.size, ret)

            ret.store(prop.size)
        pass