Example #1
0
  def testFilter3(self):
    with JeevesLib.PositiveVariable(self.x):
      an = Animal.objects.create(name='filter_test3', sound='a')
    with JeevesLib.NegativeVariable(self.y):
      bn = Animal.objects.create(name='filter_test3', sound='b')

    bl = Animal.objects.filter(name='filter_test3').order_by('sound').get_jiter()
    self.assertEquals(bl, [(an, {self.x.name:True}), (bn, {self.y.name:False})])
Example #2
0
  def testSaveCollapse(self):
    an = Animal.objects.create(name='savec_test', sound='b')
    an.sound = 'c'
    with JeevesLib.PositiveVariable(self.x):
      an.save()
    with JeevesLib.NegativeVariable(self.x):
      an.save()

    a = list(Animal._objects_ordinary.filter(name='savec_test').all())
    self.assertTrue(areRowsEqual(a, [
        ({'name':'savec_test', 'sound':'c'}, {}),
    ]))
Example #3
0
    def testGet4(self):
        with JeevesLib.PositiveVariable(self.x):
            an = Animal.objects.create(name='get_test4', sound='a')
        with JeevesLib.NegativeVariable(self.y):
            bn = Animal.objects.create(name='get_test4', sound='b')

        got_exc = False
        try:
            cn = Animal.objects.get(name='get_test4')
        except Exception:
            got_exc = True

        self.assertTrue(got_exc)
