<s> from flexmock import flexmock , flexmock_teardown <EOL> from orator . orm . scopes import SoftDeletingScope <EOL> from orator . orm import Builder , Model <EOL> from orator . query import QueryBuilder <EOL> from ... import OratorTestCase , mock <EOL> class SoftDeletingScopeTestCase ( OratorTestCase ) : <EOL> def tearDown ( self ) : <EOL> flexmock_teardown ( ) <EOL> def test_apply_scope_to_a_builder ( self ) : <EOL> scope = SoftDeletingScope ( ) <EOL> query = flexmock ( QueryBuilder ( None , None , None ) ) <EOL> builder = Builder ( query ) <EOL> model = flexmock ( ModelStub ( ) ) <EOL> model . should_receive ( '<STR_LIT>' ) . once ( ) . and_return ( '<STR_LIT>' ) <EOL> builder . get_query ( ) . should_receive ( '<STR_LIT>' ) . once ( ) . with_args ( '<STR_LIT>' ) <EOL> scope . apply ( builder , model ) <EOL> def test_force_delete_extension ( self ) : <EOL> scope = SoftDeletingScope ( ) <EOL> builder = Builder ( None ) <EOL> scope . extend ( builder ) <EOL> callback = builder . get_macro ( '<STR_LIT>' ) <EOL> query = flexmock ( QueryBuilder ( None , None , None ) ) <EOL> given_builder = Builder ( query ) <EOL> query . should_receive ( '<STR_LIT>' ) . once ( ) <EOL> callback ( given_builder ) <EOL> def test_restore_extension ( self ) : <EOL> scope = SoftDeletingScope ( ) <EOL> builder = Builder ( None ) <EOL> scope . extend ( builder ) <EOL> callback = builder . get_macro ( '<STR_LIT>' ) <EOL> query = flexmock ( QueryBuilder ( None , None , None ) ) <EOL> builder_mock = flexmock ( BuilderWithTrashedStub ) <EOL> given_builder = BuilderWithTrashedStub ( query ) <EOL> builder_mock . should_receive ( '<STR_LIT>' ) . once ( ) <EOL> builder_mock . should_receive ( '<STR_LIT>' ) . once ( ) . and_return ( ModelStub ( ) ) <EOL> builder_mock . should_receive ( '<STR_LIT>' ) . once ( ) . with_args ( { '<STR_LIT>' : None } ) <EOL> callback ( given_builder ) <EOL> def test_with_trashed_extension ( self ) : <EOL> scope = flexmock ( SoftDeletingScope ( ) ) <EOL> builder = Builder ( None ) <EOL> scope . extend ( builder ) <EOL> callback = builder . get_macro ( '<STR_LIT>' ) <EOL> query = flexmock ( QueryBuilder ( None , None , None ) ) <EOL> given_builder = Builder ( query ) <EOL> model = flexmock ( ModelStub ( ) ) <EOL> given_builder . set_model ( model ) <EOL> given_builder . remove_global_scope = mock . MagicMock ( return_value = given_builder ) <EOL> result = callback ( given_builder ) <EOL> self . assertEqual ( given_builder , result ) <EOL> given_builder . remove_global_scope . assert_called_with ( scope ) <EOL> class ModelStub ( Model ) : <EOL> def get_qualified_deleted_at_column ( self ) : <EOL> return '<STR_LIT>' <EOL> def get_deleted_at_column ( self ) : <EOL> return '<STR_LIT>' <EOL> class BuilderWithTrashedStub ( Builder ) : <EOL> def with_trashed ( self ) : <EOL> pass </s>
