Exemplo n.º 1
0
    def add_edit_datasender(self):
        global_navigation = GlobalNavigationPage(self.driver)
        all_data_sender_page = global_navigation.navigate_to_all_data_sender_page(
        )
        add_data_sender_page = all_data_sender_page.navigate_to_add_a_data_sender_page(
        )
        email = generate_random_email_id()
        add_data_sender_page.enter_data_sender_details_from(
            VALID_DATA_WITH_EMAIL, email=email)
        success_msg = add_data_sender_page.get_success_message()
        self.assertIn(fetch_(SUCCESS_MESSAGE, from_(VALID_DATA_WITH_EMAIL)),
                      success_msg)
        add_data_sender_page.navigate_to_datasender_page()
        all_data_sender_page = AllDataSendersPage(self.driver)

        rep_id = success_msg.replace(VALID_DATA_WITH_EMAIL[SUCCESS_MESSAGE],
                                     '')
        all_data_sender_page.select_a_data_sender_by_id(rep_id)

        all_data_sender_page.select_edit_action()
        time.sleep(2)
        edit_datasender_page = AddDataSenderPage(self.driver)
        edit_datasender_page.enter_data_sender_details_from(
            VALID_DATA_WITH_EMAIL_FOR_EDIT)
        self.assertRegexpMatches(
            edit_datasender_page.get_success_message(),
            fetch_(SUCCESS_MSG, from_(VALID_DATA_WITH_EMAIL_FOR_EDIT)))

        edit_datasender_page.navigate_to_datasender_page()
        all_data_sender_page = AllDataSendersPage(self.driver)
        all_data_sender_page.associate_datasender_to_projects(
            rep_id, [self.project_name])
        return email
Exemplo n.º 2
0
    def test_delete_data_sender_and_re_register(self):
        all_data_sender_page = self.page
        self.delete_ds(all_data_sender_page)
        self.assertEqual(all_data_sender_page.get_delete_success_message(),
                         DELETE_SUCCESS_TEXT)
        global_navigation = GlobalNavigationPage(self.driver)
        global_navigation.sign_out()

        sms_tester_page = SMSTesterPage(self.driver)
        self.send_sms(VALID_SMS, sms_tester_page)
        self.assertEqual(sms_tester_page.get_response_message(),
                         SMS_ERROR_MESSAGE)

        self.login()
        self.driver.go_to(DATA_WINNER_CREATE_DATA_SENDERS)
        add_data_sender_page = AddDataSenderPage(self.driver)
        add_data_sender_page.enter_data_sender_details_from(VALID_DATA)
        message = add_data_sender_page.get_success_message()
        self.assertRegexpMatches(message, fetch_(SUCCESS_MSG,
                                                 from_(VALID_DATA)))
        self.assertNotEqual(message.split()[-1],
                            fetch_(UID, from_(DELETE_DATA_SENDER)))
        self.driver.wait_until_modal_dismissed(10)
        global_navigation.sign_out()

        self.send_sms(VALID_SMS, sms_tester_page)
        self.assertEqual(sms_tester_page.get_response_message(),
                         fetch_(SUCCESS_MESSAGE, from_(VALID_SMS)))
        self.login()
