本文整理汇总了Python中h.accounts.views.ProfileController.edit_profile方法的典型用法代码示例。如果您正苦于以下问题:Python ProfileController.edit_profile方法的具体用法?Python ProfileController.edit_profile怎么用?Python ProfileController.edit_profile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类h.accounts.views.ProfileController
的用法示例。
在下文中一共展示了ProfileController.edit_profile方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_subscription_update
# 需要导入模块: from h.accounts.views import ProfileController [as 别名]
# 或者: from h.accounts.views.ProfileController import edit_profile [as 别名]
def test_subscription_update(self, config, dummy_db_session):
"""Make sure that the new status is written into the DB."""
request = _get_fake_request('acct:[email protected]', 'smith', True, True)
configure(config)
with patch('h.accounts.views.Subscriptions') as mock_subs:
mock_subs.get_by_id = MagicMock()
mock_subs.get_by_id.return_value = Mock(active=True)
profile = ProfileController(request)
profile.edit_profile()
assert dummy_db_session.added
示例2: test_profile_invalid_password
# 需要导入模块: from h.accounts.views import ProfileController [as 别名]
# 或者: from h.accounts.views.ProfileController import edit_profile [as 别名]
def test_profile_invalid_password():
""" Make sure our edit_profile call validates the user password
"""
request = _get_fake_request('john', 'doe')
with testConfig() as config:
configure(config)
with patch('horus.models.UserMixin') as mock_user:
with patch('horus.lib.FlashMessage') as mock_flash:
mock_user.get_user = MagicMock(side_effect=_bad_password)
profile = ProfileController(request)
profile.User = mock_user
profile.edit_profile()
assert mock_flash.called_with(request, _('Invalid password.'), kind='error')
示例3: test_profile_calls_super
# 需要导入模块: from h.accounts.views import ProfileController [as 别名]
# 或者: from h.accounts.views.ProfileController import edit_profile [as 别名]
def test_profile_calls_super():
"""Make sure our method calls the superclasses edit_profile
if the validations are successful
"""
request = _get_fake_request('john', 'smith')
with testConfig() as config:
configure(config)
with patch('horus.models.UserMixin') as mock_user:
with patch('horus.views.ProfileController.edit_profile') as mock_super_profile:
mock_user.get_user = MagicMock(side_effect=_good_password_simple)
profile = ProfileController(request)
profile.User = mock_user
profile.edit_profile()
assert profile.request.context is True
assert mock_super_profile.called
示例4: test_subscription_update
# 需要导入模块: from h.accounts.views import ProfileController [as 别名]
# 或者: from h.accounts.views.ProfileController import edit_profile [as 别名]
def test_subscription_update():
"""Make sure that the new status is written into the DB
"""
request = _get_fake_request('acct:[email protected]', 'smith', True, True)
print "request", request.POST
with testConfig() as config:
configure(config)
with patch('h.accounts.views.Subscriptions') as mock_subs:
mock_subs.get_by_id = MagicMock()
mock_subs.get_by_id.return_value = Mock(active=True)
profile = ProfileController(request)
profile.db = Mock()
profile.db.add = MagicMock(name='add')
profile.edit_profile()
assert profile.db.add.called
示例5: test_edit_profile_with_validation_failure
# 需要导入模块: from h.accounts.views import ProfileController [as 别名]
# 或者: from h.accounts.views.ProfileController import edit_profile [as 别名]
def test_edit_profile_with_validation_failure(authn_policy, form_validator):
"""If form validation fails, return the error object."""
authn_policy.authenticated_userid.return_value = "johndoe"
form_validator.return_value = ({"errors": "BOOM!"}, None)
request = DummyRequest(method='POST')
profile = ProfileController(request)
result = profile.edit_profile()
assert result == {"errors": "BOOM!"}
示例6: test_edit_profile_successfully
# 需要导入模块: from h.accounts.views import ProfileController [as 别名]
# 或者: from h.accounts.views.ProfileController import edit_profile [as 别名]
def test_edit_profile_successfully(authn_policy, form_validator, user_model):
"""edit_profile() returns a dict with key "form" when successful."""
authn_policy.authenticated_userid.return_value = "johndoe"
form_validator.return_value = (None, {"username": "johndoe", "pwd": "password", "subscriptions": ""})
user_model.validate_user.return_value = True
user_model.get_by_id.return_value = FakeUser(email="[email protected]")
request = DummyRequest(method="POST")
profile = ProfileController(request)
result = profile.edit_profile()
assert result == {"model": {"email": "[email protected]"}}
示例7: test_profile_invalid_password
# 需要导入模块: from h.accounts.views import ProfileController [as 别名]
# 或者: from h.accounts.views.ProfileController import edit_profile [as 别名]
def test_profile_invalid_password(self, config, user_model):
"""Make sure our edit_profile call validates the user password."""
request = _get_fake_request('john', 'doe')
configure(config)
# With an invalid password, get_user returns None
user_model.get_user.return_value = None
profile = ProfileController(request)
result = profile.edit_profile()
assert result['code'] == 401
assert any('pwd' in err for err in result['errors'])
示例8: test_edit_profile_invalid_password
# 需要导入模块: from h.accounts.views import ProfileController [as 别名]
# 或者: from h.accounts.views.ProfileController import edit_profile [as 别名]
def test_edit_profile_invalid_password(authn_policy, form_validator, user_model):
"""Make sure our edit_profile call validates the user password."""
authn_policy.authenticated_userid.return_value = "johndoe"
form_validator.return_value = (None, {"username": "john", "pwd": "blah", "subscriptions": ""})
# Mock an invalid password
user_model.validate_user.return_value = False
request = DummyRequest(method="POST")
profile = ProfileController(request)
result = profile.edit_profile()
assert result["code"] == 401
assert any("pwd" in err for err in result["errors"])
示例9: test_edit_profile_successfully
# 需要导入模块: from h.accounts.views import ProfileController [as 别名]
# 或者: from h.accounts.views.ProfileController import edit_profile [as 别名]
def test_edit_profile_successfully(self, config, user_model):
"""edit_profile() returns a dict with key "form" when successful."""
configure(config)
profile = ProfileController(DummyRequest())
with patch(
"h.accounts.views._validate_edit_profile_request") as validate:
validate.return_value = {
"username": "johndoe",
"pwd": "password",
"subscriptions": []
}
result = profile.edit_profile()
assert "form" in result
assert "errors" not in result
示例10: test_subscription_update
# 需要导入模块: from h.accounts.views import ProfileController [as 别名]
# 或者: from h.accounts.views.ProfileController import edit_profile [as 别名]
def test_subscription_update(authn_policy, form_validator, subscriptions_model, user_model):
"""Make sure that the new status is written into the DB."""
authn_policy.authenticated_userid.return_value = "acct:[email protected]"
form_validator.return_value = (
None,
{"username": "acct:[email protected]", "pwd": "smith", "subscriptions": '{"active":true,"uri":"acct:[email protected]","id":1}'},
)
mock_sub = Mock(active=False, uri="acct:[email protected]")
subscriptions_model.get_by_id.return_value = mock_sub
user_model.get_by_id.return_value = FakeUser(email="[email protected]")
request = DummyRequest(method="POST")
profile = ProfileController(request)
result = profile.edit_profile()
assert mock_sub.active is True
assert result == {"model": {"email": "[email protected]"}}
示例11: test_edit_profile_with_validation_failure
# 需要导入模块: from h.accounts.views import ProfileController [as 别名]
# 或者: from h.accounts.views.ProfileController import edit_profile [as 别名]
def test_edit_profile_with_validation_failure(self, config, user_model):
"""If validation raises edit_profile() should return an error.
If _validate_edit_profile_request() raises an exception then
edit_profile() should return a dict with an "errors" list containing a
list of the error(s) from the exception's .errors property.
"""
configure(config)
profile = ProfileController(DummyRequest())
errors = [
("email", ["That email is invalid", "That email is taken"]),
("emailAgain", "The emails must match."),
("password", ["That password is wrong"])
]
with patch(
"h.accounts.views._validate_edit_profile_request") as validate:
validate.side_effect = (
views._InvalidEditProfileRequestError(errors=errors))
result = profile.edit_profile()
assert result["errors"] == errors