def append_job(self, job):
     from job_view      import JobView
     from job_model     import JobModel
     from job_presenter import JobPresenter
     id = job.id
     jobmodel  = JobModel(job)
     jobview   = JobView()
     jobpresen = JobPresenter(jobmodel, jobview)
     jobmodel.init()
     self.__job_dict[id] = (jobmodel, jobview, jobpresen)
     self.created_event.fire()
 def setUp(self):
     from  job_presenter  import JobPresenter
     from  job_model      import JobModel
     from  job_view       import JobView, NotFoundRequestError
     from  jobmock        import JobMock
     job         = JobMock(1)
     self.model  = JobModel(job)
     self.view   = JobView()
     self.presen = JobPresenter(self.model, self.view)
 def setUp(self):
     self.job   = JobMock(5)
     self.model = JobModel(self.job)
class TestJobModelWithState:
    
    def setUp(self):
        self.job   = JobMock(5)
        self.model = JobModel(self.job)

    def tearDown(self):
        self.model = None
        self.job   = None

    def test_init(self):
        prop_list = [
            'expected_time' , 
            'start_time'    , 
            'finish_time'   , 
            'elasped_time'  ,
            'jms'           , 
            'location'      , 
            'name'          , 
        ]
        assert_equal(self.model.get_state(), self.job.state)
        for prop in prop_list:
            assert_equal(getattr(self.model, prop), getattr(self.model, prop))

        req_set = set( self.model.get_available_request_dict().keys() )
        assert_equal( req_set, set( self.job.get_all_request()) )

    def test_run_request(self):
        for reqname, b in self.model.get_available_request_dict().items():
            print reqname
            if b:
                assert_not_catch_exc(
                    NotUsedRequestError, getattr(self.model, reqname) )
            else:
                assert_catch_exc(
                    NotUsedRequestError, getattr(self.model, reqname) )

        # state changed
        self.job.switch_state()
        for reqname, b in self.model.get_available_request_dict().items():
            print reqname
            if b:
                assert_not_catch_exc(
                    NotUsedRequestError, getattr(self.model, reqname) )
            else:
                assert_catch_exc(
                    NotUsedRequestError, getattr(self.model, reqname) )

    def test_get_available_request_dict(self):
        ava_req_list = [
            req for req, b in self.model.get_available_request_dict().items()
                if b
        ]
        assert_equal( set(ava_req_list), set(self.job.get_available_request()))

        # state changed
        self.job.switch_state()
        ava_req_list = [
            req for req, b in self.model.get_available_request_dict().items()
                if b
        ]
        assert_equal( set(ava_req_list), set(self.job.get_available_request()))

    def test_state_changed(self):
        state_catcher = EventCatcher(self.model.state_changed_event)
        self.job.switch_state()
        # assert_equal(state_catcher.is_catched(), True)
        assert_equal(state_catcher.count, 1)
        assert_equal(self.model.get_state(), self.job.state)

    def test_property_and_model_updated(self):
        update_catcher = EventCatcher(self.model.update_event)
        prop_val_dict = dict(
            expected_time = '2:00'       , 
            start_time    = '18:00'      , 
            finish_time   = '20:00'      , 
            elasped_time  = '1:00'       , 
            jms           = 'NQS'        , 
            location      = 'vlsn'       , 
            name          = 'Job name b' , 
        )

        i = 0
        for prop, value in prop_val_dict.items():
            i += 1
            set_method = 'set_' + prop
            get_method = 'get_' + prop
            getattr(self.job, set_method)(value)
            assert_catch_event( update_catcher )
            assert_equal( getattr(self.model, prop), value )

    def test_set_auto(self):
        enable = self.job.is_auto()
        assert_equal(self.model.is_auto(), enable)

        self.model.enable_auto(not enable)
        assert_equal(self.model.is_auto(), not enable)
        assert_equal(self.model.is_auto(), self.job.is_auto())

    def test_is_selected(self):
        assert_equal( self.model.is_selected(), False )
        self.model.enable_selected(True)
        assert_equal( self.model.is_selected(), True )
class TestJobPresenter:

    def setUp(self):
        from  job_presenter  import JobPresenter
        from  job_model      import JobModel
        from  job_view       import JobView, NotFoundRequestError
        from  jobmock        import JobMock
        job         = JobMock(1)
        self.model  = JobModel(job)
        self.view   = JobView()
        self.presen = JobPresenter(self.model, self.view)

    def tearDown(self):
        self.model = None
        self.view = None
        self.present = None

    def test_init(self):
        # ec = EventCatcher(self.view.delete_event)
        ec = EventCatcher(self.model.delete_event)
        ec.trigger('fuga')
        assert_catch_event(ec,'fuga')
        assert_method(self.view, 'get_name', ret='task name' )
        #assert hasattr(self.presen, 'change_state')
        #assert ec.is_event()

    def test_change_state(self):
        assert_method(self.model, 'get_state', ret='Running')
        assert_method(self.view, 'set_state', args=['Running'])

        assert_method(self.model, 'get_available_request_dict')
        req_dict = self.model.get_available_request_dict()
        assert_method(self.model, 'get_available_request_dict', args=[req_dict])

        assert_method(self.view, 'set_request_dict')
        request_dict = dict(
            request_submit  = False , 
            request_convert = False , 
            request_send    = False , 
            request_run     = False , 
            request_stop    = True  , 
            request_cancel  = True  , 
            request_rerun   = False , 
            request_receive = False , 
            request_sync    = False , 
        )
        assert_method(self.view, 'set_request_dict', args=[request_dict])

    def test_update_view(self):

        ec = EventCatcher(self.model.update_event)
        prop_val_dict = dict(
            expected_time = '2:00'       , 
            start_time    = '18:00'      , 
            finish_time   = '20:00'      , 
            elasped_time  = '1:00'       , 
            jms           = 'NQS'        , 
            location      = 'vlsn'       , 
            name          = 'Job name b' , 
        )
        for prop, val in prop_val_dict.items():
            ec.trigger(prop)
            assert_catch_event(ec, prop)

            set_prop = 'set_'+prop
            get_prop = 'get_'+prop

            assert_method(self.model, prop)
            assert_method(self.view , set_prop, args=[val])

    def test_delete_in_model(self):
        pass

    def test_request(self):
        request_list = [
            'request_submit',
            'request_convert',
            'request_send',
            'request_run',
            'request_stop',
            'request_cancel',
            'request_rerun',
            'request_receive',
            'request_sync',
        ]
        for reqname in request_list:
            assert_method(self.model, reqname)