-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1548] add and regroup tests for profile deletion refactor
- Loading branch information
Showing
5 changed files
with
105 additions
and
168 deletions.
There are no files selected for viewing
31 changes: 0 additions & 31 deletions
31
src/open_inwoner/accounts/management/commands/deleteinactiveusers.py
This file was deleted.
Oops, something went wrong.
92 changes: 0 additions & 92 deletions
92
src/open_inwoner/accounts/tests/test_deleteinactiveusers.py
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
from open_inwoner.cms.profile.cms_appconfig import ProfileConfig | ||
from open_inwoner.haalcentraal.tests.mixins import HaalCentraalMixin | ||
from open_inwoner.pdc.tests.factories import CategoryFactory | ||
from open_inwoner.plans.tests.factories import PlanFactory | ||
from open_inwoner.utils.logentry import LOG_ACTIONS | ||
from open_inwoner.utils.tests.helpers import AssertTimelineLogMixin, create_image_bytes | ||
|
||
|
@@ -21,6 +22,7 @@ | |
from ...questionnaire.tests.factories import QuestionnaireStepFactory | ||
from ..choices import ContactTypeChoices, LoginTypeChoices | ||
from ..forms import BrpUserForm, UserForm | ||
from ..models import User | ||
from .factories import ActionFactory, DigidUserFactory, DocumentFactory, UserFactory | ||
|
||
|
||
|
@@ -92,49 +94,6 @@ def test_only_open_actions(self): | |
self.assertEquals(response.status_code, 200) | ||
self.assertContains(response, "0 acties staan open.") | ||
|
||
def test_deactivate_account(self): | ||
response = self.app.get(self.url, user=self.user) | ||
self.assertEquals(response.status_code, 200) | ||
form = response.forms["deactivate-form"] | ||
base_response = form.submit() | ||
self.assertEquals(base_response.url, self.return_url) | ||
followed_response = base_response.follow().follow() | ||
self.assertEquals(followed_response.status_code, 200) | ||
self.user.refresh_from_db() | ||
self.assertFalse(self.user.is_active) | ||
self.assertIsNotNone(self.user.deactivated_on) | ||
|
||
def test_deactivate_account_staff(self): | ||
self.user.is_staff = True | ||
self.user.save() | ||
response = self.app.get(self.url, user=self.user) | ||
self.assertEquals(response.status_code, 200) | ||
form = response.forms["deactivate-form"] | ||
base_response = form.submit() | ||
self.assertEquals(base_response.url, self.url) | ||
followed_response = base_response.follow() | ||
self.assertEquals(followed_response.status_code, 200) | ||
self.user.refresh_from_db() | ||
self.assertTrue(self.user.is_active) | ||
self.assertIsNone(self.user.deactivated_on) | ||
|
||
def test_deactivate_account_digid(self): | ||
""" | ||
check that user is redirected to digid:logout | ||
""" | ||
user = UserFactory.create( | ||
login_type=LoginTypeChoices.digid, email="[email protected]" | ||
) | ||
|
||
response = self.app.get(self.url, user=user) | ||
self.assertEquals(response.status_code, 200) | ||
form = response.forms["deactivate-form"] | ||
|
||
response = form.submit() | ||
|
||
self.assertEquals(response.status_code, 302) | ||
self.assertEquals(response.url, reverse("digid:logout")) | ||
|
||
def test_get_documents_sorted(self): | ||
""" | ||
check that the new document is shown first | ||
|
@@ -560,6 +519,96 @@ def test_modify_phone_updates_klant_api_but_skip_unchanged_phone(self, m): | |
) | ||
|
||
|
||
@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls") | ||
class ProfileDeleteTest(WebTest): | ||
csrf_checks = False | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
cls.url = reverse("profile:detail") | ||
|
||
def test_delete_regular_user_success(self): | ||
user = UserFactory() | ||
|
||
# get profile page | ||
response = self.app.get(self.url, user=user) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
# check delete | ||
response = response.forms["deactivate-form"].submit() | ||
self.assertIsNone(User.objects.first()) | ||
|
||
# check redirect | ||
self.assertRedirects( | ||
self.app.get(response.url), | ||
reverse("pages-root"), | ||
status_code=302, | ||
target_status_code=200, | ||
fetch_redirect_response=True, | ||
) | ||
|
||
def test_delete_user_with_digid_login_success(self): | ||
user = DigidUserFactory() | ||
|
||
# get profile page | ||
response = self.app.get(self.url, user=user) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
# check user deleted | ||
response = response.forms["deactivate-form"].submit() | ||
self.assertIsNone(User.objects.first()) | ||
|
||
# check redirect | ||
self.assertRedirects( | ||
self.app.get(response.url), | ||
reverse("pages-root"), | ||
status_code=302, | ||
target_status_code=200, | ||
fetch_redirect_response=True, | ||
) | ||
|
||
def test_delete_regular_with_existing_plans_fail(self): | ||
user = UserFactory() | ||
PlanFactory.create(created_by=user) | ||
|
||
# get profile page | ||
response = self.app.get(self.url, user=user) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
# check user not deleted | ||
response = response.forms["deactivate-form"].submit() | ||
self.assertEqual(User.objects.first(), user) | ||
|
||
# check redirect | ||
self.assertRedirects( | ||
response, | ||
reverse("profile:detail"), | ||
status_code=302, | ||
target_status_code=200, | ||
fetch_redirect_response=True, | ||
) | ||
|
||
def test_delete_staff_user_via_frontend_does_not_work(self): | ||
user = UserFactory(is_staff=True) | ||
|
||
# get profile page | ||
response = self.app.get(self.url, user=user) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
# check staff user not deleted | ||
response = response.forms["deactivate-form"].submit() | ||
self.assertEqual(User.objects.first(), user) | ||
|
||
# check redirect | ||
self.assertRedirects( | ||
response, | ||
reverse("profile:detail"), | ||
status_code=302, | ||
target_status_code=200, | ||
fetch_redirect_response=True, | ||
) | ||
|
||
|
||
@requests_mock.Mocker() | ||
@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls") | ||
class MyDataTests(HaalCentraalMixin, WebTest): | ||
|
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