예제 #1
0
    def testServiceElementCallbackScreenInfoObsolete(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

        element_callback = (fase_model.ElementCallback(
            id_list=['next_button_id'],
            method=fase.ON_CLICK_METHOD,
            device=device))
        response_click_again = fase_server.FaseServer.Get().ElementCallback(
            element_callback, version_info, session_info,
            screen_info_entered_name)
        self.assertEqual(screen_clicked_next, response_click_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_click_again.resources.resource_list))
        self.assertIsNone(response_click_again.elements_update)
        self.assertEqual(session_info, response_click_again.session_info)
        self.assertEqual(screen_info_clicked_next,
                         response_click_again.screen_info)
예제 #2
0
    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)
예제 #3
0
    def _GetServiceAndAssert(self, device, get_screen_and_assert=True):
        response = fase_server.FaseServer.Get().GetService(device)
        version_info = response.version_info
        session_info = response.session_info
        screen_info = response.screen_info
        service_prog = fase_database.FaseDatabaseInterface.Get(
        ).GetServiceProg(session_info.session_id)
        expected_screen = FaseServerTest._GetEnterNameScreen(
            service_prog.service)
        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.logo_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._GetScreenProgAndAssert(session_info,
                                     expected_screen=expected_screen,
                                     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)
        return version_info, session_info, screen_info
예제 #4
0
  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'))
예제 #5
0
    def testServiceUpdateDevice(self):
        device = fase_model.Device(device_type='MockType',
                                   device_id='MockDeviceID',
                                   device_token='Token1')
        version_info, session_info, screen_info = self._GetServiceAndAssert(
            device)
        self._AssertDevice(device, session_info)

        device = fase_model.Device(device_type='MockType',
                                   device_id='MockDeviceID',
                                   device_token='Token2')
        service_prog = fase_database.FaseDatabaseInterface.Get(
        ).GetServiceProg(session_info.session_id)
        expected_screen = FaseServerTest._GetEnterNameScreen(
            service_prog.service)
        expected_screen._screen_id = screen_info.screen_id
        expected_resources = fase_model.Resources(
            resource_list=[fase_model.Resource(filename=self.logo_filename)])
        self._GetScreenAndAssert(device,
                                 version_info,
                                 session_info,
                                 screen_info,
                                 expected_screen=expected_screen,
                                 expected_resources=expected_resources)
        self._AssertDevice(device, session_info)

        device = fase_model.Device(device_type='MockType',
                                   device_id='MockDeviceID',
                                   device_token='Token3')
        self._EnterNameAndAssert('Henry Ford', device, version_info,
                                 session_info, screen_info)
        self._AssertDevice(device, session_info)

        device = fase_model.Device(device_type='MockType',
                                   device_id='MockDeviceID',
                                   device_token='Token4')
        screen_info = self._EnterNextAndAssert('Henry Ford', device,
                                               version_info, session_info,
                                               screen_info)
        self._AssertDevice(device, session_info)

        device = fase_model.Device(device_type='MockType',
                                   device_id='MockDeviceID',
                                   device_token='Token5')
        self._EnterResetAndAssert(device, version_info, session_info,
                                  screen_info)
        self._AssertDevice(device, session_info)
예제 #6
0
 def _AssertDeviceUpdateScreen(self, response_updated, session_info,
                               screen_info_clicked_next):
     screen_info_updated = response_updated.screen_info
     self.assertEqual(screen_info_clicked_next, screen_info_updated)
     service_prog_updated = fase_database.FaseDatabaseInterface.Get(
     ).GetServiceProg(session_info.session_id)
     expected_screen = FaseServerTest._GetGreetingScreen(
         service_prog_updated.service, 'Henry Ford')
     expected_screen._screen_id = screen_info_updated.screen_id
     self.assertEqual(expected_screen, response_updated.screen)
     expected_resources = fase_model.Resources(
         resource_list=[fase_model.Resource(filename=self.hello_filename)])
     self.assertEqual(set(expected_resources.resource_list),
                      set(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)
예제 #7
0
    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)
예제 #8
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)
예제 #9
0
    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)
예제 #10
0
    def _EnterNextAndAssert(self,
                            name,
                            device,
                            version_info,
                            session_info,
                            screen_info,
                            get_screen_and_assert=True):
        element_callback = (fase_model.ElementCallback(
            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, name)
        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)
        if get_screen_and_assert:
            self._GetScreenAndAssert(device,
                                     version_info,
                                     session_info,
                                     screen_info,
                                     expected_screen=expected_screen,
                                     expected_resources=expected_resources)
        return screen_info
예제 #11
0
    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)