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)
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)
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)
def testGeneral(self): resource_dir = tempfile.mkdtemp() http_client = MockFaseHTTPClient(resource_dir) resource_manager = fase_resource_manager.FaseResourceManager(resource_dir, http_client) self.assertFalse(resource_manager.HasResourceFilename('a')) self.assertFalse(resource_manager.HasResourceFilename('b')) self.assertFalse(resource_manager.HasResourceFilename('c')) self.assertFalse(resource_manager.HasResourceFilename('d')) resource_list = [fase_model.Resource(filename='a'), fase_model.Resource(filename='b')] resources = fase_model.Resources(resource_list=resource_list) resource_manager.PreloadResources(resources) self.assertEqual(2, http_client.get_resource_filename_calls) self.assertTrue(resource_manager.HasResourceFilename('a')) self.assertTrue(resource_manager.HasResourceFilename('b')) self.assertFalse(resource_manager.HasResourceFilename('c')) self.assertFalse(resource_manager.HasResourceFilename('d')) resource_list = [fase_model.Resource(filename='a'), fase_model.Resource(filename='b'), fase_model.Resource(filename='c'), fase_model.Resource(filename='d')] resources = fase_model.Resources(resource_list=resource_list) resource_manager.PreloadResources(resources) self.assertEqual(4, http_client.get_resource_filename_calls) self.assertTrue(resource_manager.HasResourceFilename('a')) self.assertTrue(resource_manager.HasResourceFilename('b')) self.assertTrue(resource_manager.HasResourceFilename('c')) self.assertTrue(resource_manager.HasResourceFilename('d')) resource_list = [fase_model.Resource(filename='b'), fase_model.Resource(filename='c')] resources = fase_model.Resources(resource_list=resource_list) resource_manager.PreloadResources(resources) self.assertEqual(4, http_client.get_resource_filename_calls) self.assertTrue(resource_manager.HasResourceFilename('a')) self.assertTrue(resource_manager.HasResourceFilename('b')) self.assertTrue(resource_manager.HasResourceFilename('c')) self.assertTrue(resource_manager.HasResourceFilename('d'))