예제 #1
0
 def test_fixture(self):
     from camelot.model.party import Person
     from camelot.model.fixture import Fixture
     session = Session()
     self.assertEqual(Fixture.find_fixture_key(Person, -1), None)
     p1 = Person()
     self.assertEqual(Fixture.find_fixture_key_and_class(p1), (None, None))
     session.expunge(p1)
     # insert a new Fixture
     p2 = Fixture.insert_or_update_fixture(Person,
                                           'test', {
                                               'first_name': 'Peter',
                                               'last_name': 'Principle'
                                           },
                                           fixture_class='test')
     # see if we can find it back
     self.assertEqual(Fixture.find_fixture_key(Person, p2.id), 'test')
     self.assertEqual(Fixture.find_fixture_key_and_class(p2),
                      ('test', 'test'))
     self.assertEqual(
         Fixture.find_fixture_keys_and_classes(Person)[p2.id],
         ('test', 'test'))
     # delete the person, and insert it back in the same fixture
     session.delete(p2)
     session.flush()
     p3 = Fixture.insert_or_update_fixture(Person,
                                           'test', {
                                               'first_name': 'Peter',
                                               'last_name': 'Principle'
                                           },
                                           fixture_class='test')
     self.assertNotEqual(p2, p3)
     # remove all fixtures
     Fixture.remove_all_fixtures(Person)
예제 #2
0
 def test_fixture( self ):
     from camelot.model.party import Person
     from camelot.model.fixture import Fixture
     session = Session()
     self.assertEqual( Fixture.find_fixture_key( Person, -1 ), None )
     p1 = Person()
     self.assertEqual( Fixture.find_fixture_key_and_class( p1 ), 
                       (None, None) )
     session.expunge( p1 )
     # insert a new Fixture
     p2 = Fixture.insert_or_update_fixture( Person, 'test',
                                            {'first_name':'Peter',
                                             'last_name':'Principle'},
                                            fixture_class = 'test' )
     # see if we can find it back
     self.assertEqual( Fixture.find_fixture_key( Person, p2.id ), 'test' )
     self.assertEqual( Fixture.find_fixture_key_and_class( p2 ), 
                       ('test', 'test') )
     self.assertEqual( Fixture.find_fixture_keys_and_classes( Person )[p2.id],
                       ('test', 'test') )
     # delete the person, and insert it back in the same fixture
     session.delete( p2 )
     session.flush()
     p3 = Fixture.insert_or_update_fixture( Person, 'test',
                                            {'first_name':'Peter',
                                             'last_name':'Principle'},
                                            fixture_class = 'test' )
     self.assertNotEqual( p2, p3 )
     # remove all fixtures
     Fixture.remove_all_fixtures( Person )
예제 #3
0
 def model_run( self, model_context ):
     import sqlalchemy.exc as sa_exc
     from camelot.core.orm import Session
     from camelot.view import action_steps
     from camelot.view.remote_signals import get_signal_handler
     LOGGER.debug('session refresh requested')
     progress_db_message = ugettext('Reload data from database')
     progress_view_message = ugettext('Update screens')
     session = Session()
     signal_handler = get_signal_handler()
     refreshed_objects = []
     expunged_objects = []
     #
     # Loop over the objects one by one to be able to detect the deleted
     # objects
     #
     session_items = len( session.identity_map )
     for i, (_key, obj) in enumerate( session.identity_map.items() ):
         try:
             session.refresh( obj )
             refreshed_objects.append( obj )
         except sa_exc.InvalidRequestError:
             #
             # this object could not be refreshed, it was probably deleted
             # outside the scope of this session, so assume it is deleted
             # from the application its point of view
             #
             session.expunge( obj )
             expunged_objects.append( obj )
         if i%10 == 0:
             yield action_steps.UpdateProgress( i, 
                                                session_items, 
                                                progress_db_message )
     yield action_steps.UpdateProgress( text = progress_view_message )
     for obj in refreshed_objects:
         signal_handler.sendEntityUpdate( None, obj )
     for obj in expunged_objects:
         signal_handler.sendEntityDelete( None, obj )
     yield action_steps.Refresh()
예제 #4
0
 def model_run(self, model_context):
     import sqlalchemy.exc as sa_exc
     from camelot.core.orm import Session
     from camelot.view import action_steps
     from camelot.view.remote_signals import get_signal_handler
     LOGGER.debug('session refresh requested')
     progress_db_message = ugettext('Reload data from database')
     progress_view_message = ugettext('Update screens')
     session = Session()
     signal_handler = get_signal_handler()
     refreshed_objects = []
     expunged_objects = []
     #
     # Loop over the objects one by one to be able to detect the deleted
     # objects
     #
     session_items = len(session.identity_map)
     for i, (_key, obj) in enumerate(six.iteritems(session.identity_map)):
         try:
             session.refresh(obj)
             refreshed_objects.append(obj)
         except sa_exc.InvalidRequestError:
             #
             # this object could not be refreshed, it was probably deleted
             # outside the scope of this session, so assume it is deleted
             # from the application its point of view
             #
             session.expunge(obj)
             expunged_objects.append(obj)
         if i % 10 == 0:
             yield action_steps.UpdateProgress(i, session_items,
                                               progress_db_message)
     yield action_steps.UpdateProgress(text=progress_view_message)
     for obj in refreshed_objects:
         signal_handler.sendEntityUpdate(self, obj)
     for obj in expunged_objects:
         signal_handler.sendEntityDelete(self, obj)
     yield action_steps.Refresh()