Beispiel #1
0
    def test_cache_gets_change_from_db(self):

        dog = Dog(name="woofer")
        self.db.put(dog)

        with buffered_db(self.db) as dbc:
            fetched = dbc.get(dog.key)
            self.assertTrue(fetched is not None)
            self.assertNotEqual(id(dog), id(fetched))
            fetched_again = dbc.get(dog.key)
            self.assertTrue(fetched_again is not None)

            self.assertEqual(id(fetched), id(fetched_again))
            dog.name = "fly"
            self.db.put(dog)

            fetched_yet_again = dbc.get(dog.key)
            self.assertTrue(fetched_yet_again is not None)

            self.assertEqual(id(fetched), id(fetched_yet_again))
            self.assertEqual(fetched_yet_again.name, 'fly')
            fetched_yet_again.name = "bluebottle"
            db_fetched = self.db.get(dog.key)
            self.assertEqual(db_fetched.name, 'fly')

        db_fetched = self.db.get(dog.key)
        self.assertEqual(db_fetched.name, 'fly')
Beispiel #2
0
 def test_refs_with_other_inheritance(self):
     paul = Monarch(name="paul")
     self.db.put(paul)
     jack = Dog()
     jack.owner = paul
     jack.name = "jack"
     self.db.put(jack)
     dogs = list(paul.dogs)
     self.assertEqual(dogs[0], jack)
Beispiel #3
0
 def test_refs_with_other_inheritance(self):
     paul = Monarch(name="paul")
     self.db.put(paul)
     jack = Dog()
     jack.owner = paul
     jack.name = "jack"
     self.db.put(jack)
     dogs = list(paul.dogs)
     self.assertEqual(dogs[0], jack)
Beispiel #4
0
        def test_delete_callbacks(self):

            with patch.object(Dog, 'pre_delete_cb', return_value=None) as mock_pre_delete:
                dog = Dog(name="woofer")
                self.db.put(dog)
                mock_pre_delete.assert_not_called()
                dog.name = "fly"
                self.db.delete(dog)
                mock_pre_delete.assert_called_once_with(self.db)


            with patch.object(Dog, 'post_delete_cb', return_value=None) as mock_post_delete:
                dog = Dog(name="woofer")
                self.db.put(dog)
                mock_post_delete.assert_not_called()
                dog.name = "fly"
                self.db.delete(dog)
                mock_post_delete.assert_called_once_with(self.db)
Beispiel #5
0
        def test_update_callbacks(self):

            with patch.object(Dog, 'pre_save_update_cb', return_value=None) as mock_pre_update:
                dog = Dog(name="woofer")
                self.db.put(dog)
                old_properties = deepcopy(dog._properties)
                mock_pre_update.assert_not_called()
                dog.name = "fly"
                self.db.put(dog)
                mock_pre_update.assert_called_once_with(self.db, old_properties)

            with patch.object(Dog, 'post_save_update_cb', return_value=None) as mock_post_update:
                dog = Dog(name="woofer")
                self.db.put(dog)
                mock_post_update.assert_not_called()
                dog.name = "fly"
                self.db.put(dog)
                mock_post_update.assert_called_once_with(self.db)
Beispiel #6
0
 def test_update_fails_without_rev(self):
     dog = Dog(name="fly")
     dog.save(self.db)
     dog.rev = None
     dog.name = "jess"
     self.assertRaises(FamResourceConflict, self.db.put, dog)
Beispiel #7
0
 def test_update_fails_without_rev(self):
     dog = Dog(name="fly")
     dog.save(self.db)
     dog.rev = None
     dog.name = "jess"
     self.assertRaises(FamResourceConflict, self.db.put, dog)