Exemplo n.º 3
0
class TestAllDataSenderRegistration(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.driver = setup_driver()
        cls.driver.go_to(DATA_WINNER_LOGIN_PAGE)
        login_page = LoginPage(cls.driver)
        login_page.do_successful_login_with(VALID_CREDENTIALS)

    def setUp(self):
        TestAllDataSenderRegistration.driver.refresh()
        self.driver.go_to(DATA_WINNER_CREATE_DATA_SENDERS)
        self.current_page = AddDataSenderPage(self.driver)

    @classmethod
    def tearDownClass(cls):
        teardown_driver(cls.driver)

    def login_with_created_datasenders_account(self, email):
        global_navigation = GlobalNavigationPage(self.driver)
        global_navigation.sign_out()
        self.driver.go_to(DATA_WINNER_LOGIN_PAGE)
        data_sender_credentials = {USERNAME: email, PASSWORD: "******"}
        login_page = LoginPage(self.driver)
        login_page.login_with(data_sender_credentials)
        message = global_navigation.welcome_message()
        return message

    @attr('functional_test')
    def test_successful_addition_and_editing_of_data_sender(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(VALID_DATA)
        success_msg = add_data_sender_page.get_success_message()
        self.assertRegexpMatches(success_msg,
                                 fetch_(SUCCESS_MSG, from_(VALID_DATA)))
        rep_id = self._parse(success_msg)
        all_data_senders_page = AllDataSendersPage(self.driver)
        all_data_senders_page.load()
        all_data_senders_page.search_with(rep_id)
        all_data_senders_page.select_a_data_sender_by_id(rep_id)
        all_data_senders_page.select_edit_action()
        self.current_page.enter_data_sender_details_from(VALID_EDIT_DATA)
        self.assertRegexpMatches(self.current_page.get_success_message(),
                                 fetch_(SUCCESS_MSG, from_(VALID_EDIT_DATA)))

    @attr('functional_test')
    def test_addition_of_data_sender_without_email_address(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.select_web_device()
        add_data_sender_page.enter_data_sender_details_from(
            VALID_DATA_WITHOUT_EMAIL)

        self.assertRegexpMatches(
            add_data_sender_page.get_error_message(),
            fetch_(ERROR_MSG, from_(VALID_DATA_WITHOUT_EMAIL)))

    @attr('functional_test')
    def test_addition_of_data_sender_without_entering_data(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(BLANK_FIELDS)
        self.assertEqual(add_data_sender_page.get_error_message(),
                         fetch_(ERROR_MSG, from_(BLANK_FIELDS)))
        a = self.driver.switch_to_active_element()
        self.assertEqual(a.get_attribute("id"), u"id_name")

    @attr('functional_test')
    def test_addition_of_data_sender_with_existing_data(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(EXISTING_DATA)

        time.sleep(1)
        self.assertEqual(add_data_sender_page.get_error_message(),
                         fetch_(ERROR_MSG, from_(EXISTING_DATA)))

    @attr('functional_test')
    def test_addition_of_data_sender_without_location_name(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(
            WITHOUT_LOCATION_NAME)
        self.assertRegexpMatches(
            add_data_sender_page.get_success_message(),
            fetch_(SUCCESS_MSG, from_(WITHOUT_LOCATION_NAME)))

    @attr('functional_test')
    def test_addition_of_data_sender_without_gps(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(WITHOUT_GPS)
        self.assertRegexpMatches(add_data_sender_page.get_success_message(),
                                 fetch_(SUCCESS_MSG, from_(WITHOUT_GPS)))

    @attr('functional_test')
    def test_addition_of_data_sender_with_invalid_gps(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(INVALID_GPS)
        self.assertEqual(add_data_sender_page.get_error_message(),
                         fetch_(ERROR_MSG, from_(INVALID_GPS)))

    @attr('functional_test')
    def test_addition_of_data_sender_with_invalid_latitude_gps(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(
            INVALID_LATITUDE_GPS)
        self.assertEqual(add_data_sender_page.get_error_message(),
                         fetch_(ERROR_MSG, from_(INVALID_LATITUDE_GPS)))

    @attr('functional_test')
    def test_addition_of_data_sender_with_invalid_longitude_gps(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(
            INVALID_LONGITUDE_GPS)
        self.assertEqual(add_data_sender_page.get_error_message(),
                         fetch_(ERROR_MSG, from_(INVALID_LONGITUDE_GPS)))

    @attr('functional_test')
    def test_addition_of_data_sender_with_unicode_in_gps(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(
            WITH_UNICODE_IN_GPS)
        self.assertEqual(add_data_sender_page.get_error_message(),
                         fetch_(ERROR_MSG, from_(WITH_UNICODE_IN_GPS)))

    @SkipTest
    def test_addition_of_data_sender_with_invalid_gps_with_comma(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(
            INVALID_GPS_WITH_COMMA)
        self.assertEqual(add_data_sender_page.get_error_message(),
                         fetch_(ERROR_MSG, from_(INVALID_GPS_WITH_COMMA)))

    @attr('functional_test')
    def test_add_datasender_with_long_uid(self):
        add_data_sender_page = self.current_page
        self.driver.find(by_css("#generate_id")).click()
        self.driver.find_text_box(
            by_css("#id_short_code")).enter_text("rep012345678901234567891")
        short_code = self.driver.find(
            by_css("#id_short_code")).get_attribute('value')
        self.assertEquals(len(short_code), 12)

    def assert_fields_are_populated_properly_in_edit_page(
            self, valid_registration_data):
        self.assertEquals(
            fetch_(NAME, from_(valid_registration_data)),
            self.driver.find_text_box(NAME_TB).get_attribute('value'))
        self.assertEquals(
            fetch_(MOBILE_NUMBER, from_(valid_registration_data)),
            self.driver.find_text_box(MOBILE_NUMBER_TB).get_attribute('value'))
        self.assertEqual(
            fetch_(COMMUNE, from_(valid_registration_data)),
            self.driver.find_text_box(COMMUNE_TB).get_attribute('value'))
        self.assertEqual(
            fetch_(GPS, from_(valid_registration_data)),
            self.driver.find_text_box(GPS_TB).get_attribute('value'))

    @attr('functional_test')
    def test_edit_datasender_should_populate_all_fields_properly(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(
            VALID_DATA_WITH_EMAIL)
        success_msg = self.current_page.get_success_message()
        rep_id = self._parse(success_msg)
        self.assertRegexpMatches(
            success_msg, fetch_(SUCCESS_MSG, from_(VALID_DATA_WITH_EMAIL)))

        self.driver.go_to(DATA_WINNER_ALL_DATA_SENDERS_PAGE)
        all_datasender_page = AllDataSendersPage(self.driver)
        edit_datasender_page = all_datasender_page.edit_datasender(rep_id)

        self.assert_fields_are_populated_properly_in_edit_page(
            VALID_DATA_WITH_EMAIL)

        edit_datasender_page.enter_data_sender_details_from(
            VALID_DATA_WITH_EMAIL_EDITED)
        self.assertRegexpMatches(
            edit_datasender_page.get_success_message(),
            fetch_(SUCCESS_MSG, from_(VALID_DATA_WITH_EMAIL_EDITED)))

        self.driver.go_to(DATA_WINNER_ALL_DATA_SENDERS_PAGE)
        all_datasender_page = AllDataSendersPage(self.driver)
        all_datasender_page.edit_datasender(rep_id)

        self.assert_fields_are_populated_properly_in_edit_page(
            VALID_DATA_WITH_EMAIL_EDITED)

    # @attr('functional_test')
#     def test_should_uncheck_reporter_id_checkbox_if_user_has_given_id(self):
#         self.driver.go_to(DATA_WINNER_CREATE_DATA_SENDERS)
#         add_data_sender_page = AddDataSenderPage(self.driver)
#         self.assertTrue(add_data_sender_page.unique_id_check_box_is_checked())
#         add_data_sender_page.enter_data_sender_details_from(INVALID_MOBILE_NUMBER_DATA, "DS040")
#         time.sleep(1)
#         self.assertFalse(add_data_sender_page.unique_id_check_box_is_checked())
#         self.assertTrue(add_data_sender_page.unique_id_field_is_enabled())
#

    def _parse(self, message):
        return message.split(' ')[-1]
class TestAllDataSender(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.driver = setup_driver()
        cls.driver.go_to(DATA_WINNER_LOGIN_PAGE)
        login_page = LoginPage(cls.driver)
        login_page.do_successful_login_with(VALID_CREDENTIALS)

    def setUp(self):
        TestAllDataSender.driver.refresh()
        self.driver.go_to(DATA_WINNER_CREATE_DATA_SENDERS)
        self.current_page = AddDataSenderPage(self.driver)

    def tearDown(self):
        import sys

        exception_info = sys.exc_info()
        if exception_info != (None, None, None):
            import os
            if not os.path.exists("screenshots"):
                os.mkdir("screenshots")
            self.driver.get_screenshot_as_file("screenshots/screenshot-%s-%s.png" % (self.__class__.__name__, self._testMethodName))

    @classmethod
    def tearDownClass(cls):
        teardown_driver(cls.driver)

    def login_with_created_datasenders_account(self):
        self.driver.go_to(DATA_WINNER_ALL_DATA_SENDERS_PAGE)
        all_data_senders_page = AllDataSendersPage(self.driver)
        email = all_data_senders_page.get_data_sender_email_by_mobile_number(VALID_DATA_WITH_EMAIL[MOBILE_NUMBER_WITHOUT_HYPHENS])
        global_navigation = GlobalNavigationPage(self.driver)
        global_navigation.sign_out()
        self.driver.go_to(DATA_WINNER_LOGIN_PAGE)
        data_sender_crendentials = {USERNAME: email, PASSWORD: "******"}
        login_page = LoginPage(self.driver)
        login_page.login_with(data_sender_crendentials)
        message = global_navigation.welcome_message()
        return email, message

    @attr('functional_test', 'smoke')
    def test_successful_addition_editing_of_data_sender(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(VALID_DATA)

        self.assertRegexpMatches(add_data_sender_page.get_success_message(),
                                 fetch_(SUCCESS_MSG, from_(VALID_DATA)))
        self.driver.go_to(DATA_WINNER_ALL_DATA_SENDERS_PAGE)
        all_data_senders_page = AllDataSendersPage(self.driver)
        all_data_senders_page.select_a_data_sender_by_mobile(VALID_DATA[MOBILE_NUMBER_WITHOUT_HYPHENS])
        all_data_senders_page.select_edit_action()
        self.current_page.enter_data_sender_details_from(VALID_EDIT_DATA)
        self.assertRegexpMatches(self.current_page.get_success_message(),
            fetch_(SUCCESS_MSG, from_(VALID_EDIT_DATA)))

    @attr('functional_test', 'smoke')
    def test_successful_addition_of_data_sender_with_email_address(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.select_web_device()
        add_data_sender_page.enter_email(VALID_DATA_WITH_EMAIL)
        add_data_sender_page.enter_data_sender_details_from(VALID_DATA_WITH_EMAIL)

        self.assertRegexpMatches(add_data_sender_page.get_success_message(),
                                 fetch_(SUCCESS_MSG, from_(VALID_DATA_WITH_EMAIL)))

        email, message = self.login_with_created_datasenders_account()
        self.assertEqual(email.lower(), email)
        self.assertEqual(message, "Welcome Mickey Duck!")

    @attr('functional_test', 'smoke')
    def test_addition_of_data_sender_without_email_address(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.select_web_device()
        add_data_sender_page.enter_data_sender_details_from(VALID_DATA_WITHOUT_EMAIL)

        self.assertRegexpMatches(add_data_sender_page.get_error_message(),
                                 fetch_(ERROR_MSG, from_(VALID_DATA_WITHOUT_EMAIL)))

    @attr('functional_test')
    def test_addition_of_data_sender_without_entering_data(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(BLANK_FIELDS)
        self.assertEqual(add_data_sender_page.get_error_message(),
                         fetch_(ERROR_MSG, from_(BLANK_FIELDS)))

    @attr('functional_test')
    def test_addition_of_data_sender_with_existing_data(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(EXISTING_DATA)

        sleep(1)
        self.assertEqual(add_data_sender_page.get_error_message(),
                         fetch_(ERROR_MSG, from_(EXISTING_DATA)))


    @attr('functional_test')
    def test_addition_of_data_sender_without_location_name(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(WITHOUT_LOCATION_NAME)
        self.assertRegexpMatches(add_data_sender_page.get_success_message(),
                                 fetch_(SUCCESS_MSG, from_(WITHOUT_LOCATION_NAME)))

    @attr('functional_test')
    def test_addition_of_data_sender_without_gps(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(WITHOUT_GPS)
        self.assertRegexpMatches(add_data_sender_page.get_success_message(),
                                 fetch_(SUCCESS_MSG, from_(WITHOUT_GPS)))

    @attr('functional_test')
    def test_addition_of_data_sender_with_invalid_gps(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(INVALID_GPS)
        self.assertEqual(add_data_sender_page.get_error_message(),
                         fetch_(ERROR_MSG, from_(INVALID_GPS)))

    @attr('functional_test')
    def test_addition_of_data_sender_with_invalid_latitude_gps(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(INVALID_LATITUDE_GPS)
        self.assertEqual(add_data_sender_page.get_error_message(),
                         fetch_(ERROR_MSG, from_(INVALID_LATITUDE_GPS)))

    @attr('functional_test')
    def test_addition_of_data_sender_with_invalid_longitude_gps(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(INVALID_LONGITUDE_GPS)
        self.assertEqual(add_data_sender_page.get_error_message(),
                         fetch_(ERROR_MSG, from_(INVALID_LONGITUDE_GPS)))

    @attr('functional_test')
    def test_addition_of_data_sender_with_unicode_in_gps(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(WITH_UNICODE_IN_GPS)
        self.assertEqual(add_data_sender_page.get_error_message(),
                         fetch_(ERROR_MSG, from_(WITH_UNICODE_IN_GPS)))

    @SkipTest
    def test_addition_of_data_sender_with_invalid_gps_with_comma(self):
        add_data_sender_page = self.current_page
        add_data_sender_page.enter_data_sender_details_from(INVALID_GPS_WITH_COMMA)
        self.assertEqual(add_data_sender_page.get_error_message(),
                         fetch_(ERROR_MSG, from_(INVALID_GPS_WITH_COMMA)))