Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
2c5264cb
Commit
2c5264cb
authored
5 years ago
by
Mike O'Connell
Browse files
Options
Downloads
Patches
Plain Diff
Unit test for account recovery
Add a unit test to create and activate a recovery email address ENT-2607
parent
7d67dcfb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
openedx/core/djangoapps/user_api/accounts/tests/test_api.py
+46
-22
46 additions, 22 deletions
openedx/core/djangoapps/user_api/accounts/tests/test_api.py
with
46 additions
and
22 deletions
openedx/core/djangoapps/user_api/accounts/tests/test_api.py
+
46
−
22
View file @
2c5264cb
...
...
@@ -6,26 +6,31 @@ Most of the functionality is covered in test_views.py.
import
itertools
import
re
import
unicodedata
import
ddt
import
pytest
from
dateutil.parser
import
parse
as
parse_datetime
from
django.conf
import
settings
from
django.contrib.auth.hashers
import
make_password
from
django.contrib.auth.models
import
User
from
django.
core
import
mail
from
django.
http
import
HttpResponse
from
django.test
import
TestCase
from
django.test.client
import
RequestFactory
from
django.urls
import
reverse
from
mock
import
Mock
,
patch
from
six
import
iteritems
from
social_django.models
import
UserSocialAuth
from
student.models
import
(
AccountRecovery
,
PendingEmailChange
,
PendingSecondaryEmailChange
,
UserProfile
)
from
student.tests.factories
import
UserFactory
from
student.tests.tests
import
UserSettingsEventTestMixin
from
student.views.management
import
activate_secondary_email
from
openedx.core.djangoapps.ace_common.tests.mixins
import
EmailTemplateTagMixin
from
openedx.core.djangoapps.site_configuration.tests.factories
import
SiteFactory
from
openedx.core.djangoapps.user_api.accounts
import
PRIVATE_VISIBILITY
,
USERNAME_MAX_LENGTH
from
openedx.core.djangoapps.user_api.accounts
import
PRIVATE_VISIBILITY
from
openedx.core.djangoapps.user_api.accounts.api
import
(
get_account_settings
,
update_account_settings
...
...
@@ -35,30 +40,14 @@ from openedx.core.djangoapps.user_api.accounts.tests.retirement_helpers import (
fake_requested_retirement
,
setup_retirement_states
)
from
openedx.core.djangoapps.user_api.accounts.tests.testutils
import
(
INVALID_EMAILS
,
INVALID_PASSWORDS
,
INVALID_USERNAMES
,
VALID_USERNAMES_UNICODE
)
from
openedx.core.djangoapps.user_api.config.waffle
import
PREVENT_AUTH_USER_WRITES
,
SYSTEM_MAINTENANCE_MSG
,
waffle
from
openedx.core.djangoapps.user_api.errors
import
(
AccountEmailInvalid
,
AccountPasswordInvalid
,
AccountRequestError
,
AccountUpdateError
,
AccountUserAlreadyExists
,
AccountUsernameInvalid
,
AccountValidationError
,
UserAPIInternalError
,
UserNotAuthorized
,
UserNotFound
)
from
openedx.core.djangolib.testing.utils
import
skip_unless_lms
from
openedx.features.enterprise_support.tests.factories
import
EnterpriseCustomerUserFactory
from
student.models
import
PendingEmailChange
,
Registration
from
student.tests.factories
import
UserFactory
from
student.tests.tests
import
UserSettingsEventTestMixin
def
mock_render_to_string
(
template_name
,
context
):
...
...
@@ -66,6 +55,15 @@ def mock_render_to_string(template_name, context):
return
str
((
template_name
,
sorted
(
iteritems
(
context
))))
def
mock_render_to_response
(
template_name
):
"""
Return an HttpResponse with content that encodes template_name and context
"""
# This simulates any db access in the templates.
UserProfile
.
objects
.
exists
()
return
HttpResponse
(
template_name
)
class
CreateAccountMixin
(
object
):
def
create_account
(
self
,
username
,
password
,
email
):
# pylint: disable=missing-docstring
...
...
@@ -82,6 +80,7 @@ class CreateAccountMixin(object):
@skip_unless_lms
@ddt.ddt
@patch
(
'
student.views.management.render_to_response
'
,
Mock
(
side_effect
=
mock_render_to_response
,
autospec
=
True
))
class
TestAccountApi
(
UserSettingsEventTestMixin
,
EmailTemplateTagMixin
,
CreateAccountMixin
,
RetirementTestCase
):
"""
These tests specifically cover the parts of the API methods that are not covered by test_views.py.
...
...
@@ -457,6 +456,31 @@ class TestAccountApi(UserSettingsEventTestMixin, EmailTemplateTagMixin, CreateAc
verify_event_emitted
([{
"
code
"
:
"
en
"
},
{
"
code
"
:
"
fr
"
}],
[{
"
code
"
:
"
en
"
},
{
"
code
"
:
"
fr
"
}])
verify_event_emitted
([],
[{
"
code
"
:
"
en
"
},
{
"
code
"
:
"
fr
"
}])
def
test_add_account_recovery
(
self
):
test_email
=
"
test@example.com
"
pending_secondary_email_changes
=
PendingSecondaryEmailChange
.
objects
.
filter
(
user
=
self
.
user
)
self
.
assertEqual
(
0
,
len
(
pending_secondary_email_changes
))
account_recovery_objects
=
AccountRecovery
.
objects
.
filter
(
user
=
self
.
user
)
self
.
assertEqual
(
0
,
len
(
account_recovery_objects
))
with
patch
(
'
crum.get_current_request
'
,
return_value
=
self
.
fake_request
):
update
=
{
"
secondary_email
"
:
test_email
}
update_account_settings
(
self
.
user
,
update
)
pending_secondary_email_change
=
PendingSecondaryEmailChange
.
objects
.
get
(
user
=
self
.
user
)
self
.
assertIsNot
(
pending_secondary_email_change
,
None
)
self
.
assertEqual
(
pending_secondary_email_change
.
new_secondary_email
,
test_email
)
activate_secondary_email
(
self
.
fake_request
,
pending_secondary_email_change
.
activation_key
)
pending_secondary_email_changes
=
PendingSecondaryEmailChange
.
objects
.
filter
(
user
=
self
.
user
)
self
.
assertEqual
(
0
,
len
(
pending_secondary_email_changes
))
account_recovery
=
AccountRecovery
.
objects
.
get
(
user
=
self
.
user
)
self
.
assertIsNot
(
account_recovery
,
None
)
self
.
assertEqual
(
account_recovery
.
secondary_email
,
test_email
)
@patch
(
'
openedx.core.djangoapps.user_api.accounts.image_helpers._PROFILE_IMAGE_SIZES
'
,
[
50
,
10
])
@patch.dict
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment