-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from moshthepitt/issue-18
Add users app
- Loading branch information
Showing
31 changed files
with
783 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
"""example URL Configuration""" | ||
from django.conf.urls import include | ||
from django.urls import path | ||
|
||
from artists import views | ||
|
||
urlpatterns = views.ArtistCRUD().url_patterns() +\ | ||
|
||
urlpatterns = [ | ||
path('', include('vega_admin.contrib.users.urls')), | ||
] + views.ArtistCRUD().url_patterns() +\ | ||
views.SongCRUD().url_patterns() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{% load i18n %} | ||
<div class="sidebar content-box" style="display: block;"> | ||
<ul class="nav"> | ||
<li class="submenu"> | ||
<a href="{% url 'auth.user-list' %}"> | ||
<i class="glyphicon glyphicon-list"></i> {% trans "Users" %} | ||
<span class="caret pull-right"></span> | ||
</a> | ||
<!-- Sub menu --> | ||
<ul> | ||
<li><a href="{% url 'auth.user-list' %}">{% trans "View Users" %}</a></li> | ||
<li><a href="{% url 'auth.user-create' %}">{% trans "Create User" %}</a></li> | ||
</ul> | ||
<!-- Sub menu --> | ||
<ul> | ||
<li><a href="{% url 'auth.group-list' %}">{% trans "View Groups" %}</a></li> | ||
<li><a href="{% url 'auth.group-create' %}">{% trans "Create Group" %}</a></li> | ||
</ul> | ||
</li> | ||
</ul> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
# load from setup.py | ||
-e . | ||
|
||
# allauth | ||
django-allauth | ||
|
||
# others | ||
pylint | ||
pylint-django | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
"""Test vega_admin.contrib.users.forms module""" | ||
|
||
from django.test import TestCase, override_settings | ||
from unittest.mock import patch | ||
|
||
from model_mommy import mommy | ||
|
||
from vega_admin.contrib.users.forms import (AddUserForm, EditUserForm, | ||
PasswordChangeForm) | ||
|
||
|
||
@override_settings( | ||
ROOT_URLCONF="vega_admin.contrib.users.urls", VEGA_TEMPLATE="basic") | ||
class TestForms(TestCase): | ||
""" | ||
Test class for vega_admin.contrib.users.forms | ||
""" | ||
|
||
def test_adduserform(self): | ||
""" | ||
Test AddUserForm | ||
""" | ||
good_data = { | ||
"first_name": "mosh", | ||
"last_name": "pitt", | ||
"username": "moshthepitt", | ||
"email": "[email protected]", | ||
"password": "Miserable-Water-9", | ||
} | ||
|
||
form = AddUserForm(data=good_data) | ||
self.assertTrue(form.is_valid()) | ||
user = form.save() | ||
self.assertEqual("mosh", user.first_name) | ||
self.assertEqual("pitt", user.last_name) | ||
self.assertEqual("moshthepitt", user.username) | ||
self.assertEqual("[email protected]", user.email) | ||
self.assertTrue( | ||
self.client.login( | ||
username="moshthepitt", password="Miserable-Water-9")) | ||
|
||
# good data no username | ||
good_data = { | ||
"first_name": "mosh", | ||
"last_name": "pitt", | ||
"email": "[email protected]", | ||
"password": "Bean-Quarrel-0", | ||
} | ||
|
||
form = AddUserForm(data=good_data) | ||
self.assertTrue(form.is_valid()) | ||
user = form.save() | ||
self.assertEqual("mosh", user.username) # was generated | ||
|
||
# weak password | ||
bad_data = { | ||
"first_name": "mosh", | ||
"last_name": "pitt", | ||
"username": "moshthepitt2", | ||
"email": "[email protected]", | ||
"password": "[email protected]", | ||
} | ||
form = AddUserForm(data=bad_data) | ||
self.assertFalse(form.is_valid()) | ||
self.assertEqual(1, len(form.errors.keys())) | ||
self.assertEqual( | ||
"The password is too similar to the email address.", | ||
form.errors["password"][0], | ||
) | ||
|
||
# email not unique | ||
bad_data = { | ||
"first_name": "mosh", | ||
"last_name": "pitt", | ||
"username": "moshthepitt3", | ||
"email": "[email protected]", | ||
"password": "Every-Actor-1", | ||
} | ||
form = AddUserForm(data=bad_data) | ||
self.assertFalse(form.is_valid()) | ||
self.assertEqual(1, len(form.errors.keys())) | ||
self.assertEqual( | ||
"A user is already registered with this e-mail address.", | ||
form.errors["email"][0], | ||
) | ||
|
||
# missing email and username | ||
bad_data = { | ||
"first_name": "mosh", | ||
"last_name": "pitt", | ||
"password": "TestAddUserForm", | ||
} | ||
form = AddUserForm(data=bad_data) | ||
self.assertFalse(form.is_valid()) | ||
self.assertEqual(1, len(form.errors.keys())) | ||
self.assertEqual("You must provide one of email or username", | ||
form.errors["__all__"][0]) | ||
|
||
def test_edituserform(self): | ||
""" | ||
Test EditUserForm | ||
""" | ||
user = mommy.make("auth.User") | ||
|
||
good_data = { | ||
"first_name": "mosh", | ||
"last_name": "pitt", | ||
"username": "moshthepitt22", | ||
"email": "[email protected]", | ||
} | ||
form = EditUserForm(instance=user, data=good_data) | ||
self.assertTrue(form.is_valid()) | ||
user = form.save() | ||
self.assertEqual("mosh", user.first_name) | ||
self.assertEqual("pitt", user.last_name) | ||
self.assertEqual("moshthepitt22", user.username) | ||
self.assertEqual("[email protected]", user.email) | ||
|
||
def test_password_change_form(self): | ||
""" | ||
Test PasswordChangeForm | ||
""" | ||
user = mommy.make("auth.User", username="softie") | ||
|
||
good_data = { | ||
"password1": "PasswordChangeForm", | ||
"password2": "PasswordChangeForm", | ||
} | ||
form = PasswordChangeForm(instance=user, data=good_data) | ||
self.assertTrue(form.is_valid()) | ||
form.save() | ||
self.assertTrue( | ||
self.client.login( | ||
username="softie", password="PasswordChangeForm")) | ||
|
||
# weak password | ||
bad_data = {"password1": "123456789", "password2": "123456789"} | ||
form = PasswordChangeForm(instance=user, data=bad_data) | ||
self.assertFalse(form.is_valid()) | ||
self.assertEqual(1, len(form.errors.keys())) | ||
self.assertEqual("This password is too common.", | ||
form.errors["password2"][0]) | ||
self.assertEqual("This password is entirely numeric.", | ||
form.errors["password2"][1]) | ||
|
||
# different passwords | ||
bad_data = { | ||
"password1": "PasswordChangeForm", | ||
"password2": "123456789" | ||
} | ||
form = PasswordChangeForm(instance=user, data=bad_data) | ||
self.assertFalse(form.is_valid()) | ||
self.assertEqual(1, len(form.errors.keys())) | ||
self.assertEqual("The two password fields didn't match.", | ||
form.errors["password2"][0]) | ||
|
||
@patch('vega_admin.contrib.users.forms.get_form_actions') | ||
def test_password_change_form_cancel_url(self, mock): | ||
"""Test cancel url on password change form""" | ||
user = mommy.make("auth.User") | ||
|
||
good_data = { | ||
"password1": "PasswordChangeForm", | ||
"password2": "PasswordChangeForm", | ||
} | ||
form = PasswordChangeForm(instance=user, data=good_data) | ||
self.assertTrue(form.is_valid()) | ||
form.save() | ||
|
||
mock.assert_called_with(cancel_url="/auth.user/list/") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"""Test vega_admin.contrib.users.forms module""" | ||
|
||
from django.test import TestCase, override_settings | ||
|
||
from model_mommy import mommy | ||
|
||
from vega_admin.contrib.users.forms import PasswordChangeForm | ||
from vega_admin.contrib.users.views import ChangePassword | ||
from vega_admin.views import VegaUpdateView | ||
|
||
|
||
@override_settings( | ||
ROOT_URLCONF="vega_admin.contrib.users.urls", VEGA_TEMPLATE="basic") | ||
class TestViews(TestCase): | ||
""" | ||
Test class for vega_admin.contrib.users.views | ||
""" | ||
|
||
def test_changepassword(self): | ||
""" | ||
Test ChangePassword | ||
""" | ||
user = mommy.make("auth.User", username="TestChangePasswordView") | ||
data = { | ||
"password1": "Extension-I-School-5", | ||
"password2": "Extension-I-School-5", | ||
} | ||
|
||
res = self.client.get(f"/auth.user/change%20password/{user.id}/") | ||
self.assertEqual(res.status_code, 200) | ||
self.assertIsInstance(res.context["form"], PasswordChangeForm) | ||
self.assertIsInstance(res.context["view"], ChangePassword) | ||
self.assertIsInstance(res.context["view"], VegaUpdateView) | ||
self.assertTemplateUsed(res, "vega_admin/basic/update.html") | ||
res = self.client.post(f"/auth.user/change%20password/{user.id}/", | ||
data) | ||
self.assertEqual(res.status_code, 302) | ||
self.assertRedirects(res, "/auth.user/list/") | ||
user.refresh_from_db() | ||
self.assertTrue( | ||
self.client.login( | ||
username="TestChangePasswordView", | ||
password="Extension-I-School-5")) | ||
|
||
@override_settings(VEGA_FORCE_ORDERING=True) | ||
def test_list_view_ordering(self): | ||
""" | ||
Test VEGA_FORCE_ORDERING=True | ||
""" | ||
mommy.make("auth.User", _quantity=7) | ||
res = self.client.get("/auth.user/list/") | ||
self.assertTrue(res.context["object_list"].ordered) | ||
self.assertEqual("-last_login", | ||
res.context["object_list"].query.order_by[0]) | ||
self.assertEqual("first_name", | ||
res.context["object_list"].query.order_by[1]) | ||
|
||
@override_settings(VEGA_FORCE_ORDERING=False) | ||
def test_list_view_ordering_off(self): | ||
""" | ||
Test VEGA_FORCE_ORDERING=False | ||
""" | ||
res = self.client.get("/auth.user/list/") | ||
self.assertFalse(res.context["object_list"].ordered) |
Oops, something went wrong.