Example #4
0
    def testSave(self):
        """Test that saving does the correct bookkeeping.
        """
        an = Animal.objects.create(name='save_test1', sound='b')
        an.sound = 'c'
        with JeevesLib.PositiveVariable(self.x):
            an.save()
        a = list(Animal._objects_ordinary.filter(name='save_test1').all())
        self.assertTrue(
            areRowsEqual(a, [
                ({
                    'name': 'save_test1',
                    'sound': 'b'
                }, {
                    self.x.name: False
                }),
                ({
                    'name': 'save_test1',
                    'sound': 'c'
                }, {
                    self.x.name: True
                }),
            ]))

        an = Animal.objects.create(name='save_test2', sound='b')
        an.sound = 'c'
        with JeevesLib.PositiveVariable(self.x):
            with JeevesLib.NegativeVariable(self.y):
                an.save()
        a = list(Animal._objects_ordinary.filter(name='save_test2').all())
        self.assertTrue(
            areRowsEqual(a, [
                ({
                    'name': 'save_test2',
                    'sound': 'c'
                }, {
                    self.x.name: True,
                    self.y.name: False
                }),
                ({
                    'name': 'save_test2',
                    'sound': 'b'
                }, {
                    self.x.name: True,
                    self.y.name: True
                }),
                ({
                    'name': 'save_test2',
                    'sound': 'b'
                }, {
                    self.x.name: False
                }),
            ]) or areRowsEqual(a, [
                ({
                    'name': 'save_test2',
                    'sound': 'c'
                }, {
                    self.x.name: True,
                    self.y.name: False
                }),
                ({
                    'name': 'save_test2',
                    'sound': 'b'
                }, {
                    self.x.name: False,
                    self.y.name: False
                }),
                ({
                    'name': 'save_test2',
                    'sound': 'b'
                }, {
                    self.y.name: True
                }),
            ]))

        an = Animal.objects.create(name='save_test3',
                                   sound=JeevesLib.mkSensitive(
                                       self.x, 'b', 'c'))
        an.sound = JeevesLib.mkSensitive(self.x, 'd', 'e')
        an.save()
        a = list(Animal._objects_ordinary.filter(name='save_test3').all())
        self.assertTrue(
            areRowsEqual(a, [
                ({
                    'name': 'save_test3',
                    'sound': 'd'
                }, {
                    self.x.name: True
                }),
                ({
                    'name': 'save_test3',
                    'sound': 'e'
                }, {
                    self.x.name: False
                }),
            ]))

        an = Animal.objects.create(name='save_test4',
                                   sound=JeevesLib.mkSensitive(
                                       self.x, 'b', 'c'))
        an.sound = JeevesLib.mkSensitive(self.y, 'd', 'e')
        an.save()
        a = list(Animal._objects_ordinary.filter(name='save_test4').all())
        self.assertTrue(
            areRowsEqual(a, [
                ({
                    'name': 'save_test4',
                    'sound': 'd'
                }, {
                    self.y.name: True
                }),
                ({
                    'name': 'save_test4',
                    'sound': 'e'
                }, {
                    self.y.name: False
                }),
            ]) or areRowsEqual(a, [
                ({
                    'name': 'save_test4',
                    'sound': 'd'
                }, {
                    self.y.name: True,
                    self.x.name: True
                }),
                ({
                    'name': 'save_test4',
                    'sound': 'd'
                }, {
                    self.y.name: True,
                    self.x.name: False
                }),
                ({
                    'name': 'save_test4',
                    'sound': 'e'
                }, {
                    self.y.name: False,
                    self.x.name: True
                }),
                ({
                    'name': 'save_test4',
                    'sound': 'e'
                }, {
                    self.y.name: False,
                    self.x.name: False
                }),
            ]))

        an = Animal.objects.create(name='save_test5',
                                   sound=JeevesLib.mkSensitive(
                                       self.x, 'b', 'c'))
        an.sound = JeevesLib.mkSensitive(self.y, 'd', 'e')
        with JeevesLib.PositiveVariable(self.x):
            an.save()
        a = list(Animal._objects_ordinary.filter(name='save_test5').all())
        self.assertTrue(
            areRowsEqual(a, [
                ({
                    'name': 'save_test5',
                    'sound': 'c'
                }, {
                    self.x.name: False
                }),
                ({
                    'name': 'save_test5',
                    'sound': 'd'
                }, {
                    self.x.name: True,
                    self.y.name: True
                }),
                ({
                    'name': 'save_test5',
                    'sound': 'e'
                }, {
                    self.x.name: True,
                    self.y.name: False
                }),
            ]))

        an = Animal.objects.create(name='save_test6',
                                   sound=JeevesLib.mkSensitive(
                                       self.x, 'b', 'c'))
        an.sound = JeevesLib.mkSensitive(self.y, 'd', 'e')
        with JeevesLib.PositiveVariable(self.y):
            an.save()
        a = list(Animal._objects_ordinary.filter(name='save_test6').all())
        self.assertTrue(
            areRowsEqual(a, [
                ({
                    'name': 'save_test6',
                    'sound': 'b'
                }, {
                    self.x.name: True,
                    self.y.name: False
                }),
                ({
                    'name': 'save_test6',
                    'sound': 'd'
                }, {
                    self.x.name: True,
                    self.y.name: True
                }),
                ({
                    'name': 'save_test6',
                    'sound': 'c'
                }, {
                    self.x.name: False,
                    self.y.name: False
                }),
                ({
                    'name': 'save_test6',
                    'sound': 'd'
                }, {
                    self.x.name: False,
                    self.y.name: True
                }),
            ]) or areRowsEqual(a, [
                ({
                    'name': 'save_test6',
                    'sound': 'b'
                }, {
                    self.x.name: True,
                    self.y.name: False
                }),
                ({
                    'name': 'save_test6',
                    'sound': 'd'
                }, {
                    self.y.name: True
                }),
                ({
                    'name': 'save_test6',
                    'sound': 'c'
                }, {
                    self.x.name: False,
                    self.y.name: False
                }),
            ]))

        an = Animal.objects.create(name='save_test7',
                                   sound=JeevesLib.mkSensitive(
                                       self.x, 'b', 'c'))
        an.sound = JeevesLib.mkSensitive(self.y, 'd', 'e')
        with JeevesLib.PositiveVariable(self.x):
            with JeevesLib.PositiveVariable(self.y):
                an.save()
        a = list(Animal._objects_ordinary.filter(name='save_test7').all())
        self.assertTrue(
            areRowsEqual(a, [
                ({
                    'name': 'save_test7',
                    'sound': 'd'
                }, {
                    self.x.name: True,
                    self.y.name: True
                }),
                ({
                    'name': 'save_test7',
                    'sound': 'b'
                }, {
                    self.x.name: True,
                    self.y.name: False
                }),
                ({
                    'name': 'save_test7',
                    'sound': 'c'
                }, {
                    self.x.name: False
                }),
            ]))
