class StudioLanguageTest(AcceptanceTest): """ Test suite for the Studio Language """ shard = 21 def setUp(self): super(StudioLanguageTest, self).setUp() self.dashboard_page = DashboardPage(self.browser) self.account_settings = AccountSettingsPage(self.browser) AutoAuthPage(self.browser).visit() def test_studio_language_change(self): """ Scenario: Ensure that language selection is working fine. First I go to the user dashboard page in studio. I can see 'English' is selected by default. Then I choose 'Dummy Language' from drop down (at top of the page). Then I visit the student account settings page and I can see the language has been updated to 'Dummy Language' in both drop downs. """ dummy_language = u'Dummy Language (Esperanto)' self.dashboard_page.visit() language_selector = self.dashboard_page.language_selector self.assertEqual(get_selected_option_text(language_selector), u'English') select_option_by_text(language_selector, dummy_language) self.dashboard_page.wait_for_ajax() self.account_settings.visit() self.assertEqual( self.account_settings.value_for_dropdown_field('pref-lang'), dummy_language) self.assertEqual(get_selected_option_text(language_selector), u'Dummy Language (Esperanto)')
class StudioLanguageTest(AcceptanceTest): """ Test suite for the Studio Language """ def setUp(self): super(StudioLanguageTest, self).setUp() self.dashboard_page = DashboardPage(self.browser) self.account_settings = AccountSettingsPage(self.browser) AutoAuthPage(self.browser).visit() def test_studio_language_change(self): """ Scenario: Ensure that language selection is working fine. First I go to the user dashboard page in studio. I can see 'English' is selected by default. Then I choose 'Dummy Language' from drop down (at top of the page). Then I visit the student account settings page and I can see the language has been updated to 'Dummy Language' in both drop downs. """ dummy_language = u'Dummy Language (Esperanto)' self.dashboard_page.visit() language_selector = self.dashboard_page.language_selector self.assertEqual( get_selected_option_text(language_selector), u'English' ) select_option_by_text(language_selector, dummy_language) self.dashboard_page.wait_for_ajax() self.account_settings.visit() self.assertEqual(self.account_settings.value_for_dropdown_field('pref-lang'), dummy_language) self.assertEqual( get_selected_option_text(language_selector), u'Dummy Language (Esperanto)' )
def visit_account_settings_page(self): """ Visit the account settings page for the current user, and store the page instance as self.account_settings_page. """ # pylint: disable=attribute-defined-outside-init self.account_settings_page = AccountSettingsPage(self.browser) self.account_settings_page.visit() self.account_settings_page.wait_for_ajax()
def visit_account_settings_page(self, gdpr=False): """ Visit the account settings page for the current user, and store the page instance as self.account_settings_page. """ self.account_settings_page = AccountSettingsPage(self.browser) self.account_settings_page.visit() self.account_settings_page.wait_for_ajax() # TODO: LEARNER-4422 - delete when we clean up flags if gdpr: self.account_settings_page.browser.get(self.browser.current_url + "?course_experience.gdpr=1") self.account_settings_page.wait_for_page()
def _unlink_dummy_account(self): """ Verify that the 'Dummy' third party auth provider is linked, then unlink it """ # This must be done after linking the account, or we'll get cross-test side effects account_settings = AccountSettingsPage(self.browser).visit() # switch to "Linked Accounts" tab account_settings.switch_account_settings_tabs('accounts-tab') field_id = "auth-oa2-dummy" account_settings.wait_for_field(field_id) self.assertEqual("Unlink This Account", account_settings.link_title_for_link_field(field_id)) account_settings.click_on_link_in_link_field(field_id) account_settings.wait_for_message(field_id, "Successfully unlinked")
def test_third_party_register(self): """ Test that we can register using third party credentials, and that the third party account gets linked to the edX account. """ # Navigate to the register page self.register_page.visit() # Baseline screen-shots are different for chrome and firefox. #self.assertScreenshot('#register .login-providers', 'register-providers-{}'.format(self.browser.name), .25) # The line above is commented out temporarily see SOL-1937 # Try to authenticate using the "Dummy" provider self.register_page.click_third_party_dummy_provider() # The user will be redirected somewhere and then back to the register page: msg_text = self.register_page.wait_for_auth_status_message() self.assertEqual(self.register_page.current_form, "register") self.assertIn("You've successfully signed into Dummy", msg_text) self.assertIn("We just need a little more information", msg_text) # Now the form should be pre-filled with the data from the Dummy provider: self.assertEqual(self.register_page.email_value, "*****@*****.**") self.assertEqual(self.register_page.full_name_value, "William Adama") self.assertIn("Galactica1", self.register_page.username_value) # Set country and submit the form: self.register_page.register(country="US", favorite_movie="Battlestar Galactica") # Expect that we reach the dashboard and we're auto-enrolled in the course course_names = self.dashboard_page.wait_for_page().available_courses self.assertIn(self.course_info["display_name"], course_names) # Now logout and check that we can log back in instantly (because the account is linked): LogoutPage(self.browser).visit() login_page = CombinedLoginAndRegisterPage(self.browser, start_page="login") login_page.visit() login_page.click_third_party_dummy_provider() self.dashboard_page.wait_for_page() # Now unlink the account (To test the account settings view and also to prevent cross-test side effects) account_settings = AccountSettingsPage(self.browser).visit() # switch to "Linked Accounts" tab account_settings.switch_account_settings_tabs('accounts-tab') field_id = "auth-oa2-dummy" account_settings.wait_for_field(field_id) self.assertEqual("Unlink This Account", account_settings.link_title_for_link_field(field_id)) account_settings.click_on_link_in_link_field(field_id) account_settings.wait_for_message(field_id, "Successfully unlinked")
def set_birth_year(self, birth_year): """ Set birth year for the current user to the specified value. """ account_settings_page = AccountSettingsPage(self.browser) account_settings_page.visit() account_settings_page.wait_for_page() self.assertEqual( account_settings_page.value_for_dropdown_field( 'year_of_birth', str(birth_year)), str(birth_year))
def set_birth_year(self, birth_year): """ Set birth year for the current user to the specified value. """ account_settings_page = AccountSettingsPage(self.browser) account_settings_page.visit() account_settings_page.wait_for_page() self.assertEqual( account_settings_page.value_for_dropdown_field('year_of_birth', str(birth_year)), str(birth_year) )
class LMSLanguageTest(UniqueCourseTest): """ Test suite for the LMS Language """ def setUp(self): super(LMSLanguageTest, self).setUp() self.dashboard_page = DashboardPage(self.browser) self.account_settings = AccountSettingsPage(self.browser) AutoAuthPage(self.browser).visit() def test_lms_language_change(self): """ Scenario: Ensure that language selection is working fine. First I go to the user dashboard page in LMS. I can see 'English' is selected by default. Then I choose 'Dummy Language' from drop down (at top of the page). Then I visit the student account settings page and I can see the language has been updated to 'Dummy Language' in both drop downs. After that I select the 'English' language and visit the dashboard page again. Then I can see that top level language selector persist its value to 'English'. """ self.dashboard_page.visit() language_selector = self.dashboard_page.language_selector self.assertEqual( get_selected_option_text(language_selector), u'English' ) select_option_by_text(language_selector, 'Dummy Language (Esperanto)') self.dashboard_page.wait_for_ajax() self.account_settings.visit() self.assertEqual(self.account_settings.value_for_dropdown_field('pref-lang'), u'Dummy Language (Esperanto)') self.assertEqual( get_selected_option_text(language_selector), u'Dummy Language (Esperanto)' ) # changed back to English language. select_option_by_text(language_selector, 'English') self.account_settings.wait_for_ajax() self.assertEqual(self.account_settings.value_for_dropdown_field('pref-lang'), u'English') self.dashboard_page.visit() self.assertEqual( get_selected_option_text(language_selector), u'English' )
class AccountSettingsTestMixin(EventsTestMixin, AcceptanceTest): """ Mixin with helper methods to test the account settings page. """ CHANGE_INITIATED_EVENT_NAME = u"edx.user.settings.change_initiated" USER_SETTINGS_CHANGED_EVENT_NAME = 'edx.user.settings.changed' ACCOUNT_SETTINGS_REFERER = u"/account/settings" shard = 23 def visit_account_settings_page(self, gdpr=False): """ Visit the account settings page for the current user, and store the page instance as self.account_settings_page. """ self.account_settings_page = AccountSettingsPage(self.browser) self.account_settings_page.visit() self.account_settings_page.wait_for_ajax() # TODO: LEARNER-4422 - delete when we clean up flags if gdpr: self.account_settings_page.browser.get(self.browser.current_url + "?course_experience.gdpr=1") self.account_settings_page.wait_for_page() def log_in_as_unique_user(self, email=None, full_name=None, password=None): """ Create a unique user and return the account's username and id. """ username = "******".format(uuid=self.unique_id[0:6]) auto_auth_page = AutoAuthPage( self.browser, username=username, email=email, full_name=full_name, password=password ).visit() user_id = auto_auth_page.get_user_id() return username, user_id
def _link_dummy_account(self): """ Go to Account Settings page and link the user's account to the Dummy provider """ account_settings = AccountSettingsPage(self.browser).visit() # switch to "Linked Accounts" tab account_settings.switch_account_settings_tabs('accounts-tab') field_id = "auth-oa2-dummy" account_settings.wait_for_field(field_id) self.assertEqual("Link Your Account", account_settings.link_title_for_link_field(field_id)) account_settings.click_on_link_in_link_field(field_id) # make sure we are on "Linked Accounts" tab after the account settings # page is reloaded account_settings.switch_account_settings_tabs('accounts-tab') account_settings.wait_for_link_title_for_link_field( field_id, "Unlink This Account")
def setUp(self): super(LMSLanguageTest, self).setUp() self.dashboard_page = DashboardPage(self.browser) self.account_settings = AccountSettingsPage(self.browser) AutoAuthPage(self.browser).visit()
class AccountSettingsTestMixin(EventsTestMixin, AcceptanceTest): """ Mixin with helper methods to test the account settings page. """ CHANGE_INITIATED_EVENT_NAME = u"edx.user.settings.change_initiated" USER_SETTINGS_CHANGED_EVENT_NAME = 'edx.user.settings.changed' ACCOUNT_SETTINGS_REFERER = u"/account/settings" def visit_account_settings_page(self): """ Visit the account settings page for the current user, and store the page instance as self.account_settings_page. """ # pylint: disable=attribute-defined-outside-init self.account_settings_page = AccountSettingsPage(self.browser) self.account_settings_page.visit() self.account_settings_page.wait_for_ajax() def log_in_as_unique_user(self, email=None, full_name=None): """ Create a unique user and return the account's username and id. """ username = "******".format(uuid=self.unique_id[0:6]) auto_auth_page = AutoAuthPage(self.browser, username=username, email=email, full_name=full_name).visit() user_id = auto_auth_page.get_user_id() return username, user_id def settings_changed_event_filter(self, event): """Filter out any events that are not "settings changed" events.""" return event['event_type'] == self.USER_SETTINGS_CHANGED_EVENT_NAME def expected_settings_changed_event(self, setting, old, new, table=None): """A dictionary representing the expected fields in a "settings changed" event.""" return { 'username': self.username, 'referer': self.get_settings_page_url(), 'event': { 'user_id': self.user_id, 'setting': setting, 'old': old, 'new': new, 'truncated': [], 'table': table or 'auth_userprofile' } } def settings_change_initiated_event_filter(self, event): """Filter out any events that are not "settings change initiated" events.""" return event['event_type'] == self.CHANGE_INITIATED_EVENT_NAME def expected_settings_change_initiated_event(self, setting, old, new, username=None, user_id=None): """A dictionary representing the expected fields in a "settings change initiated" event.""" return { 'username': username or self.username, 'referer': self.get_settings_page_url(), 'event': { 'user_id': user_id or self.user_id, 'setting': setting, 'old': old, 'new': new, } } def get_settings_page_url(self): """The absolute URL of the account settings page given the test context.""" return self.relative_path_to_absolute_uri(self.ACCOUNT_SETTINGS_REFERER) def assert_no_setting_changed_event(self): """Assert no setting changed event has been emitted thus far.""" self.assert_no_matching_events_were_emitted({'event_type': self.USER_SETTINGS_CHANGED_EVENT_NAME})
class AccountSettingsTestMixin(EventsTestMixin, AcceptanceTest): """ Mixin with helper methods to test the account settings page. """ CHANGE_INITIATED_EVENT_NAME = u"edx.user.settings.change_initiated" USER_SETTINGS_CHANGED_EVENT_NAME = 'edx.user.settings.changed' ACCOUNT_SETTINGS_REFERER = u"/account/settings" def visit_account_settings_page(self, gdpr=False): """ Visit the account settings page for the current user, and store the page instance as self.account_settings_page. """ # pylint: disable=attribute-defined-outside-init self.account_settings_page = AccountSettingsPage(self.browser) self.account_settings_page.visit() self.account_settings_page.wait_for_ajax() # TODO: LEARNER-4422 - delete when we clean up flags if gdpr: self.account_settings_page.browser.get(self.browser.current_url + "?course_experience.gdpr=1") self.account_settings_page.wait_for_page() def log_in_as_unique_user(self, email=None, full_name=None, password=None): """ Create a unique user and return the account's username and id. """ username = "******".format(uuid=self.unique_id[0:6]) auto_auth_page = AutoAuthPage(self.browser, username=username, email=email, full_name=full_name, password=password).visit() user_id = auto_auth_page.get_user_id() return username, user_id def settings_changed_event_filter(self, event): """Filter out any events that are not "settings changed" events.""" return event['event_type'] == self.USER_SETTINGS_CHANGED_EVENT_NAME def expected_settings_changed_event(self, setting, old, new, table=None): """A dictionary representing the expected fields in a "settings changed" event.""" return { 'username': self.username, 'referer': self.get_settings_page_url(), 'event': { 'user_id': self.user_id, 'setting': setting, 'old': old, 'new': new, 'truncated': [], 'table': table or 'auth_userprofile' } } def settings_change_initiated_event_filter(self, event): """Filter out any events that are not "settings change initiated" events.""" return event['event_type'] == self.CHANGE_INITIATED_EVENT_NAME def expected_settings_change_initiated_event(self, setting, old, new, username=None, user_id=None): """A dictionary representing the expected fields in a "settings change initiated" event.""" return { 'username': username or self.username, 'referer': self.get_settings_page_url(), 'event': { 'user_id': user_id or self.user_id, 'setting': setting, 'old': old, 'new': new, } } def get_settings_page_url(self): """The absolute URL of the account settings page given the test context.""" return self.relative_path_to_absolute_uri( self.ACCOUNT_SETTINGS_REFERER) def assert_no_setting_changed_event(self): """Assert no setting changed event has been emitted thus far.""" self.assert_no_matching_events_were_emitted( {'event_type': self.USER_SETTINGS_CHANGED_EVENT_NAME})
def _link_dummy_account(self): """ Go to Account Settings page and link the user's account to the Dummy provider """ account_settings = AccountSettingsPage(self.browser).visit() # switch to "Linked Accounts" tab account_settings.switch_account_settings_tabs('accounts-tab') field_id = "auth-oa2-dummy" account_settings.wait_for_field(field_id) self.assertEqual("Link Your Account", account_settings.link_title_for_link_field(field_id)) account_settings.click_on_link_in_link_field(field_id) # make sure we are on "Linked Accounts" tab after the account settings # page is reloaded account_settings.switch_account_settings_tabs('accounts-tab') account_settings.wait_for_link_title_for_link_field(field_id, "Unlink This Account")