def test_settings_request_post(self, mock_redirect, mock_usf): username = '******' mock_first_name = mock.MagicMock() mock_last_name = mock.MagicMock() mock_email = mock.MagicMock() mock_user = mock.MagicMock() mock_user.username = '******' mock_user.first_name = mock_first_name mock_user.last_name = mock_last_name mock_user.email = mock_email mock_request = mock.MagicMock() mock_request.user = mock_user mock_request.method = 'POST' mock_request.POST = 'user-settings-submit' mock_form = mock.MagicMock() mock_form.is_valid.return_value = True mock_usf.return_value = mock_form settings(mock_request, username) mock_user.save.assert_called() mock_usf.assert_called_once_with(mock_request.POST) mock_redirect.assert_called_once_with('user:profile', username='******')
def test_settings_request_get(self, mock_render, mock_usf, mock_token_get_create, mock_django_settings, _): username = '******' mock_request_user = mock.MagicMock() mock_request_user.username = '******' mock_request = mock.MagicMock() mock_request.user = mock_request_user mock_request.method = 'GET' mock_form = mock.MagicMock() mock_usf.return_value = mock_form mock_user_token = mock.MagicMock() mock_token_created = mock.MagicMock() mock_token_get_create.return_value = mock_user_token, mock_token_created mock_django_settings.MFA_REQUIRED = False expected_context = {'form': mock_form, 'context_user': mock_request.user, 'user_token': mock_user_token.key, 'current_use': '0 bytes', 'quota': None, 'mfa_required': False, 'has_mfa': False } settings(mock_request, username) mock_usf.assert_called_once_with(instance=mock_request_user) mock_token_get_create.assert_called_once_with(user=mock_request_user) mock_render.assert_called_once_with(mock_request, 'tethys_portal/user/settings.html', expected_context)
def test_settings_request_get(self, mock_render, mock_usf, mock_token_get_create): username = '******' mock_request_user = mock.MagicMock() mock_request_user.username = '******' mock_request = mock.MagicMock() mock_request.user = mock_request_user mock_request.method = 'GET' mock_form = mock.MagicMock() mock_usf.return_value = mock_form mock_user_token = mock.MagicMock() mock_token_created = mock.MagicMock() mock_token_get_create.return_value = mock_user_token, mock_token_created expected_context = {'form': mock_form, 'context_user': mock_request.user, 'user_token': mock_user_token.key} settings(mock_request, username) mock_usf.assert_called_once_with(instance=mock_request_user) mock_token_get_create.assert_called_once_with(user=mock_request_user) mock_render.assert_called_once_with(mock_request, 'tethys_portal/user/settings.html', expected_context)
def test_settings(self, mock_redirect, mock_message_warn): mock_request = mock.MagicMock() username = '******' mock_user = mock.MagicMock() mock_user.username = '******' mock_request.user = mock_user settings(mock_request, username) mock_message_warn.assert_called_once_with(mock_request, "You are not allowed to change other users' settings.") mock_redirect.assert_called_once_with('user:profile', username='******')