| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# |
| 3 |
# Copyright (C) 2018-2023 by the Free Software Foundation, Inc. |
| 4 |
# |
| 5 |
# This file is part of Django-Mailman. |
| 6 |
# |
| 7 |
# Django-Mailman is free software: you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by the Free |
| 9 |
# Software Foundation, either version 3 of the License, or (at your option) |
| 10 |
# any later version. |
| 11 |
# |
| 12 |
# Django-Mailman is distributed in the hope that it will be useful, but WITHOUT |
| 13 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 |
# more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License along with |
| 18 |
# Django-Mailman. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
# |
| 20 |
|
| 21 |
|
| 22 |
from unittest.mock import Mock |
| 23 |
|
| 24 |
from django.contrib.auth.models import User |
| 25 |
from django.urls import reverse |
| 26 |
|
| 27 |
from django_mailman3.models import Profile |
| 28 |
from django_mailman3.tests.utils import TestCase |
| 29 |
|
| 30 |
|
| 31 |
class AccountDeletionTests(TestCase): |
| 32 |
|
| 33 |
def setUp(self): |
| 34 |
self.mm_user = Mock() |
| 35 |
self.mm_user.user_id = "dummy" |
| 36 |
self.mm_user.addresses = [Mock()] |
| 37 |
self.mailman_client.get_user.side_effect = lambda e: self.mm_user |
| 38 |
self.user = User.objects.create_user( |
| 39 |
'testuser', '[email protected]', 'testPass', |
| 40 |
first_name="firstname", last_name="lastname", |
| 41 |
) |
| 42 |
self.client.login(username='testuser', password='testPass') |
| 43 |
|
| 44 |
def test_get_page(self): |
| 45 |
response = self.client.get(reverse('mm_user_account_delete')) |
| 46 |
self.assertEqual(response.status_code, 200) |
| 47 |
|
| 48 |
def test_delete(self): |
| 49 |
user_id = self.user.id |
| 50 |
self.assertTrue(Profile.objects.filter(user_id=user_id).exists()) |
| 51 |
response = self.client.post( |
| 52 |
reverse('mm_user_account_delete'), {}) |
| 53 |
self.assertEqual(response.url, '/') |
| 54 |
self.assertEqual(response.status_code, 302) |
| 55 |
self.assertFalse(User.objects.filter(id=user_id).exists()) |
| 56 |
self.assertFalse(Profile.objects.filter(user_id=user_id).exists()) |
| 57 |
self.mm_user.delete.assert_called() |