Skip to content

Commit

Permalink
Fix #984 -- Add resetting user to template context
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverroick committed Dec 8, 2016
1 parent 4cba99a commit 3c9a920
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
38 changes: 34 additions & 4 deletions cadasta/accounts/tests/test_views_default.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import datetime
from django.test import TestCase
from django.core import mail
from django.contrib.auth.tokens import default_token_generator
from skivvy import ViewTestCase

from accounts.tests.factories import UserFactory
from core.tests.utils.cases import UserTestCase

from allauth.account.models import EmailConfirmation, EmailAddress
from allauth.account.forms import ResetPasswordKeyForm
from allauth.account.utils import user_pk_to_url_str

from ..views.default import AccountProfile, AccountLogin, ConfirmEmail
from ..views import default
from ..forms import ProfileForm


class ProfileTest(ViewTestCase, UserTestCase, TestCase):
view_class = AccountProfile
view_class = default.AccountProfile
template = 'accounts/profile.html'

def setup_template_context(self):
Expand Down Expand Up @@ -66,7 +69,7 @@ def test_update_profile_duplicate_email(self):


class LoginTest(ViewTestCase, UserTestCase, TestCase):
view_class = AccountLogin
view_class = default.AccountLogin

def setup_models(self):
self.user = UserFactory.create(username='imagine71',
Expand All @@ -93,7 +96,7 @@ def test_successful_login_with_unverified_user(self):


class ConfirmEmailTest(ViewTestCase, UserTestCase, TestCase):
view_class = ConfirmEmail
view_class = default.ConfirmEmail
url_kwargs = {'key': '123'}

def setup_models(self):
Expand Down Expand Up @@ -132,3 +135,30 @@ def test_activate_with_invalid_token(self):

self.email_address.refresh_from_db()
assert self.email_address.verified is False


class PasswordResetFromKeyViewTest(ViewTestCase, UserTestCase, TestCase):
view_class = default.PasswordResetFromKeyView
template = 'account/password_reset_from_key.html'

def setup_models(self):
self.user = UserFactory.create(email='[email protected]')

def setup_template_context(self):
return {
'reset_user': self.user,
'form': ResetPasswordKeyForm(
user=self.user,
temp_key=default_token_generator.make_token(self.user))
}

def setup_url_kwargs(self):
return {
'uidb36': user_pk_to_url_str(self.user),
'key': default_token_generator.make_token(self.user)
}

def test_render_view(self):
response = self.request()
assert response.status_code == 200
assert response.content == self.expected_content
4 changes: 4 additions & 0 deletions cadasta/accounts/views/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class PasswordResetFromKeyView(SuperUserCheckMixin,
allauth_views.PasswordResetFromKeyView):
form_class = ResetPasswordKeyForm

def get_context_data(self, *args, **kwargs):
return super().get_context_data(reset_user=self.reset_user,
*args, **kwargs)


class AccountProfile(LoginRequiredMixin, UpdateView):
model = User
Expand Down
5 changes: 1 addition & 4 deletions cadasta/core/static/css/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ <h1>{% if token_fail %}{% trans "Bad token" %}{% else %}{% trans "Change your pa
{% else %}
{% if form %}
<form method="POST" action="." data-parsley-validate>
<input type="hidden" id="id_username" value="{{ user.username }}">
<input type="hidden" id="id_email" value="{{ user.email }}">
<input type="hidden" id="id_username" value="{{ reset_user.username }}">
<input type="hidden" id="id_email" value="{{ reset_user.email }}">
{% csrf_token %}

<div class="form-group{% if form.password1.errors %} has-error{% endif %}">
Expand Down

0 comments on commit 3c9a920

Please sign in to comment.