Example #5
0
    def testQueryDelete(self):
        """Test that delete removes all rows.
        """
        Animal.objects.create(name='delete_test1',
                              sound=JeevesLib.mkSensitive(
                                  self.x,
                                  JeevesLib.mkSensitive(self.y, 'b', 'c'),
                                  JeevesLib.mkSensitive(self.y, 'd', 'e')))
        Animal.objects.filter(name='delete_test1').filter(sound='b').delete()
        a = list(Animal._objects_ordinary.filter(name='delete_test1').all())
        self.assertTrue(
            areRowsEqual(a, [({
                'name': 'delete_test1',
                'sound': 'c'
            }, {
                self.x.name: True,
                self.y.name: False
            }),
                             ({
                                 'name': 'delete_test1',
                                 'sound': 'd'
                             }, {
                                 self.x.name: False,
                                 self.y.name: True
                             }),
                             ({
                                 'name': 'delete_test1',
                                 'sound': 'e'
                             }, {
                                 self.x.name: False,
                                 self.y.name: False
                             })]))

        an = Animal.objects.create(name='delete_test2',
                                   sound=JeevesLib.mkSensitive(
                                       self.x,
                                       JeevesLib.mkSensitive(self.y, 'b', 'c'),
                                       JeevesLib.mkSensitive(self.y, 'd',
                                                             'e')))
        with JeevesLib.PositiveVariable(self.x):
            an.delete()
        a = list(Animal._objects_ordinary.filter(name='delete_test2').all())
        self.assertTrue(
            areRowsEqual(a, [
                ({
                    'name': 'delete_test2',
                    'sound': 'd'
                }, {
                    self.x.name: False,
                    self.y.name: True
                }),
                ({
                    'name': 'delete_test2',
                    'sound': 'e'
                }, {
                    self.x.name: False,
                    self.y.name: False
                }),
            ]))

        an = Animal.objects.create(name='delete_test3', sound='b')
        with JeevesLib.PositiveVariable(self.x):
            an.delete()
        a = list(Animal._objects_ordinary.filter(name='delete_test3').all())
        self.assertTrue(
            areRowsEqual(a, [({
                'name': 'delete_test3',
                'sound': 'b'
            }, {
                self.x.name: False
            })]))

        an = Animal.objects.create(name='delete_test4', sound='b')
        with JeevesLib.PositiveVariable(self.x):
            with JeevesLib.NegativeVariable(self.y):
                an.delete()
        a = list(Animal._objects_ordinary.filter(name='delete_test4').all())
        self.assertTrue(
            areRowsEqual(a, [
                ({
                    'name': 'delete_test4',
                    'sound': 'b'
                }, {
                    self.x.name: False
                }),
                ({
                    'name': 'delete_test4',
                    'sound': 'b'
                }, {
                    self.x.name: True,
                    self.y.name: True
                }),
            ]) or areRowsEqual(a, [
                ({
                    'name': 'delete_test4',
                    'sound': 'b'
                }, {
                    self.y.name: True
                }),
                ({
                    'name': 'delete_test4',
                    'sound': 'b'
                }, {
                    self.y.name: False,
                    self.x.name: False
                }),
            ]))

        an = Animal.objects.create(name='delete_test5',
                                   sound=JeevesLib.mkSensitive(
                                       self.x, 'b', 'c'))
        with JeevesLib.PositiveVariable(self.x):
            an.delete()
        a = list(Animal._objects_ordinary.filter(name='delete_test5').all())
        self.assertTrue(
            areRowsEqual(a, [({
                'name': 'delete_test5',
                'sound': 'c'
            }, {
                self.x.name: False
            })]))

        an = Animal.objects.create(name='delete_test6',
                                   sound=JeevesLib.mkSensitive(
                                       self.x, 'b', 'c'))
        with JeevesLib.PositiveVariable(self.y):
            an.delete()
        a = list(Animal._objects_ordinary.filter(name='delete_test6').all())
        self.assertTrue(
            areRowsEqual(a, [
                ({
                    'name': 'delete_test6',
                    'sound': 'b'
                }, {
                    self.x.name: True,
                    self.y.name: False
                }),
                ({
                    'name': 'delete_test6',
                    'sound': 'c'
                }, {
                    self.x.name: False,
                    self.y.name: False
                }),
            ]))