コード例 #1
0
    def _test_signup_new_user(self):

        """
        Create a new user and log them in.

        """

        self.username = rndemail()
        first_name = rndstring(10)
        password = rndpasswd(10)

        user = User.objects.create_user(username=self.username,
                                        first_name=first_name,
                                        email=self.username,
                                        password=password)

        Subject.objects.create_subject(user)

        signed_in_as = self.wilhelmlogin(self.username, password)

        self.assertIn(self.username, signed_in_as.text)
コード例 #2
0
    def subtest_wordrecallwidget(self):

        recallmemorytest_box_xpath\
            = "//div[@id='recalltest_widget']"

        start_box_xpath\
            = recallmemorytest_box_xpath + "//div[@id='StartBox']"

        instruction_box_xpath\
            = start_box_xpath + "/div[@id='InstruxtionBox']"

        start_button_xpath\
            = start_box_xpath + "//span[@id='StartButton']"

        stimulus_box_xpath\
            = recallmemorytest_box_xpath + "//div[@id='StimulusBox']"

        recalledwords_box_xpath\
            = stimulus_box_xpath + "//div[@id='recalledwordsbox']"

        recalledwordslist_box_xpath\
            = recalledwords_box_xpath + "//ol[@id='recalledwordslist']"

        morelessoptions_xpath\
            = recalledwords_box_xpath + "//div[@id='morelessoptions']"

        lessoptions_xpath\
            = morelessoptions_xpath + "/span[@id='lessoptionsbutton']"

        moreoptions_xpath\
            = morelessoptions_xpath + "/span[@id='moreoptionsbutton']"

        results_box\
           = recalledwords_box_xpath + "//div[@id='results']"

        submit_results_box\
            = results_box + "/span[@id='submitresults']"

        finish_box_xpath\
            = recallmemorytest_box_xpath + "//div[@id='FinishBox']"

        finish_msg_xpath\
            = finish_box_xpath + "/p[@id='FinishMsg']"


        self.assertTrue(
            all_visible(self.driver,
                        (recallmemorytest_box_xpath,
                         start_box_xpath,
                         instruction_box_xpath,
                         start_button_xpath))
        )


        self.assertTrue(
            none_visible(self.driver,
                         (stimulus_box_xpath,
                          recalledwords_box_xpath,
                          morelessoptions_xpath,
                          results_box,
                          submit_results_box,
                          finish_box_xpath,
                          finish_msg_xpath,
                          recalledwordslist_box_xpath))
        )

        self.driver.find_element_by_xpath(start_button_xpath).click()

        wait(5)

        self.assertTrue(
            all_visible(self.driver,
                         (recallmemorytest_box_xpath,
                          stimulus_box_xpath,
                          recalledwords_box_xpath,
                          results_box,
                          submit_results_box,
                          morelessoptions_xpath,
                          lessoptions_xpath,
                          moreoptions_xpath,
                          recalledwordslist_box_xpath))
        )

        self.assertTrue(
            none_visible(self.driver,
                        (start_box_xpath,
                         instruction_box_xpath,
                         finish_msg_xpath, 
                         finish_box_xpath,
                         start_button_xpath))
        )


        items\
            = self.driver.find_element_by_xpath(recalledwordslist_box_xpath)\
            .find_elements_by_tag_name('li')

        # TODO (Fri 29 May 2015 03:28:32 BST): Deal with this
        magic_number = 10 

        self.assertEqual(len(items), magic_number)

        less_button = self.driver.find_element_by_xpath(lessoptions_xpath)
        more_button = self.driver.find_element_by_xpath(moreoptions_xpath)

        less_button.click()

        items\
            = self.driver.find_element_by_xpath(recalledwordslist_box_xpath)\
            .find_elements_by_tag_name('li')

        self.assertEqual(len(items), magic_number-1)

        less_button.click()

        items\
            = self.driver.find_element_by_xpath(recalledwordslist_box_xpath)\
            .find_elements_by_tag_name('li')

        self.assertEqual(len(items), magic_number-2)

        more_button.click()

        items\
            = self.driver.find_element_by_xpath(recalledwordslist_box_xpath)\
            .find_elements_by_tag_name('li')

        self.assertEqual(len(items), magic_number-1)

        more_button.click()

        items\
            = self.driver.find_element_by_xpath(recalledwordslist_box_xpath)\
            .find_elements_by_tag_name('li')

        self.assertEqual(len(items), magic_number)

        random_words = []
        for item in items[:random.randint(1, len(items)-1)]:
            input_box = item.find_element_by_tag_name('input')
            random_word = rndstring(random.randint(3, 10))
            input_box.send_keys(random_word)
            random_words.append(random_word)

        wait(2)

        self.driver.find_element_by_xpath(submit_results_box).click()

        wait_until_element_displayed(self.driver, 
                                     finish_msg_xpath,
                                     attribute_type='xpath')

        self.assertTrue(
            all_visible(self.driver,
                        (finish_msg_xpath, finish_box_xpath))
        )

        items\
            = self.driver.find_element_by_xpath(finish_box_xpath)\
            .find_element_by_tag_name('ol')\
            .find_elements_by_tag_name('li')

        self.assertEqual(len(items), len(random_words))

        for random_word, item in zip(random_words, items):
            self.assertEqual(random_word, item.text)

        presentation_widget, response_widget\
            = self.get_session_widgets()

        self.assertEqual(random_words, response_widget.recalledwords)