Commit 1f3d2c24 by Andy Armstrong

Isolate Bok Choy tests to unique test users

parent 9907cb52
......@@ -17,7 +17,7 @@ class AccountSettingsPage(FieldsMixin, PageObject):
url = "{base}/{settings}".format(base=BASE_URL, settings='account/settings')
def is_browser_on_page(self):
return 'Account Settings' in self.browser.title
return self.q(css='.account-settings-container').present
def sections_structure(self):
"""
......@@ -31,8 +31,6 @@ class AccountSettingsPage(FieldsMixin, PageObject):
...
]
"""
self.wait_for_ajax()
structure = []
sections = self.q(css='.section')
......
......@@ -16,8 +16,6 @@ class FieldsMixin(object):
"""
Return field with field_id.
"""
self.wait_for_ajax()
query = self.q(css='.u-field-{}'.format(field_id))
return query.text[0] if query.present else None
......
......@@ -306,18 +306,20 @@ class EventsTestMixin(object):
self.event_collection.drop()
self.start_time = datetime.now()
def get_matching_events(self, event_type):
def get_matching_events(self, username, event_type):
"""
Returns a cursor for the matching browser events.
"""
return self.event_collection.find({
"username": username,
"event_type": event_type,
"time": {"$gt": self.start_time},
})
def verify_events_of_type(self, event_type, expected_events, expected_referers=None):
def verify_events_of_type(self, username, event_type, expected_events, expected_referers=None):
"""Verify that the expected events of a given type were logged.
Args:
username (str): The name of the authenticated user.
event_type (str): The type of event to be verified.
expected_events (list): A list of dicts representing the events that should
have been fired.
......@@ -328,12 +330,12 @@ class EventsTestMixin(object):
will verify that the referer for the single event ends with "/account/settings".
"""
EmptyPromise(
lambda: self.get_matching_events(event_type).count() >= len(expected_events),
lambda: self.get_matching_events(username, event_type).count() >= len(expected_events),
"Waiting for the minimum number of events of type {type} to have been recorded".format(type=event_type)
).fulfill()
# Verify that the correct events were fired
cursor = self.get_matching_events(event_type)
cursor = self.get_matching_events(username, event_type)
actual_events = []
actual_referers = []
for __ in range(0, cursor.count()):
......
......@@ -84,14 +84,15 @@ class LearnerProfileTestMixin(EventsTestMixin):
str(birth_year)
)
def verify_profile_page_view_event(self, profile_user_id, visibility=None):
def verify_profile_page_view_event(self, requesting_username, profile_user_id, visibility=None):
"""
Verifies that the correct view event was captured for the profile page.
"""
self.verify_events_of_type(
requesting_username,
u"edx.user.settings.viewed",
[{
u"user_id": int(profile_user_id),
u"user_id": long(profile_user_id),
u"page": u"profile",
u"visibility": unicode(visibility),
}]
......@@ -180,7 +181,7 @@ class OwnLearnerProfilePageTest(LearnerProfileTestMixin, WebAppTest):
self.assertTrue(profile_page.privacy_field_visible)
self.assertEqual(profile_page.visible_fields, self.PRIVATE_PROFILE_FIELDS)
self.verify_profile_page_view_event(user_id, visibility=self.PRIVACY_PRIVATE)
self.verify_profile_page_view_event(username, user_id, visibility=self.PRIVACY_PRIVATE)
def test_fields_on_my_public_profile(self):
"""
......@@ -202,7 +203,7 @@ class OwnLearnerProfilePageTest(LearnerProfileTestMixin, WebAppTest):
self.assertEqual(profile_page.editable_fields, self.PUBLIC_PROFILE_EDITABLE_FIELDS)
self.verify_profile_page_view_event(user_id, visibility=self.PRIVACY_PUBLIC)
self.verify_profile_page_view_event(username, user_id, visibility=self.PRIVACY_PUBLIC)
def _test_dropdown_field(self, profile_page, field_id, new_value, displayed_value, mode):
"""
......@@ -332,7 +333,7 @@ class OwnLearnerProfilePageTest(LearnerProfileTestMixin, WebAppTest):
username, user_id = self.log_in_as_unique_user()
message = "You must specify your birth year before you can share your full profile."
self.verify_profile_forced_private_message(username, birth_year=None, message=message)
self.verify_profile_page_view_event(user_id, visibility=self.PRIVACY_PRIVATE)
self.verify_profile_page_view_event(username, user_id, visibility=self.PRIVACY_PRIVATE)
def test_user_is_under_age(self):
"""
......@@ -350,7 +351,7 @@ class OwnLearnerProfilePageTest(LearnerProfileTestMixin, WebAppTest):
birth_year=under_age_birth_year,
message='You must be over 13 to share a full profile.'
)
self.verify_profile_page_view_event(user_id, visibility=self.PRIVACY_PRIVATE)
self.verify_profile_page_view_event(username, user_id, visibility=self.PRIVACY_PRIVATE)
def test_user_can_only_see_default_image_for_private_profile(self):
"""
......@@ -557,12 +558,12 @@ class DifferentUserLearnerProfilePageTest(LearnerProfileTestMixin, WebAppTest):
Then I see some of the profile fields are shown.
"""
different_username, different_user_id = self._initialize_different_user(privacy=self.PRIVACY_PRIVATE)
self.log_in_as_unique_user()
username, __ = self.log_in_as_unique_user()
profile_page = self.visit_profile_page(different_username)
self.assertFalse(profile_page.privacy_field_visible)
self.assertEqual(profile_page.visible_fields, self.PRIVATE_PROFILE_FIELDS)
self.verify_profile_page_view_event(different_user_id, visibility=self.PRIVACY_PRIVATE)
self.verify_profile_page_view_event(username, different_user_id, visibility=self.PRIVACY_PRIVATE)
def test_different_user_under_age(self):
"""
......@@ -597,13 +598,13 @@ class DifferentUserLearnerProfilePageTest(LearnerProfileTestMixin, WebAppTest):
Also `location`, `language` and `about me` fields are not editable.
"""
different_username, different_user_id = self._initialize_different_user(privacy=self.PRIVACY_PUBLIC)
self.log_in_as_unique_user()
username, __ = self.log_in_as_unique_user()
profile_page = self.visit_profile_page(different_username)
profile_page.wait_for_public_fields()
self.assertFalse(profile_page.privacy_field_visible)
self.assertEqual(profile_page.visible_fields, self.PUBLIC_PROFILE_FIELDS)
self.assertEqual(profile_page.editable_fields, [])
self.verify_profile_page_view_event(different_user_id, visibility=self.PRIVACY_PUBLIC)
self.verify_profile_page_view_event(username, different_user_id, visibility=self.PRIVACY_PUBLIC)
def _initialize_different_user(self, privacy=None, birth_year=None):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment