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 testServiceScreenUpdateDeviceVersionObsolete(self): previous_version = ServerTestService.version ServerTestService.version = '2' device = fase_model.Device(device_type='MockType', device_id='MockDeviceID') version_info, session_info, screen_info_entered_name = self._GetServiceAndAssert( device) self._EnterNameAndAssert('Henry Ford', device, version_info, session_info, screen_info_entered_name) screen_info_clicked_next = self._EnterNextAndAssert( 'Henry Ford', device, version_info, session_info, screen_info_entered_name) version_info = fase_model.VersionInfo(version=previous_version) elements_update = fase_model.ElementsUpdate([['text_name_id']], ['Howard Hughes']) screen_update = fase_model.ScreenUpdate( elements_update=elements_update, device=device) response_updated = fase_server.FaseServer.Get().ScreenUpdate( screen_update, version_info, session_info, screen_info_entered_name) self._AssertDeviceUpdateScreen(response_updated, session_info, screen_info_clicked_next) ServerTestService.version = previous_version
def AddNote(self, version_info, session_info, screen_info, note): # Click on New button. response = fase_server.FaseServer.Get().ElementCallback( fase_model.ElementCallback(id_list=[fase.MAIN_BUTTON_ID], method=fase.ON_CLICK_METHOD, device=self.device), version_info, session_info, screen_info) version_info = response.screen_info session_info = response.session_info screen_info = response.screen_info screen = response.screen # Check present of main elements. screen.GetElement(id_='note_frame') # Enter note. elements_update=fase_model.ElementsUpdate([['note_frame', 'header_text'], ['note_frame', 'text_text']], [note.header, note.text]) screen_update = fase_model.ScreenUpdate(elements_update=elements_update, device=self.device) fase_server.FaseServer.Get().ScreenUpdate(screen_update, version_info, session_info, screen_info) # Click on Save button. response = fase_server.FaseServer.Get().ElementCallback( fase_model.ElementCallback(id_list=[fase.NEXT_STEP_BUTTON_ID], method=fase.ON_CLICK_METHOD, device=self.device), version_info, session_info, screen_info) version_info = response.screen_info session_info = response.session_info screen_info = response.screen_info screen = response.screen # Check present of main elements. screen.GetElement(id_='notes_frame') return version_info, session_info, screen_info, screen
def testServiceScreenUpdateScreenInfoObsolete(self): device = fase_model.Device(device_type='MockType', device_id='MockDeviceID') version_info, session_info, screen_info_entered_name = self._GetServiceAndAssert( device) self._EnterNameAndAssert('Henry Ford', device, version_info, session_info, screen_info_entered_name) screen_info_clicked_next = self._EnterNextAndAssert( 'Henry Ford', device, version_info, session_info, screen_info_entered_name) screen_prog_clicked_next = fase_database.FaseDatabaseInterface.Get( ).GetScreenProg(session_info.session_id) screen_clicked_next = screen_prog_clicked_next.screen elements_update = fase_model.ElementsUpdate([['text_name_id']], ['Howard Hughes']) screen_update = fase_model.ScreenUpdate( elements_update=elements_update, device=device) response_enter_name_again = fase_server.FaseServer.Get().ScreenUpdate( screen_update, version_info, session_info, screen_info_entered_name) self.assertEqual(screen_clicked_next, response_enter_name_again.screen) expected_resources = fase_model.Resources( resource_list=[fase_model.Resource(filename=self.hello_filename)]) self.assertEqual( set(expected_resources.resource_list), set(response_enter_name_again.resources.resource_list)) self.assertIsNone(response_enter_name_again.elements_update) self.assertEqual(session_info, response_enter_name_again.session_info) self.assertEqual(screen_info_clicked_next, response_enter_name_again.screen_info)
def testService(self): device = fase_model.Device(device_type='MockType', device_id='MockDeviceID') response = self._GetService(device) session_info = response.session_info screen_info = response.screen_info service_prog = fase_database.FaseDatabaseInterface.Get( ).GetServiceProg(session_info.session_id) expected_screen = ApplicationTest._GetEnterNameScreen( service_prog.service) expected_screen._screen_id = screen_info.screen_id self.assertEqual(expected_screen, response.screen) response = self._GetScreen(device, session_info) self.assertEqual(expected_screen, response.screen) elements_update = fase_model.ElementsUpdate([['text_name_id']], ['Hanry Ford']) screen_update = fase_model.ScreenUpdate( elements_update=elements_update, device=device) response = self._ScreenUpdate(screen_update, session_info, screen_info) expected_screen = ApplicationTest._GetEnterNameScreen( service_prog.service, name='Hanry Ford') expected_screen._screen_id = screen_info.screen_id self.assertIsNone(response.screen) response = self._GetScreen(device, session_info) self.assertEqual(expected_screen, response.screen) element_callback = (fase_model.ElementCallback( id_list=['next_button_id'], method=fase.ON_CLICK_METHOD, device=device)) response = self._ElementCallback(element_callback, session_info, screen_info) screen_info = response.screen_info expected_screen = ApplicationTest._GetGreetingScreen( service_prog.service, name='Hanry Ford') expected_screen._screen_id = screen_info.screen_id self.assertEqual(expected_screen, response.screen) response = self._GetScreen(device, session_info) self.assertEqual(expected_screen, response.screen) element_callback = (fase_model.ElementCallback( id_list=['reset_button_id'], method=fase.ON_CLICK_METHOD, device=device)) response = self._ElementCallback(element_callback, session_info, screen_info) screen_info = response.screen_info expected_screen = ApplicationTest._GetEnterNameScreen( service_prog.service) expected_screen._screen_id = screen_info.screen_id self.assertEqual(expected_screen, response.screen) response = self._GetScreen(device, session_info) self.assertEqual(expected_screen, response.screen)
def testServiceUpdateElementsEmpty(self): device = fase_model.Device(device_type='MockType', device_id='MockDeviceID') version_info, session_info, screen_info = self._GetServiceAndAssert( device) # Enter name and assert update in database. self._EnterNameAndAssert('Henry Ford', device, version_info, session_info, screen_info) screen_prog = fase_database.FaseDatabaseInterface.Get().GetScreenProg( session_info.session_id) expected_elements_update = fase_model.ElementsUpdate( [['text_name_id']], ['Henry Ford']) self.assertEqual(expected_elements_update, screen_prog.elements_update) # Clean name and assert update has been deleted from database. elements_update = fase_model.ElementsUpdate([['text_name_id']], ['']) screen_update = fase_model.ScreenUpdate( elements_update=elements_update, device=device) fase_server.FaseServer.Get().ScreenUpdate(screen_update, version_info, session_info, screen_info) screen_prog = fase_database.FaseDatabaseInterface.Get().GetScreenProg( session_info.session_id) expected_elements_update = fase_model.ElementsUpdate( [['text_name_id']], ['']) self.assertEqual(expected_elements_update, screen_prog.elements_update)
def testServiceElementCallbackWithElementsUpdate(self): device = fase_model.Device(device_type='MockType', device_id='MockDeviceID') version_info, session_info, screen_info = self._GetServiceAndAssert( device) elements_update = fase_model.ElementsUpdate([['text_name_id']], ['Henry Ford']) element_callback = fase_model.ElementCallback( elements_update=elements_update, id_list=['next_button_id'], method=fase.ON_CLICK_METHOD, device=device) response = fase_server.FaseServer.Get().ElementCallback( element_callback, version_info, session_info, screen_info) screen_info = response.screen_info service_prog = fase_database.FaseDatabaseInterface.Get( ).GetServiceProg(session_info.session_id) expected_screen = FaseServerTest._GetGreetingScreen( service_prog.service, 'Henry Ford') expected_screen._screen_id = screen_info.screen_id self.assertEqual(expected_screen, response.screen) expected_resources = fase_model.Resources( resource_list=[fase_model.Resource(filename=self.hello_filename)]) self.assertEqual(set(expected_resources.resource_list), set(response.resources.resource_list)) self.assertFalse(response.resources.reset_resources) self.assertIsNone(response.elements_update) self.assertEqual(session_info, response.session_info) self._GetScreenProgAndAssert(session_info, expected_screen=expected_screen, expected_device=device) self._GetScreenAndAssert(device, version_info, session_info, screen_info, expected_screen=expected_screen, expected_resources=expected_resources) self._EnterResetAndAssert(device, version_info, session_info, screen_info)
def testElementCallbackElementsUpdateReceived(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) screen.GetElement(id_='text_name_id').Update('Hanry Ford') element_callback_screen = (getattr(screen.GetElement(id_='next_button_id'), fase.ON_CLICK_METHOD) (service, screen, screen.GetElement(id_='next_button_id'))) http_client.expected_id_list = ['next_button_id'] http_client.element_callback_screen = element_callback_screen http_client.element_callback_session_info = fase_model.SessionInfo(service.GetSessionId()) http_client.element_callback_screen_info = fase_model.ScreenInfo(element_callback_screen.GetScreenId()) ui.expected_id_list = ['text_name_id'] ui.expected_value = 'Hanry Ford' ui.expected_screen = element_callback_screen client.ElementCallback(id_list=['next_button_id'], method=fase.ON_CLICK_METHOD) self.assertEqual(1, http_client.element_callback_calls) self.assertEqual(2, ui.draw_screen_calls) self.assertEqual(1, ui.element_updated_received_calls)
def testServiceScreenUpdateWithDiffDevice(self): device = fase_model.Device(device_type='MockType', device_id='MockDeviceID') version_info, session_info, screen_info = self._GetServiceAndAssert( device) self._EnterNameAndAssert('Henry Ford', device, version_info, session_info, screen_info) device_2 = fase_model.Device(device_type='MockType', device_id='MockDeviceID2') elements_update = fase_model.ElementsUpdate([['text_name_id']], ['Howard Hughes']) screen_update = fase_model.ScreenUpdate( elements_update=elements_update, device=device_2) response = fase_server.FaseServer.Get().ScreenUpdate( screen_update, version_info, session_info, screen_info) service_prog = fase_database.FaseDatabaseInterface.Get( ).GetServiceProg(session_info.session_id) expected_screen = FaseServerTest._GetEnterNameScreen( service_prog.service, name='Howard Hughes') expected_screen._screen_id = screen_info.screen_id expected_resources = fase_model.Resources( resource_list=[fase_model.Resource(filename=self.logo_filename)]) self.assertIsNone(response.screen) self.assertIsNone(response.resources) self.assertEqual(elements_update, response.elements_update) self.assertEqual(session_info, response.session_info) self.assertEqual(screen_info, response.screen_info) self._GetScreenProgAndAssert(session_info, expected_screen=expected_screen, expected_elements_update=elements_update, expected_device=device_2) self._GetScreenAndAssert(device_2, version_info, session_info, screen_info, expected_screen=expected_screen, expected_resources=expected_resources)
def testNotes_Start_SignIn_EditNote_Cancel(self): version_info, session_info, screen_info, screen = self.Start() self.AssertNotes([], screen) # Sign In. version_info, session_info, screen_info, screen = ( fase_sign_in_test_util.SignInProcedure( version_info, session_info, screen_info, sign_in_id_list=[fase.NAVIGATION_ID, 'sign_in_button'], sign_in=True, phone_number='+13216549870')) self.AssertNotes([self.note_1, self.note_2, self.note_3], screen) # Copy and edit Note. note_2_edited = copy.copy(self.note_2) note_2_edited.header = 'Note 2 Header edited' note_2_edited.text = 'Note 2 text edited' version_info, session_info, screen_info, screen = self.SelectNote( version_info, session_info, screen_info, self.note_2) # Edit Note. elements_update=fase_model.ElementsUpdate([['note_frame', 'header_text'], ['note_frame', 'text_text']], [note_2_edited.header, note_2_edited.text]) screen_update = fase_model.ScreenUpdate(elements_update=elements_update, device=self.device) fase_server.FaseServer.Get().ScreenUpdate(screen_update, version_info, session_info, screen_info) # Click on Cancel button. response = fase_server.FaseServer.Get().ElementCallback( fase_model.ElementCallback(id_list=[fase.PREV_STEP_BUTTON_ID], method=fase.ON_CLICK_METHOD, device=self.device), version_info, session_info, screen_info) version_info = response.version_info session_info = response.session_info screen_info = response.screen_info screen = response.screen # Check present of main elements. screen.GetElement(id_='notes_frame') self.AssertNotes([self.note_1, self.note_2, self.note_3], screen)
def _EnterNameAndAssert(self, name, device, version_info, session_info, screen_info, get_screen_and_assert=True): elements_update = fase_model.ElementsUpdate([['text_name_id']], [name]) screen_update = fase_model.ScreenUpdate( elements_update=elements_update, device=device) response = fase_server.FaseServer.Get().ScreenUpdate( screen_update, version_info, session_info, screen_info) service_prog = fase_database.FaseDatabaseInterface.Get( ).GetServiceProg(session_info.session_id) expected_screen = FaseServerTest._GetEnterNameScreen( service_prog.service, name=name) expected_screen._screen_id = screen_info.screen_id expected_resources = fase_model.Resources( resource_list=[fase_model.Resource(filename=self.logo_filename)]) self.assertIsNone(response.screen) self.assertIsNone(response.resources) self.assertIsNone(response.elements_update) self.assertEqual(session_info, response.session_info) self.assertEqual(screen_info, response.screen_info) self._GetScreenProgAndAssert(session_info, expected_screen=expected_screen, expected_elements_update=elements_update, expected_device=device) if get_screen_and_assert: self._GetScreenAndAssert(device, version_info, session_info, screen_info, expected_screen=expected_screen, expected_resources=expected_resources)