def __init__(self, experiment_name): super(InitialPlaylistSlideLauncher, self).__init__(experiment_name) instructions = self.experiment.current_version.playlist.instructions if instructions: rendered_instructions\ = [rst2innerhtml(instruction) for instruction in instructions] self.template_data['instructions'] = rendered_instructions self.template_data['experiment_start_status'] = 'initial'
def welcome(request): ''' The main landing page for the experiments website. ''' welcome_info\ = configobj.ConfigObj(os.path.join(settings.WILHELM_ROOT, 'apps/front/flatfiles/welcome.cfg')) welcome_blurbs = [] for welcome_blurb_key, welcome_blurb in welcome_info.iteritems(): welcome_blurbs.append((welcome_blurb['title'], rst2innerhtml(welcome_blurb['short-text']), )) context = {'title': 'Cognition Experiments', 'welcome_blurbs': welcome_blurbs} return http_response(request, 'front/welcome.html', context)
def listing(request): ''' Return a page listing all available experiments. ''' projects = models.Project.objects.all() project_list = [] for project in projects: project_list.append( dict(url = project.experiment.name, name = project.experiment.class_name, title = project.experiment.title, blurb = rst2innerhtml(project.blurb)) ) context = dict(title = 'Experiment List', projects = project_list) return http_response(request, 'research/listing.html', context)
def listing(request): ''' Return a page listing all available experiments. ''' experiments = models.Experiment.objects.filter(live=True) experiment_list = [] for experiment in experiments: experiment_list.append( dict(url = experiment.name, name = experiment.class_name, title = experiment.title, blurb = rst2innerhtml(experiment.blurb)) ) context = dict(title = 'Experiment List', experiments = experiment_list) return http_response(request, 'archives/listing.html', context)
def blurb(request, blurb_type): ''' The view for the blurb pages. These pages present general info about the site and their content is stored in text files as restructuredText.''' blurb_types = dict(about='about.cfg', takingpart='takingpart.cfg', privacy='privacy.cfg') _blurb = configobj.ConfigObj(os.path.join(settings.WILHELM_ROOT, 'apps/front/flatfiles', blurb_types[blurb_type])) blurb = dict(title = _blurb['title'], text = rst2innerhtml(_blurb['text'])) context = {'title': 'Cognition Experiments', 'blurb': blurb} return http_response(request, 'front/blurb.html', context)
def test_instructions(self): """ Test if the instructions are correct and are displayed properly, i.e. one page at a time. """ def test_is_instruction_page_displayed(instruction_pages, displayed=(True, False, False)): """ A convenience function to test which instructions page is currently being displayed. """ for instruction_page, page_displayed in zip(instruction_pages, displayed): self.assertEquals(instruction_page.is_displayed(), page_displayed) def test_is_button_displayed(buttons, displayed=(True, False, False)): """ A convenience function to test which button is displayed. """ for button, button_displayed in zip(buttons, displayed): self.assertEquals(button.is_displayed(), button_displayed) #===================================================================== # Retrieve the true instructions from the Playlist model. #===================================================================== instructions = self._test_get_experiment_instructions() rendered_instructions\ = [rst2innerhtml(instruction) for instruction in instructions] #===================================================================== # Get the instructions list from the webpage. #===================================================================== self._test_signup_new_user() self.driver.get( self.live_server_url + '/{0}'.format(self.experiment_name) ) wait(1.0) instruction_items\ = self.driver.find_element_by_class_name('InstructionBox')\ .find_element_by_tag_name('ol')\ .find_elements_by_tag_name('li') # Do we have the correct number of instructions? self.assertEqual(len(instruction_items), len(rendered_instructions)) # Is the content of the instructions correct? for instruction_item, rendered_instruction\ in zip(instruction_items, rendered_instructions): self.assertEquals(instruction_item.get_attribute('innerHTML'), rendered_instruction) # Is only the first page actually displayed? test_is_instruction_page_displayed(instruction_items, (True, False, False)) # Are there three buttons? # = self.driver.find_element_by_class_name('ButtonBox')\ # .find_elements_by_class_name('button') buttons\ = self.driver.find_element_by_id('instructions-nav-buttons')\ .find_elements_by_class_name('button') self.assertEqual(len(buttons), 3) # Are they Previous, Next and Start Experiment, in that order? for button, label in zip(buttons, ['Previous', 'Next', 'Start Experiment']): self.assertEqual(button.get_attribute('innerHTML'), label) # But only Next is visible? test_is_button_displayed(buttons, (False, True, False)) #===================================================================== # Walk through the instructions pages. #===================================================================== def click_next(): self.driver.find_element_by_id('next-instruction').click() wait(0.5) def click_previous(): self.driver.find_element_by_id('previous-instruction').click() wait(0.5) # Forward one page ... click_next() # Now is only the second page displayed? test_is_instruction_page_displayed(instruction_items, (False, True, False)) # The Previous and Next buttons should be displayed. test_is_button_displayed(buttons, (True, True, False)) # Forward one more page ... click_next() # Now is only the third page displayed? test_is_instruction_page_displayed(instruction_items, (False, False, True)) # The Previous and Start Experiment buttons should be displayed. test_is_button_displayed(buttons, (True, False, True)) # Back one page ... click_previous() # Now is only the second page displayed? test_is_instruction_page_displayed(instruction_items, (False, True, False)) # The Previous and Next buttons should be displayed. test_is_button_displayed(buttons, (True, True, False)) # Back one more page ... click_previous() # Now is only the first page displayed? test_is_instruction_page_displayed(instruction_items, (True, False, False)) # Only the Previous button should be displayed. test_is_button_displayed(buttons, (False, True, False)) #===================================================================== # A random walk through the instructions pages. #===================================================================== page_and_button_display_conditions\ = (((True, False, False), (False, True, False)), ((False, True, False), (True, True, False)), ((False, False, True), (True, False, True))) def test_page_and_buttons(page=0): page_display, button_display\ = page_and_button_display_conditions[page] test_is_instruction_page_displayed(instruction_items, page_display) test_is_button_displayed(buttons, button_display) def forward(page=0): if page < 2: wait(0.5) click_next() page +=1 test_page_and_buttons(page) return page def back(page=2): if page > 0: wait(0.5) click_previous() page -=1 test_page_and_buttons(page) return page page = 0 for _ in xrange(100): movement = random.choice([forward, back]) page = movement(page) self.driver.get(self.live_server_url) self.wilhelmlogout()