def tearDown(self):
     responses = PollBase.get_poll_responses_ids(self.browser, self.poll_id)
     for response in responses:
         delete_responses_url = build_url('/polls/responses/%s/delete/' %
                                          response.value)
         post(self.opener, delete_responses_url)
     PollBase.close_poll(self.poll_id)
    def test_that_a_response_can_be_replied_to_an_ureporter(self):
        message = "Hello"
        PollBase.start_poll(self.browser,self.poll_id)
        number_of_responses = PollBase.respond_to_the_started_poll("0794339344", "yes")
        self.assert_that_number_of_responses_increase_by(number_of_responses, 1)

        PollBase.reply_poll_to_an_ureporter(self.poll_id, message)
        self.assert_that_message_has_been_sent_out_to_ureporter(message)
    def test_that_poll_responses_are_shown_up_at_report_page(self):
        PollBase.start_poll(self.browser,self.poll_id)

        PollBase.respond_to_the_started_poll("0794339344", "yes")
        SplinterWrapper.open('/polls/%s/report/' % self.poll_id)
        self.assert_that_question_is(self.question)
        self.assert_the_number_of_participants_of_the_poll_is(1)

        self.assert_that_response_location_is("Kasese")
        self.assert_that_number_of_responses_is(1)
    def test_that_a_response_can_be_replied_to_an_ureporter(self):
        message = "Hello"
        PollBase.start_poll(self.browser, self.poll_id)
        number_of_responses = PollBase.respond_to_the_started_poll(
            "0794339344", "yes")
        self.assert_that_number_of_responses_increase_by(
            number_of_responses, 1)

        PollBase.reply_poll_to_an_ureporter(self.poll_id, message)
        self.assert_that_message_has_been_sent_out_to_ureporter(message)
    def test_that_poll_responses_are_shown_up_at_report_page(self):
        PollBase.start_poll(self.browser, self.poll_id)

        PollBase.respond_to_the_started_poll("0794339344", "yes")
        SplinterWrapper.open('/polls/%s/report/' % self.poll_id)
        self.assert_that_question_is(self.question)
        self.assert_the_number_of_participants_of_the_poll_is(1)

        self.assert_that_response_location_is("Kasese")
        self.assert_that_number_of_responses_is(1)
    def test_that_a_poll_response_can_be_reassigned_to_another_poll(self):
        second_poll_id = PollBase.create_poll(self.browser,name='Second Poll',type="Yes/No Question",question="Is the first poll working?",group="groupFT")
        PollBase.start_poll(self.browser,second_poll_id)

        PollBase.respond_to_the_started_poll("0794339344", "yes")
        PollBase.close_poll(second_poll_id)

        PollBase.reassign_poll_response(second_poll_id,self.poll_id)
        time.sleep(2) #Takes a time for a poll to be reassigned
        PollBase.start_poll(self.browser,self.poll_id)

        SplinterWrapper.open('/polls/%s/report/' % self.poll_id)
        self.assert_that_number_of_responses_is(1)
 def setUpClass(cls):
     AdminBase.log_in_as_ureport()
     cls.poll_id, cls.question = PollBase.setup_poll(cls.browser,question="This is a new poll.")
     AdminBase.change_users_group("groupFT")
     cls.opener = login_as_admin('ureport','ureport')
 def tearDown(self):
     responses = PollBase.get_poll_responses_ids(self.browser, self.poll_id)
     for response in responses:
         delete_responses_url = build_url('/polls/responses/%s/delete/' % response.value)
         post(self.opener, delete_responses_url)
     PollBase.close_poll(self.poll_id)
