Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
9907cb52
Commit
9907cb52
authored
Apr 16, 2015
by
cahrens
Committed by
Andy Armstrong
Apr 17, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for profile image eventing.
parent
4797a74e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
9 deletions
+48
-9
common/test/acceptance/pages/lms/learner_profile.py
+0
-6
common/test/acceptance/tests/lms/test_learner_profile.py
+37
-0
openedx/core/djangoapps/profile_images/tests/test_views.py
+11
-3
No files found.
common/test/acceptance/pages/lms/learner_profile.py
View file @
9907cb52
...
...
@@ -223,12 +223,6 @@ class LearnerProfilePage(FieldsMixin, PageObject):
self
.
wait_for_ajax
()
def
upload_correct_image_file
(
self
,
filename
):
"""
Selects the correct file and clicks the upload button.
"""
self
.
_upload_file
(
filename
)
@property
def
image_upload_success
(
self
):
"""
...
...
common/test/acceptance/tests/lms/test_learner_profile.py
View file @
9907cb52
...
...
@@ -27,6 +27,8 @@ class LearnerProfileTestMixin(EventsTestMixin):
PUBLIC_PROFILE_EDITABLE_FIELDS
=
[
'country'
,
'language_proficiencies'
,
'bio'
]
USER_SETTINGS_CHANGED_EVENT_NAME
=
u"edx.user.settings.changed"
def
log_in_as_unique_user
(
self
):
"""
Create a unique user and return the account's username and id.
...
...
@@ -95,6 +97,16 @@ class LearnerProfileTestMixin(EventsTestMixin):
}]
)
def
assert_event_emitted_num_times
(
self
,
profile_user_id
,
setting
,
num_times
):
"""
Verify a particular user settings change event was emitted a certain
number of times.
"""
# pylint disable=no-member
super
(
LearnerProfileTestMixin
,
self
)
.
assert_event_emitted_num_times
(
self
.
USER_SETTINGS_CHANGED_EVENT_NAME
,
self
.
start_time
,
profile_user_id
,
num_times
,
setting
=
setting
)
class
OwnLearnerProfilePageTest
(
LearnerProfileTestMixin
,
WebAppTest
):
"""
...
...
@@ -399,6 +411,8 @@ class OwnLearnerProfilePageTest(LearnerProfileTestMixin, WebAppTest):
profile_page
.
visit
()
self
.
assertTrue
(
profile_page
.
image_upload_success
)
self
.
assert_event_emitted_num_times
(
user_id
,
'profile_image_uploaded_at'
,
1
)
def
test_user_can_see_error_for_exceeding_max_file_size_limit
(
self
):
"""
Scenario: Upload profile image does not work for > 1MB image file.
...
...
@@ -421,6 +435,8 @@ class OwnLearnerProfilePageTest(LearnerProfileTestMixin, WebAppTest):
profile_page
.
visit
()
self
.
assertTrue
(
profile_page
.
profile_has_default_image
)
self
.
assert_event_emitted_num_times
(
user_id
,
'profile_image_uploaded_at'
,
0
)
def
test_user_can_see_error_for_file_size_below_the_min_limit
(
self
):
"""
Scenario: Upload profile image does not work for < 100 Bytes image file.
...
...
@@ -443,6 +459,8 @@ class OwnLearnerProfilePageTest(LearnerProfileTestMixin, WebAppTest):
profile_page
.
visit
()
self
.
assertTrue
(
profile_page
.
profile_has_default_image
)
self
.
assert_event_emitted_num_times
(
user_id
,
'profile_image_uploaded_at'
,
0
)
def
test_user_can_see_error_for_wrong_file_type
(
self
):
"""
Scenario: Upload profile image does not work for wrong file types.
...
...
@@ -465,6 +483,8 @@ class OwnLearnerProfilePageTest(LearnerProfileTestMixin, WebAppTest):
profile_page
.
visit
()
self
.
assertTrue
(
profile_page
.
profile_has_default_image
)
self
.
assert_event_emitted_num_times
(
user_id
,
'profile_image_uploaded_at'
,
0
)
def
test_user_can_remove_profile_image
(
self
):
"""
Scenario: Remove profile image works correctly.
...
...
@@ -489,6 +509,8 @@ class OwnLearnerProfilePageTest(LearnerProfileTestMixin, WebAppTest):
profile_page
.
visit
()
self
.
assertTrue
(
profile_page
.
profile_has_default_image
)
self
.
assert_event_emitted_num_times
(
user_id
,
'profile_image_uploaded_at'
,
1
)
def
test_user_cannot_remove_default_image
(
self
):
"""
Scenario: Remove profile image does not works for default images.
...
...
@@ -505,6 +527,21 @@ class OwnLearnerProfilePageTest(LearnerProfileTestMixin, WebAppTest):
self
.
assert_default_image_has_public_access
(
profile_page
)
self
.
assertFalse
(
profile_page
.
remove_link_present
)
def
test_eventing_after_multiple_uploads
(
self
):
"""
Scenario: An event is fired when a user with a profile image uploads another image
Given that I am on my profile page with public access
And I upload a new image via file uploader
When I upload another image via the file uploader
Then two upload events have been emitted
"""
username
,
user_id
=
self
.
log_in_as_unique_user
()
profile_page
=
self
.
visit_profile_page
(
username
,
privacy
=
self
.
PRIVACY_PUBLIC
)
profile_page
.
upload_file
(
filename
=
'image.jpg'
)
profile_page
.
upload_file
(
filename
=
'image.jpg'
)
self
.
assert_event_emitted_num_times
(
user_id
,
'profile_image_uploaded_at'
,
2
)
class
DifferentUserLearnerProfilePageTest
(
LearnerProfileTestMixin
,
WebAppTest
):
"""
...
...
openedx/core/djangoapps/profile_images/tests/test_views.py
View file @
9907cb52
...
...
@@ -27,6 +27,7 @@ from .helpers import make_image_file
TEST_PASSWORD
=
"test"
TEST_UPLOAD_DT
=
datetime
.
datetime
(
2002
,
1
,
9
,
15
,
43
,
01
,
tzinfo
=
UTC
)
TEST_UPLOAD_DT2
=
datetime
.
datetime
(
2003
,
1
,
9
,
15
,
43
,
01
,
tzinfo
=
UTC
)
class
ProfileImageEndpointTestCase
(
UserSettingsEventTestMixin
,
APITestCase
):
...
...
@@ -110,13 +111,13 @@ class ProfileImageUploadTestCase(ProfileImageEndpointTestCase):
"""
_view_name
=
"profile_image_upload"
def
check_upload_event_emitted
(
self
):
def
check_upload_event_emitted
(
self
,
old
=
None
,
new
=
TEST_UPLOAD_DT
):
"""
Make sure we emit a UserProfile event corresponding to the
profile_image_uploaded_at field changing.
"""
self
.
assert_user_setting_event_emitted
(
setting
=
'profile_image_uploaded_at'
,
old
=
None
,
new
=
TEST_UPLOAD_DT
setting
=
'profile_image_uploaded_at'
,
old
=
old
,
new
=
new
)
def
test_unsupported_methods
(
self
,
mock_log
):
...
...
@@ -140,7 +141,7 @@ class ProfileImageUploadTestCase(ProfileImageEndpointTestCase):
self
.
assertFalse
(
mock_log
.
info
.
called
)
self
.
assert_no_events_were_emitted
()
@patch
(
'openedx.core.djangoapps.profile_images.views._make_upload_dt'
,
return_value
=
TEST_UPLOAD_DT
)
@patch
(
'openedx.core.djangoapps.profile_images.views._make_upload_dt'
,
side_effect
=
[
TEST_UPLOAD_DT
,
TEST_UPLOAD_DT2
]
)
def
test_upload_self
(
self
,
mock_make_image_version
,
mock_log
):
# pylint: disable=unused-argument
"""
Test that an authenticated user can POST to their own upload endpoint.
...
...
@@ -156,6 +157,13 @@ class ProfileImageUploadTestCase(ProfileImageEndpointTestCase):
)
self
.
check_upload_event_emitted
()
# Try another upload and make sure that a second event is emitted.
with
make_image_file
()
as
image_file
:
response
=
self
.
client
.
post
(
self
.
url
,
{
'file'
:
image_file
},
format
=
'multipart'
)
self
.
check_response
(
response
,
204
)
self
.
check_upload_event_emitted
(
old
=
TEST_UPLOAD_DT
,
new
=
TEST_UPLOAD_DT2
)
def
test_upload_other
(
self
,
mock_log
):
"""
Test that an authenticated user cannot POST to another user's upload endpoint.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment