<s> from __future__ import absolute_import <EOL> from . fixtures import * <EOL> from blitzdb import Document <EOL> import datetime <EOL> class MyDocument ( Document ) : <EOL> """<STR_LIT>""" <EOL> def before_save ( self ) : <EOL> self . foo = "<STR_LIT:bar>" <EOL> def before_delete ( self ) : <EOL> self . foo = "<STR_LIT:bar>" <EOL> def after_load ( self ) : <EOL> self . bar = "<STR_LIT>" <EOL> def before_update ( self , set_fields , unset_fields ) : <EOL> set_fields [ '<STR_LIT>' ] = datetime . datetime . now ( ) <EOL> class MyDerivedDocument ( MyDocument ) : <EOL> pass <EOL> def test_after_load_hook ( backend , small_test_data ) : <EOL> my_document = MyDocument ( { '<STR_LIT:test>' : <NUM_LIT> } ) <EOL> backend . save ( my_document ) <EOL> backend . commit ( ) <EOL> recovered_document = backend . get ( MyDocument , { '<STR_LIT>' : my_document . pk } ) <EOL> assert hasattr ( recovered_document , '<STR_LIT:bar>' ) <EOL> assert recovered_document . bar == "<STR_LIT>" <EOL> def test_before_save_hook ( backend , small_test_data ) : <EOL> my_document = MyDocument ( { '<STR_LIT:test>' : <NUM_LIT> } ) <EOL> backend . save ( my_document ) <EOL> assert hasattr ( my_document , '<STR_LIT:foo>' ) <EOL> assert my_document . foo == "<STR_LIT:bar>" <EOL> def test_before_update_hook ( backend , small_test_data ) : <EOL> my_document = MyDerivedDocument ( { '<STR_LIT:test>' : <NUM_LIT> } ) <EOL> backend . save ( my_document ) <EOL> assert hasattr ( my_document , '<STR_LIT:foo>' ) <EOL> assert my_document . foo == "<STR_LIT:bar>" <EOL> backend . update ( my_document , { '<STR_LIT:foo>' : '<STR_LIT>' } ) <EOL> backend . commit ( ) <EOL> assert my_document . foo == '<STR_LIT>' <EOL> assert '<STR_LIT>' in my_document <EOL> assert isinstance ( my_document . updated_at , datetime . datetime ) <EOL> def test_before_delete_hook ( backend , small_test_data ) : <EOL> my_document = MyDocument ( { '<STR_LIT:test>' : <NUM_LIT> } ) <EOL> my_document . pk = <NUM_LIT:1> <EOL> backend . delete ( my_document ) <EOL> assert hasattr ( my_document , '<STR_LIT:foo>' ) <EOL> assert my_document . foo == "<STR_LIT:bar>" </s>
