2015-12-06 17:49:10 +01:00
|
|
|
"""
|
|
|
|
This module provides tests for :py:mod:`osusers.views`.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2019-01-30 21:27:25 +01:00
|
|
|
from unittest.mock import patch, MagicMock
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
from django.test import TestCase, TransactionTestCase
|
|
|
|
from django.contrib.auth import get_user_model
|
2019-01-30 21:27:25 +01:00
|
|
|
from django.urls import reverse
|
2015-12-06 17:49:10 +01:00
|
|
|
|
2019-01-30 21:27:25 +01:00
|
|
|
from hostingpackages.models import CustomerHostingPackage, HostingPackageTemplate
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
from osusers.models import SshPublicKey
|
2019-01-30 21:27:25 +01:00
|
|
|
from osusers.views import AddSshPublicKey, DeleteSshPublicKey, EditSshPublicKeyComment
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
User = get_user_model()
|
|
|
|
|
2019-01-30 21:27:25 +01:00
|
|
|
TEST_USER = "test"
|
|
|
|
TEST_PASSWORD = "secret"
|
|
|
|
TEST_EMAIL = "test@example.org"
|
|
|
|
EXAMPLE_KEY = "".join(
|
|
|
|
(
|
|
|
|
"ssh-rsa ",
|
|
|
|
"AAAAB3NzaC1yc2EAAAABIwAAAIEA1on8gxCGJJWSRT4uOrR13mUaUk0hRf4RzxSZ1zRb",
|
|
|
|
"YYFw8pfGesIFoEuVth4HKyF8k1y4mRUnYHP1XNMNMJl1JcEArC2asV8sHf6zSPVffozZ",
|
|
|
|
"5TT4SfsUu/iKy9lUcCfXzwre4WWZSXXcPff+EHtWshahu3WzBdnGxm5Xoi89zcE=",
|
|
|
|
)
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
class HostingPackageAwareTestMixin(object):
|
|
|
|
|
2019-01-30 21:27:25 +01:00
|
|
|
# noinspection PyMethodMayBeStatic
|
2015-12-06 17:49:10 +01:00
|
|
|
def _setup_hosting_package(self, customer):
|
|
|
|
template = HostingPackageTemplate.objects.create(
|
2019-01-30 21:27:25 +01:00
|
|
|
name="testpackagetemplate", mailboxcount=10, diskspace=1, diskspace_unit=0
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
package = CustomerHostingPackage.objects.create_from_template(
|
2019-01-30 21:27:25 +01:00
|
|
|
customer, template, "testpackage"
|
|
|
|
)
|
|
|
|
with patch("hostingpackages.models.settings") as hmsettings:
|
2015-12-06 17:49:10 +01:00
|
|
|
hmsettings.OSUSER_DEFAULT_GROUPS = []
|
|
|
|
package.save()
|
|
|
|
return package
|
|
|
|
|
|
|
|
|
|
|
|
class AddSshPublicKeyTest(HostingPackageAwareTestMixin, TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.customer = User.objects.create_user(
|
2019-01-30 21:27:25 +01:00
|
|
|
username=TEST_USER, password=TEST_PASSWORD
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
self.package = self._setup_hosting_package(self.customer)
|
|
|
|
|
|
|
|
def _get_url(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
return reverse("add_ssh_key", kwargs={"package": self.package.id})
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
def test_get_anonymous(self):
|
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
def test_get_regular_user(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
def test_get_other_regular_user(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
User.objects.create_user("test2", password=TEST_PASSWORD)
|
|
|
|
self.client.login(username="test2", password=TEST_PASSWORD)
|
2015-12-06 17:49:10 +01:00
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
def test_get_staff_user(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
User.objects.create_superuser("admin", email=TEST_EMAIL, password=TEST_PASSWORD)
|
|
|
|
self.client.login(username="admin", password=TEST_PASSWORD)
|
2015-12-06 17:49:10 +01:00
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
def test_get_template(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.get(self._get_url())
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertTemplateUsed(response, "osusers/sshpublickey_create.html")
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
def test_get_form_kwargs(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
view = AddSshPublicKey(
|
2019-01-30 21:27:25 +01:00
|
|
|
request=MagicMock(), kwargs={"package": str(self.package.pk)}
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
the_kwargs = view.get_form_kwargs()
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertIn("hostingpackage", the_kwargs)
|
|
|
|
self.assertEqual(the_kwargs["hostingpackage"], self.package)
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
def test_get_context_data(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.get(self._get_url())
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertIn("customer", response.context)
|
|
|
|
self.assertEqual(response.context["customer"], self.customer)
|
|
|
|
self.assertIn("osuser", response.context)
|
|
|
|
self.assertEqual(response.context["osuser"], self.package.osuser.username)
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
def test_form_valid_redirect(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.post(
|
2019-01-30 21:27:25 +01:00
|
|
|
self._get_url(), data={"publickeytext": EXAMPLE_KEY}
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
self.assertRedirects(response, self.package.get_absolute_url())
|
|
|
|
|
|
|
|
def test_form_valid_message(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.post(
|
2019-01-30 21:27:25 +01:00
|
|
|
self._get_url(), follow=True, data={"publickeytext": EXAMPLE_KEY}
|
|
|
|
)
|
|
|
|
messages = list(response.context["messages"])
|
2015-12-06 17:49:10 +01:00
|
|
|
self.assertEqual(len(messages), 1)
|
|
|
|
self.assertEqual(
|
2019-01-30 21:27:25 +01:00
|
|
|
"Successfully added new ssh-rsa SSH public key.".format(
|
2015-12-06 17:49:10 +01:00
|
|
|
username=self.package.osuser.username
|
2019-01-30 21:27:25 +01:00
|
|
|
),
|
|
|
|
str(messages[0]),
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
class DeleteSshPublicKeyTest(HostingPackageAwareTestMixin, TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.customer = User.objects.create_user(
|
2019-01-30 21:27:25 +01:00
|
|
|
username=TEST_USER, password=TEST_PASSWORD
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
self.package = self._setup_hosting_package(self.customer)
|
|
|
|
self.sshkey = SshPublicKey.objects.create(
|
2019-01-30 21:27:25 +01:00
|
|
|
user=self.package.osuser, algorithm="good", data="key", comment="comment"
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
def _get_url(self):
|
|
|
|
return reverse(
|
2019-01-30 21:27:25 +01:00
|
|
|
"delete_ssh_key", kwargs={"package": self.package.id, "pk": self.sshkey.id}
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
def test_get_anonymous(self):
|
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
def test_get_regular_user(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
def test_get_other_regular_user(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
User.objects.create_user("test2", password=TEST_PASSWORD)
|
|
|
|
self.client.login(username="test2", password=TEST_PASSWORD)
|
2015-12-06 17:49:10 +01:00
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
def test_get_staff_user(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
User.objects.create_superuser("admin", email=TEST_EMAIL, password=TEST_PASSWORD)
|
|
|
|
self.client.login(username="admin", password=TEST_PASSWORD)
|
2015-12-06 17:49:10 +01:00
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
def test_get_template(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.get(self._get_url())
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertTemplateUsed(response, "osusers/sshpublickey_confirm_delete.html")
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
def test_get_queryset(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
view = DeleteSshPublicKey(
|
2019-01-30 21:27:25 +01:00
|
|
|
request=MagicMock(),
|
|
|
|
kwargs={"package": str(self.package.pk), "pk": str(self.sshkey.pk)},
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
queryset = view.get_queryset()
|
|
|
|
self.assertQuerysetEqual(queryset, [repr(self.sshkey)])
|
|
|
|
|
|
|
|
def test_get_context_data(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.get(self._get_url())
|
2019-01-30 21:27:25 +01:00
|
|
|
for key in ("hostingpackage", "customer", "osuser"):
|
2015-12-06 17:49:10 +01:00
|
|
|
self.assertIn(key, response.context)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(response.context["hostingpackage"], self.package)
|
|
|
|
self.assertEqual(response.context["customer"], self.customer)
|
|
|
|
self.assertEqual(response.context["osuser"], self.package.osuser.username)
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
def test_get_success_url(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
2019-01-30 21:27:25 +01:00
|
|
|
response = self.client.post(self._get_url(), data={"comment": "new comment"})
|
|
|
|
self.assertRedirects(
|
|
|
|
response, reverse("list_ssh_keys", kwargs={"package": self.package.id})
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
|
2019-01-30 21:27:25 +01:00
|
|
|
class EditSshPublicKeyCommentTest(HostingPackageAwareTestMixin, TransactionTestCase):
|
2015-12-06 17:49:10 +01:00
|
|
|
def setUp(self):
|
|
|
|
self.customer = User.objects.create_user(
|
2019-01-30 21:27:25 +01:00
|
|
|
username=TEST_USER, password=TEST_PASSWORD
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
self.package = self._setup_hosting_package(self.customer)
|
|
|
|
self.sshkey = SshPublicKey.objects.create(
|
2019-01-30 21:27:25 +01:00
|
|
|
user=self.package.osuser, algorithm="good", data="key", comment="comment"
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
def _get_url(self):
|
|
|
|
return reverse(
|
2019-01-30 21:27:25 +01:00
|
|
|
"edit_ssh_key_comment",
|
|
|
|
kwargs={"package": self.package.id, "pk": self.sshkey.id},
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
def test_get_anonymous(self):
|
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
def test_get_regular_user(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
def test_get_other_regular_user(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
User.objects.create_user("test2", password=TEST_PASSWORD)
|
|
|
|
self.client.login(username="test2", password=TEST_PASSWORD)
|
2015-12-06 17:49:10 +01:00
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
def test_get_staff_user(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
User.objects.create_superuser("admin", email=TEST_EMAIL, password=TEST_PASSWORD)
|
|
|
|
self.client.login(username="admin", password=TEST_PASSWORD)
|
2015-12-06 17:49:10 +01:00
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
def test_get_template(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.get(self._get_url())
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertTemplateUsed(response, "osusers/sshpublickey_edit_comment.html")
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
def test_get_queryset(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
view = EditSshPublicKeyComment(
|
2019-01-30 21:27:25 +01:00
|
|
|
request=MagicMock(),
|
|
|
|
kwargs={"package": str(self.package.pk), "pk": str(self.sshkey.pk)},
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
queryset = view.get_queryset()
|
|
|
|
self.assertQuerysetEqual(queryset, [repr(self.sshkey)])
|
|
|
|
|
|
|
|
def test_get_form_kwargs(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
view = EditSshPublicKeyComment(
|
2019-01-30 21:27:25 +01:00
|
|
|
request=MagicMock(),
|
|
|
|
kwargs={"package": str(self.package.pk), "pk": str(self.sshkey.pk)},
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
the_kwargs = view.get_form_kwargs()
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertIn("hostingpackage", the_kwargs)
|
|
|
|
self.assertEqual(the_kwargs["hostingpackage"], self.package)
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
def test_get_context_data(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.get(self._get_url())
|
2019-01-30 21:27:25 +01:00
|
|
|
for key in ("hostingpackage", "customer", "osuser"):
|
2015-12-06 17:49:10 +01:00
|
|
|
self.assertIn(key, response.context)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(response.context["hostingpackage"], self.package)
|
|
|
|
self.assertEqual(response.context["customer"], self.customer)
|
|
|
|
self.assertEqual(response.context["osuser"], self.package.osuser.username)
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
def test_get_success_url(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
2019-01-30 21:27:25 +01:00
|
|
|
response = self.client.post(self._get_url(), data={"comment": "new comment"})
|
|
|
|
self.assertRedirects(
|
|
|
|
response, reverse("list_ssh_keys", kwargs={"package": self.package.id})
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ListSshPublicKeysTest(HostingPackageAwareTestMixin, TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.customer = User.objects.create_user(
|
2019-01-30 21:27:25 +01:00
|
|
|
username=TEST_USER, password=TEST_PASSWORD
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
self.package = self._setup_hosting_package(self.customer)
|
|
|
|
|
|
|
|
def _get_url(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
return reverse("list_ssh_keys", kwargs={"package": self.package.id})
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
def test_get_anonymous(self):
|
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
def test_get_regular_user(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
def test_get_other_regular_user(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
User.objects.create_user("test2", password=TEST_PASSWORD)
|
|
|
|
self.client.login(username="test2", password=TEST_PASSWORD)
|
2015-12-06 17:49:10 +01:00
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
def test_get_staff_user(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
User.objects.create_superuser("admin", email=TEST_EMAIL, password=TEST_PASSWORD)
|
|
|
|
self.client.login(username="admin", password=TEST_PASSWORD)
|
2015-12-06 17:49:10 +01:00
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
def test_get_template(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.get(self._get_url())
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertTemplateUsed(response, "osusers/sshpublickey_list.html")
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
def test_get_context_data(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.get(self._get_url())
|
2019-01-30 21:27:25 +01:00
|
|
|
for key in ("hostingpackage", "customer", "osuser"):
|
2015-12-06 17:49:10 +01:00
|
|
|
self.assertIn(key, response.context)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(response.context["hostingpackage"], self.package)
|
|
|
|
self.assertEqual(response.context["customer"], self.customer)
|
|
|
|
self.assertEqual(response.context["osuser"], self.package.osuser.username)
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
class SetOsUserPasswordTest(HostingPackageAwareTestMixin, TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.customer = User.objects.create_user(
|
2019-01-30 21:27:25 +01:00
|
|
|
username=TEST_USER, password=TEST_PASSWORD
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
self.package = self._setup_hosting_package(self.customer)
|
|
|
|
|
|
|
|
def _get_url(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
return reverse(
|
|
|
|
"set_osuser_password", kwargs={"slug": self.package.osuser.username}
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
def test_get_anonymous(self):
|
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
def test_get_regular_user(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
def test_get_other_regular_user(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
User.objects.create_user("test2", password=TEST_PASSWORD)
|
|
|
|
self.client.login(username="test2", password=TEST_PASSWORD)
|
2015-12-06 17:49:10 +01:00
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
def test_get_staff_user(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
User.objects.create_superuser("admin", email=TEST_EMAIL, password=TEST_PASSWORD)
|
|
|
|
self.client.login(username="admin", password=TEST_PASSWORD)
|
2015-12-06 17:49:10 +01:00
|
|
|
response = self.client.get(self._get_url())
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
def test_get_template(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.get(self._get_url())
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertTemplateUsed(response, "osusers/user_setpassword.html")
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
def test_get_context_data(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.get(self._get_url())
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertIn("customer", response.context)
|
|
|
|
self.assertEqual(response.context["customer"], self.customer)
|
2015-12-06 17:49:10 +01:00
|
|
|
|
|
|
|
def test_form_valid_redirect(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.post(
|
|
|
|
self._get_url(),
|
2019-01-30 21:27:25 +01:00
|
|
|
data={"password1": TEST_PASSWORD, "password2": TEST_PASSWORD},
|
|
|
|
)
|
2015-12-06 17:49:10 +01:00
|
|
|
self.assertRedirects(response, self.package.get_absolute_url())
|
|
|
|
|
|
|
|
def test_form_valid_message(self):
|
|
|
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
|
|
response = self.client.post(
|
2019-01-30 21:27:25 +01:00
|
|
|
self._get_url(),
|
|
|
|
follow=True,
|
|
|
|
data={"password1": TEST_PASSWORD, "password2": TEST_PASSWORD},
|
|
|
|
)
|
|
|
|
messages = list(response.context["messages"])
|
2015-12-06 17:49:10 +01:00
|
|
|
self.assertEqual(len(messages), 1)
|
|
|
|
self.assertEqual(
|
2019-01-30 21:27:25 +01:00
|
|
|
"New password for {username} has been set successfully.".format(
|
2015-12-06 17:49:10 +01:00
|
|
|
username=self.package.osuser.username
|
2019-01-30 21:27:25 +01:00
|
|
|
),
|
|
|
|
str(messages[0]),
|
|
|
|
)
|