Esempio n. 1
0
 def test_i18n(self):
     from camelot.model.i18n import Translation, ExportAsPO
     session = Session()
     session.execute(Translation.__table__.delete())
     self.assertEqual(Translation.translate('bucket', 'nl_BE'), None)
     # run twice to check all branches in the code
     Translation.translate_or_register('bucket', 'nl_BE')
     Translation.translate_or_register('bucket', 'nl_BE')
     self.assertEqual(Translation.translate('bucket', 'nl_BE'), 'bucket')
     self.assertEqual(Translation.translate('', 'nl_BE'), '')
     self.assertEqual(Translation.translate_or_register('', 'nl_BE'), '')
     # clear the cache
     Translation._cache.clear()
     # fill the cache again
     translation = Translation(language='nl_BE',
                               source='bucket',
                               value='emmer',
                               uid=1)
     orm.object_session(translation).flush()
     self.assertEqual(Translation.translate('bucket', 'nl_BE'), 'emmer')
     export_action = ExportAsPO()
     model_context = MockModelContext()
     model_context.obj = translation
     try:
         generator = export_action.model_run(model_context)
         file_step = generator.next()
         generator.send(['/tmp/test.po'])
     except StopIteration:
         pass
Esempio n. 2
0
    def test_status_enumeration(self):
        Entity, session = self.Entity, self.session

        # begin status enumeration definition
        from camelot.model import type_and_status

        class Invoice(Entity, type_and_status.StatusMixin):
            book_date = schema.Column(types.Date(), nullable=False)
            status = type_and_status.Status(enumeration=[(1, "DRAFT"), (2, "READY")])

            class Admin(EntityAdmin):
                list_display = ["book_date", "current_status"]
                list_actions = [type_and_status.ChangeStatus("DRAFT"), type_and_status.ChangeStatus("READY")]
                form_actions = list_actions

        # end status enumeration definition
        self.create_all()
        self.assertTrue(issubclass(Invoice._status_history, type_and_status.StatusHistory))
        # begin status enumeration use
        invoice = Invoice(book_date=datetime.date.today())
        self.assertEqual(invoice.current_status, None)
        invoice.change_status("DRAFT", status_from_date=datetime.date.today())
        self.assertEqual(invoice.current_status, "DRAFT")
        self.assertEqual(invoice.get_status_from_date("DRAFT"), datetime.date.today())
        draft_invoices = Invoice.query.filter(Invoice.current_status == "DRAFT").count()
        ready_invoices = Invoice.query.filter(Invoice.current_status == "READY").count()
        # end status enumeration use
        self.assertEqual(draft_invoices, 1)
        self.assertEqual(ready_invoices, 0)
        ready_action = Invoice.Admin.list_actions[-1]
        model_context = MockModelContext()
        model_context.obj = invoice
        list(ready_action.model_run(model_context))
        self.assertTrue(invoice.current_status, "READY")
Esempio n. 3
0
 def test_i18n( self ):
     from camelot.model.i18n import Translation, ExportAsPO
     session = Session()
     session.execute( Translation.__table__.delete() )
     self.assertEqual( Translation.translate( 'bucket', 'nl_BE' ), None )
     # run twice to check all branches in the code
     Translation.translate_or_register( 'bucket', 'nl_BE' )
     Translation.translate_or_register( 'bucket', 'nl_BE' )
     self.assertEqual( Translation.translate( 'bucket', 'nl_BE' ), 'bucket' )
     self.assertEqual( Translation.translate( '', 'nl_BE' ), '' )
     self.assertEqual( Translation.translate_or_register( '', 'nl_BE' ), '' )
     # clear the cache
     Translation._cache.clear()
     # fill the cache again
     translation = Translation( language = 'nl_BE', source = 'bucket',
                                value = 'emmer', uid=1 )
     orm.object_session( translation ).flush()
     self.assertEqual( Translation.translate( 'bucket', 'nl_BE' ), 'emmer' )
     export_action = ExportAsPO()
     model_context = MockModelContext()
     model_context.obj = translation
     try:
         generator = export_action.model_run( model_context )
         file_step = generator.next()
         generator.send( ['/tmp/test.po'] )
     except StopIteration:
         pass
Esempio n. 4
0
 def test_import_from_file( self, filename = 'import_example.csv' ):
     from camelot.model.party import Person
     example_folder = os.path.join( os.path.dirname(__file__), '..', 'camelot_example' )
     self.context = MockModelContext()
     self.context.obj = Person.query.first() # need an object, to have a
                                             # session
     #self.assertTrue( self.context.obj != None )
     self.context.admin = self.app_admin.get_related_admin( Person )
     import_from_file = list_action.ImportFromFile()
     generator = import_from_file.model_run( self.context )
     for step in generator:
         if isinstance( step, action_steps.SelectFile ):
             generator.send( [ os.path.join( example_folder, filename ) ] )
         if isinstance( step, action_steps.ChangeObject ):
             dialog = step.render( self.gui_context )
             dialog.show()
             self.grab_widget( dialog, suffix = 'column_selection' )
         if isinstance( step, action_steps.ChangeObjects ):
             dialog = step.render()
             dialog.show()
             self.grab_widget( dialog, suffix = 'preview' ) 
         if isinstance( step, action_steps.MessageBox ):
             dialog = step.render()
             dialog.show()
             self.grab_widget( dialog, suffix = 'confirmation' )