class PollFlowTest(unittest.TestCase,PollBase,PollAssertions):
    browser = SplinterWrapper.getBrowser()
    AdminBase.log_in_as_ureport()
    poll_id, question = PollBase.setup_poll(browser)
    opener = login_as_admin('ureport','ureport')

    @classmethod
    def setUpClass(cls):
        PollBase.start_poll(cls.browser,cls.poll_id)
        AdminBase.change_users_group("groupFT")

    @classmethod
    def cleanup(cls, url):
        SplinterWrapper.open(url)
        if cls.browser.is_element_present_by_id("action-toggle"):
            fill_form(cls.browser, {"action-toggle": True})
            fill_form_and_submit(cls.browser, {"action": "delete_selected"}, "index", True, True)
            cls.browser.find_by_value("Yes, I'm sure").first.click()

    @classmethod
    def delete_poll(cls):
        delete_url = build_url('/polls/%s/delete/' % cls.poll_id)
        post(cls.opener, delete_url)

    def tearDown(self):
        responses = PollBase.get_poll_responses_ids(self.browser, self.poll_id)
        for response in responses:
            delete_responses_url = build_url('/polls/responses/%s/delete/' % response.value)
            post(self.opener, delete_responses_url)

    @classmethod
    def tearDownClass(cls):
        cls.delete_poll()
        cls.cleanup("/admin/rapidsms/connection/")
        cls.cleanup("/admin/rapidsms/backend/")
        cls.cleanup("/admin/rapidsms/contact/")
        cls.cleanup("/admin/auth/group/")
        SplinterWrapper.open('/account/logout')

    def test_that_poll_status_changes_when_started(self):
        SplinterWrapper.open("/poll_status/%s" % self.poll_id)
        self.assert_that_poll_start_date_is_not_none(self.poll_id)

    def test_that_poll_can_be_sent_out_to_contacts(self):
         self.assert_that_poll_question_are_sent_out_to_contacts(1, 'What is your name')

    def test_that_polls_can_be_responded(self):
        SplinterWrapper.open('/router/console/')
        number_of_responses = len(rows_of_table_by_class(self.browser, "messages module"))
        self.respond_to_the_started_poll("0794339344", "yes")

        self.assert_that_number_of_responses_increase_by(number_of_responses, 1)

    def test_that_polls_can_be_reopen(self):
        SplinterWrapper.open("/view_poll/%s" % self.poll_id)
        PollBase.close_poll(self.poll_id)
        self.browser.find_link_by_text('Reopen Poll').first.click()

        self.assert_that_poll_end_date_is_none(self.poll_id)

    def test_that_admin_is_able_to_add_new_poll(self):
        SplinterWrapper.open('/mypolls/%s' % self.poll_id)
        self.assert_that_page_has_add_poll_button()

    def test_should_show_the_status_page(self):
        SplinterWrapper.open("/poll_status/%s" % self.poll_id)

        self.assertEqual(self.browser.is_element_present_by_id('poll-details'), True)
        self.assertTrue(self.poll_id in self.browser.find_by_id("poll-details").first.text)
        self.assertEqual(self.browser.find_by_id('contact-count').text, "1")
        self.assertEqual(self.browser.find_by_id('category-count').text, "3")
        self.assertEqual(self.browser.find_by_id('is-yesno').text, "yes")

    def test_admin_can_search_for_ureporter(self):
        group_name = "groupFT"
        self.respond_to_the_started_poll("0794339344", "yes")
        SplinterWrapper.open( '/reporter/')
        self.search_by_ureporter_group("%s" % group_name)
        self.assertEquals(True, self.browser.is_text_present("0794339344"))

    def search_by_ureporter_group(self, group_name):
        element_list_matching_option = self.browser.find_option_by_text(group_name)
        self.browser.select("groups", element_list_matching_option.first.value)
        self.browser.click_link_by_partial_text("Update")
        return self
    def test_that_polls_can_be_reopen(self):
        SplinterWrapper.open("/view_poll/%s" % self.poll_id)
        PollBase.close_poll(self.poll_id)
        self.browser.find_link_by_text('Reopen Poll').first.click()

        self.assert_that_poll_end_date_is_none(self.poll_id)
 def setUpClass(cls):
     PollBase.start_poll(cls.browser,cls.poll_id)
     AdminBase.change_users_group("groupFT")
    def test_that_a_poll_response_can_be_reassigned_to_another_poll(self):
        second_poll_id = PollBase.create_poll(
            self.browser,
            name='Second Poll',
            type="Yes/No Question",
            question="Is the first poll working?",
            group="groupFT")
        PollBase.start_poll(self.browser, second_poll_id)

        PollBase.respond_to_the_started_poll("0794339344", "yes")
        PollBase.close_poll(second_poll_id)

        PollBase.reassign_poll_response(second_poll_id, self.poll_id)
        time.sleep(2)  #Takes a time for a poll to be reassigned
        PollBase.start_poll(self.browser, self.poll_id)

        SplinterWrapper.open('/polls/%s/report/' % self.poll_id)
        self.assert_that_number_of_responses_is(1)
 def setUpClass(cls):
     AdminBase.log_in_as_ureport()
     cls.poll_id, cls.question = PollBase.setup_poll(
         cls.browser, question="This is a new poll.")
     AdminBase.change_users_group("groupFT")
     cls.opener = login_as_admin('ureport', 'ureport')