Ejemplo n.º 1
0
  def testScreenUpdateElementsUpdateReceived(self):
    resource_dir = tempfile.mkdtemp()
    http_client = MockFaseHTTPClient(self, resource_dir)
    ui = MockFaseUI(self)
    resource_manager = fase_resource_manager.FaseResourceManager(resource_dir, http_client)
    client = fase_client.FaseClient(http_client=http_client, ui=ui, resource_manager=resource_manager)

    service = ClientTestService()
    screen = service.OnStart()

    http_client.service = service
    http_client.screen = screen
    http_client.session_info = fase_model.SessionInfo(service.GetSessionId())
    http_client.screen_info = fase_model.ScreenInfo(screen.GetScreenId())
    ui.expected_screen = screen
    client.Run()
    self.assertEqual(1, http_client.get_service_calls)
    self.assertEqual(1, ui.draw_screen_calls)
    
    http_client.elements_update=fase_model.ElementsUpdate([['text_name_id']], ['Hanry Ford'])
    http_client.screen = None
    client.ScreenUpdate()
    time.sleep(0.1)
    self.assertEqual(1, http_client.screen_update_calls)

    ui.expected_id_list = ['text_name_id']
    ui.expected_value = 'Hanry Ford'
    client.ScreenUpdate()
    self.assertEqual(1, ui.draw_screen_calls)
    self.assertEqual(1, ui.element_updated_received_calls)
Ejemplo n.º 2
0
  def testElementCallbackScreenReceived(self):
    resource_dir = tempfile.mkdtemp()
    http_client = MockFaseHTTPClient(self, resource_dir)
    ui = MockFaseUI(self)
    resource_manager = fase_resource_manager.FaseResourceManager(resource_dir, http_client)
    client = fase_client.FaseClient(http_client=http_client, ui=ui, resource_manager=resource_manager)

    service = ClientTestService()
    screen = service.OnStart()

    http_client.service = service
    http_client.screen = screen
    http_client.session_info = fase_model.SessionInfo(service.GetSessionId())
    http_client.screen_info = fase_model.ScreenInfo(screen.GetScreenId())
    ui.expected_screen = screen
    client.Run()
    self.assertEqual(1, http_client.get_service_calls)
    self.assertEqual(1, ui.draw_screen_calls)
    
    screen.GetElement(id_='text_name_id').Update('Hanry Ford')
    screen = (getattr(screen.GetElement(id_='next_button_id'), fase.ON_CLICK_METHOD)
              (service, screen, screen.GetElement(id_='next_button_id')))
    http_client.screen = screen
    client.ScreenUpdate()
    time.sleep(0.1)
    self.assertEqual(1, http_client.screen_update_calls)

    ui.expected_screen = screen
    client.ElementCallback(id_list=['next_button_id'], method=fase.ON_CLICK_METHOD)
    self.assertEqual(2, ui.draw_screen_calls)
    self.assertEqual(0, ui.element_updated_received_calls)
Ejemplo n.º 3
0
def screenupdate():
    version_info = fase_model.VersionInfo(
        version=request.headers.get('version', None))
    session_info = fase_model.SessionInfo(
        session_id=request.headers.get('session_id', None))
    screen_info = fase_model.ScreenInfo(
        screen_id=request.headers.get('screen_id', None))
    screen_update_simple = request.get_json(force=True)
    screen_update = fase_model.ScreenUpdate.FromSimple(screen_update_simple)
    response_simple, code = SafeCall(fase_server.FaseServer.Get().ScreenUpdate,
                                     screen_update, version_info, session_info,
                                     screen_info)
    response_simple = CleanSimple(response_simple)
    return jsonify(**response_simple), code
Ejemplo n.º 4
0
def elementcallback():
    version_info = fase_model.VersionInfo(
        version=request.headers.get('version', None))
    session_info = fase_model.SessionInfo(
        session_id=request.headers.get('session_id', None))
    screen_info = fase_model.ScreenInfo(
        screen_id=request.headers.get('screen_id', None))
    element_callback_simple = request.get_json(force=True)
    element_callback = fase_model.ElementCallback.FromSimple(
        element_callback_simple)
    response_simple, code = SafeCall(
        fase_server.FaseServer.Get().ElementCallback, element_callback,
        version_info, session_info, screen_info)
    response_simple = CleanSimple(response_simple)
    return jsonify(**response_simple), code
Ejemplo n.º 5
0
 def _AssertServiceUpdateScreen(self, response_updated, session_info):
     service_prog = fase_database.FaseDatabaseInterface.Get(
     ).GetServiceProg(session_info.session_id)
     screen_prog_updated = fase_database.FaseDatabaseInterface.Get(
     ).GetScreenProg(session_info.session_id)
     screen_id_updated = screen_prog_updated.screen._screen_id
     expected_screen = FaseServerTest._GetUpdateScreen(service_prog.service)
     expected_screen._screen_id = screen_id_updated
     self.assertEqual(expected_screen, screen_prog_updated.screen)
     self.assertEqual(expected_screen, response_updated.screen)
     self.assertEqual([], response_updated.resources.resource_list)
     self.assertTrue(response_updated.resources.reset_resources)
     self.assertIsNone(response_updated.elements_update)
     self.assertEqual(session_info, response_updated.session_info)
     self.assertEqual(fase_model.ScreenInfo(screen_id=screen_id_updated),
                      response_updated.screen_info)
Ejemplo n.º 6
0
  def testGetService(self):
    resource_dir = tempfile.mkdtemp()
    http_client = MockFaseHTTPClient(self, resource_dir)
    ui = MockFaseUI(self)
    resource_manager = fase_resource_manager.FaseResourceManager(resource_dir, http_client)
    client = fase_client.FaseClient(http_client=http_client, ui=ui, resource_manager=resource_manager)

    service = ClientTestService()
    screen = service.OnStart()

    http_client.service = service
    http_client.screen = screen
    http_client.resources = fase_model.Resources(resource_list=[fase_model.Resource(filename='a')])
    http_client.session_info = fase_model.SessionInfo(service.GetSessionId())
    http_client.screen_info = fase_model.ScreenInfo(screen.GetScreenId())
    ui.expected_screen = screen
    client.Run()
    self.assertEqual(1, http_client.get_service_calls)
    self.assertEqual(1, http_client.get_resource_filename_calls)
    self.assertEqual(1, ui.draw_screen_calls)
Ejemplo n.º 7
0
 def testScreenUpdateAndElementCallback(self):
   self.requests_bkp = fase_http_client.requests 
   fase_http_client.requests = MockRequests(self) 
   
   http_client = fase_http_client.FaseHTTPClient(MOCK_URL)
   device = fase_model.Device(device_type='MockType', device_id='MockDeviceID')
   session_info = fase_model.SessionInfo(session_id='MockSessionId')
   screen_info = fase_model.ScreenInfo(screen_id='MockScreenId')
   response = fase_model.Response()
   for url_method, http_client_method in [('/screenupdate', http_client.ScreenUpdate),
                                          ('/elementcallback', http_client.ElementCallback)]:
     fase_http_client.requests.expected_url = MOCK_URL + url_method
     fase_http_client.requests.expected_headers = {
         'session-id': session_info.session_id, 'screen-id': screen_info.screen_id}
     fase_http_client.requests.expected_json = device.ToSimple()
     fase_http_client.requests.response = response
     actual_response = http_client_method(device, session_info, screen_info)
     self.assertEqual(response, actual_response)
 
   fase_http_client.requests = self.requests_bkp