Esempio n. 5
0
 def setUp(self):
     ModelThreadTestCase.setUp(self)
     from camelot_example.model import Movie
     from camelot.admin.application_admin import ApplicationAdmin
     self.app_admin = ApplicationAdmin()
     self.context = MockModelContext()
     self.context.obj = Movie.query.first()
     self.gui_context = GuiContext()
Esempio n. 6
0
    def test_status_enumeration(self):
        Entity, session = self.Entity, self.session

        #begin status enumeration definition
        from camelot.model import type_and_status

        class Invoice(Entity, type_and_status.StatusMixin):
            book_date = schema.Column(types.Date(), nullable=False)
            status = type_and_status.Status(enumeration=[(1,
                                                          'DRAFT'), (2,
                                                                     'READY')])

            class Admin(EntityAdmin):
                list_display = ['book_date', 'current_status']
                list_actions = [
                    type_and_status.ChangeStatus('DRAFT'),
                    type_and_status.ChangeStatus('READY')
                ]
                form_actions = list_actions

        #end status enumeration definition
        self.create_all()
        self.assertTrue(
            issubclass(Invoice._status_history, type_and_status.StatusHistory))
        #begin status enumeration use
        invoice = Invoice(book_date=datetime.date.today())
        self.assertEqual(invoice.current_status, None)
        invoice.change_status('DRAFT', status_from_date=datetime.date.today())
        self.assertEqual(invoice.current_status, 'DRAFT')
        self.assertEqual(invoice.get_status_from_date('DRAFT'),
                         datetime.date.today())
        draft_invoices = Invoice.query.filter(
            Invoice.current_status == 'DRAFT').count()
        ready_invoices = Invoice.query.filter(
            Invoice.current_status == 'READY').count()
        #end status enumeration use
        self.assertEqual(draft_invoices, 1)
        self.assertEqual(ready_invoices, 0)
        ready_action = Invoice.Admin.list_actions[-1]
        model_context = MockModelContext()
        model_context.obj = invoice
        list(ready_action.model_run(model_context))
        self.assertTrue(invoice.current_status, 'READY')
Esempio n. 7
0
 def setUp(self):
     super( ApplicationActionsCase, self ).setUp()
     from camelot.admin.application_admin import ApplicationAdmin
     from camelot.core.files.storage import Storage
     from camelot.view.workspace import DesktopWorkspace
     self.app_admin = ApplicationAdmin()
     self.context = MockModelContext()
     self.storage = Storage()
     self.gui_context = application_action.ApplicationActionGuiContext()
     self.gui_context.admin = self.app_admin
     self.gui_context.workspace = DesktopWorkspace( self.app_admin, None )
Esempio n. 8
0
 def setUp( self ):
     super( FormActionsCase, self ).setUp()
     from camelot.model.party import Person
     from camelot.admin.application_admin import ApplicationAdmin
     self.query_proxy_case = test_proxy.QueryProxyCase('setUp')
     self.query_proxy_case.setUp()
     self.app_admin = ApplicationAdmin()
     self.model_context = MockModelContext()
     self.model_context.obj = Person.query.first()
     self.model_context.admin = self.app_admin.get_related_admin( Person )
     self.gui_context = form_action.FormActionGuiContext()
     self.gui_context._model = self.query_proxy_case.proxy
     self.gui_context.widget_mapper = QtGui.QDataWidgetMapper()
     self.gui_context.widget_mapper.setModel( self.query_proxy_case.proxy )
     self.gui_context.admin = self.app_admin.get_related_admin( Person )
Esempio n. 9
0
 def setUp( self ):
     super( ListActionsCase, self ).setUp()
     from camelot_example.model import Movie
     from camelot.admin.application_admin import ApplicationAdmin
     self.query_proxy_case = test_proxy.QueryProxyCase('setUp')
     self.query_proxy_case.setUp()        
     self.app_admin = ApplicationAdmin()
     self.context = MockModelContext()
     self.context.obj = Movie.query.first()
     self.context.admin = self.app_admin.get_related_admin( Movie )
     self.gui_context = list_action.ListActionGuiContext()
     self.gui_context.admin = self.app_admin.get_related_admin( Movie )
     table_widget = tableview.AdminTableWidget( self.gui_context.admin )
     table_widget.setModel( self.query_proxy_case.proxy )
     self.gui_context.item_view = table_widget