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)
     )
Example #3
0
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
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})
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.
        """
        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})