|
@@ -421,13 +421,9 @@ class UserFollowTests(AuthenticatedUserTestCase):
|
|
"detail": "You can't add yourself to followed.",
|
|
"detail": "You can't add yourself to followed.",
|
|
})
|
|
})
|
|
|
|
|
|
- @patch_user_acl
|
|
|
|
- def test_cant_follow(self, patch_user_acl):
|
|
|
|
|
|
+ @patch_user_acl({'can_follow_users': 0})
|
|
|
|
+ def test_cant_follow(self):
|
|
"""no permission to follow users"""
|
|
"""no permission to follow users"""
|
|
- patch_user_acl(self.user, {
|
|
|
|
- 'can_follow_users': 0,
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
response = self.client.post(self.link)
|
|
response = self.client.post(self.link)
|
|
self.assertEqual(response.status_code, 403)
|
|
self.assertEqual(response.status_code, 403)
|
|
self.assertEqual(response.json(), {
|
|
self.assertEqual(response.json(), {
|
|
@@ -477,31 +473,25 @@ class UserBanTests(AuthenticatedUserTestCase):
|
|
|
|
|
|
self.link = '/api/users/%s/ban/' % self.other_user.pk
|
|
self.link = '/api/users/%s/ban/' % self.other_user.pk
|
|
|
|
|
|
- @patch_user_acl
|
|
|
|
- def test_no_permission(self, patch_user_acl):
|
|
|
|
|
|
+ @patch_user_acl({'can_see_ban_details': 0})
|
|
|
|
+ def test_no_permission(self):
|
|
"""user has no permission to access ban"""
|
|
"""user has no permission to access ban"""
|
|
- patch_user_acl(self.user, {'can_see_ban_details': 0})
|
|
|
|
-
|
|
|
|
response = self.client.get(self.link)
|
|
response = self.client.get(self.link)
|
|
self.assertEqual(response.status_code, 403)
|
|
self.assertEqual(response.status_code, 403)
|
|
self.assertEqual(response.json(), {
|
|
self.assertEqual(response.json(), {
|
|
"detail": "You can't see users bans details.",
|
|
"detail": "You can't see users bans details.",
|
|
})
|
|
})
|
|
|
|
|
|
- @patch_user_acl
|
|
|
|
- def test_no_ban(self, patch_user_acl):
|
|
|
|
|
|
+ @patch_user_acl({'can_see_ban_details': 1})
|
|
|
|
+ def test_no_ban(self):
|
|
"""api returns empty json"""
|
|
"""api returns empty json"""
|
|
- patch_user_acl(self.user, {'can_see_ban_details': 1})
|
|
|
|
-
|
|
|
|
response = self.client.get(self.link)
|
|
response = self.client.get(self.link)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.json(), {})
|
|
self.assertEqual(response.json(), {})
|
|
|
|
|
|
- @patch_user_acl
|
|
|
|
- def test_ban_details(self, patch_user_acl):
|
|
|
|
|
|
+ @patch_user_acl({'can_see_ban_details': 1})
|
|
|
|
+ def test_ban_details(self):
|
|
"""api returns ban json"""
|
|
"""api returns ban json"""
|
|
- patch_user_acl(self.user, {'can_see_ban_details': 1})
|
|
|
|
-
|
|
|
|
Ban.objects.create(
|
|
Ban.objects.create(
|
|
check_type=Ban.USERNAME,
|
|
check_type=Ban.USERNAME,
|
|
banned_value=self.other_user.username,
|
|
banned_value=self.other_user.username,
|
|
@@ -608,32 +598,24 @@ class UserDeleteTests(AuthenticatedUserTestCase):
|
|
self.other_user.threads = 1
|
|
self.other_user.threads = 1
|
|
self.other_user.save()
|
|
self.other_user.save()
|
|
|
|
|
|
- @patch_user_acl
|
|
|
|
- def test_delete_no_permission(self, patch_user_acl):
|
|
|
|
|
|
+ @patch_user_acl({
|
|
|
|
+ 'can_delete_users_newer_than': 0,
|
|
|
|
+ 'can_delete_users_with_less_posts_than': 0,
|
|
|
|
+ })
|
|
|
|
+ def test_delete_no_permission(self):
|
|
"""raises 403 error when no permission to delete"""
|
|
"""raises 403 error when no permission to delete"""
|
|
- patch_user_acl(
|
|
|
|
- self.user, {
|
|
|
|
- 'can_delete_users_newer_than': 0,
|
|
|
|
- 'can_delete_users_with_less_posts_than': 0,
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
response = self.client.post(self.link)
|
|
response = self.client.post(self.link)
|
|
self.assertEqual(response.status_code, 403)
|
|
self.assertEqual(response.status_code, 403)
|
|
self.assertEqual(response.json(), {
|
|
self.assertEqual(response.json(), {
|
|
'detail': "You can't delete users.",
|
|
'detail': "You can't delete users.",
|
|
})
|
|
})
|
|
|
|
|
|
- @patch_user_acl
|
|
|
|
- def test_delete_too_many_posts(self, patch_user_acl):
|
|
|
|
|
|
+ @patch_user_acl({
|
|
|
|
+ 'can_delete_users_newer_than': 0,
|
|
|
|
+ 'can_delete_users_with_less_posts_than': 5,
|
|
|
|
+ })
|
|
|
|
+ def test_delete_too_many_posts(self):
|
|
"""raises 403 error when user has too many posts"""
|
|
"""raises 403 error when user has too many posts"""
|
|
- patch_user_acl(
|
|
|
|
- self.user, {
|
|
|
|
- 'can_delete_users_newer_than': 0,
|
|
|
|
- 'can_delete_users_with_less_posts_than': 5,
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
self.other_user.posts = 6
|
|
self.other_user.posts = 6
|
|
self.other_user.save()
|
|
self.other_user.save()
|
|
|
|
|
|
@@ -643,16 +625,12 @@ class UserDeleteTests(AuthenticatedUserTestCase):
|
|
'detail': "You can't delete users that made more than 5 posts.",
|
|
'detail': "You can't delete users that made more than 5 posts.",
|
|
})
|
|
})
|
|
|
|
|
|
- @patch_user_acl
|
|
|
|
- def test_delete_too_old_member(self, patch_user_acl):
|
|
|
|
|
|
+ @patch_user_acl({
|
|
|
|
+ 'can_delete_users_newer_than': 5,
|
|
|
|
+ 'can_delete_users_with_less_posts_than': 0,
|
|
|
|
+ })
|
|
|
|
+ def test_delete_too_old_member(self):
|
|
"""raises 403 error when user is too old"""
|
|
"""raises 403 error when user is too old"""
|
|
- patch_user_acl(
|
|
|
|
- self.user, {
|
|
|
|
- 'can_delete_users_newer_than': 5,
|
|
|
|
- 'can_delete_users_with_less_posts_than': 0,
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
self.other_user.joined_on -= timedelta(days=6)
|
|
self.other_user.joined_on -= timedelta(days=6)
|
|
self.other_user.save()
|
|
self.other_user.save()
|
|
|
|
|
|
@@ -663,32 +641,24 @@ class UserDeleteTests(AuthenticatedUserTestCase):
|
|
'detail': "You can't delete users that are members for more than 5 days.",
|
|
'detail': "You can't delete users that are members for more than 5 days.",
|
|
})
|
|
})
|
|
|
|
|
|
- @patch_user_acl
|
|
|
|
- def test_delete_self(self, patch_user_acl):
|
|
|
|
|
|
+ @patch_user_acl({
|
|
|
|
+ 'can_delete_users_newer_than': 10,
|
|
|
|
+ 'can_delete_users_with_less_posts_than': 10,
|
|
|
|
+ })
|
|
|
|
+ def test_delete_self(self):
|
|
"""raises 403 error when attempting to delete oneself"""
|
|
"""raises 403 error when attempting to delete oneself"""
|
|
- patch_user_acl(
|
|
|
|
- self.user, {
|
|
|
|
- 'can_delete_users_newer_than': 10,
|
|
|
|
- 'can_delete_users_with_less_posts_than': 10,
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
response = self.client.post('/api/users/%s/delete/' % self.user.pk)
|
|
response = self.client.post('/api/users/%s/delete/' % self.user.pk)
|
|
self.assertEqual(response.status_code, 403)
|
|
self.assertEqual(response.status_code, 403)
|
|
self.assertEqual(response.json(), {
|
|
self.assertEqual(response.json(), {
|
|
'detail': "You can't delete your account.",
|
|
'detail': "You can't delete your account.",
|
|
})
|
|
})
|
|
|
|
|
|
- @patch_user_acl
|
|
|
|
- def test_delete_admin(self, patch_user_acl):
|
|
|
|
|
|
+ @patch_user_acl({
|
|
|
|
+ 'can_delete_users_newer_than': 10,
|
|
|
|
+ 'can_delete_users_with_less_posts_than': 10,
|
|
|
|
+ })
|
|
|
|
+ def test_delete_admin(self):
|
|
"""raises 403 error when attempting to delete admin"""
|
|
"""raises 403 error when attempting to delete admin"""
|
|
- patch_user_acl(
|
|
|
|
- self.user, {
|
|
|
|
- 'can_delete_users_newer_than': 10,
|
|
|
|
- 'can_delete_users_with_less_posts_than': 10,
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
self.other_user.is_staff = True
|
|
self.other_user.is_staff = True
|
|
self.other_user.save()
|
|
self.other_user.save()
|
|
|
|
|
|
@@ -698,16 +668,12 @@ class UserDeleteTests(AuthenticatedUserTestCase):
|
|
'detail': "You can't delete administrators.",
|
|
'detail': "You can't delete administrators.",
|
|
})
|
|
})
|
|
|
|
|
|
- @patch_user_acl
|
|
|
|
- def test_delete_superadmin(self, patch_user_acl):
|
|
|
|
|
|
+ @patch_user_acl({
|
|
|
|
+ 'can_delete_users_newer_than': 10,
|
|
|
|
+ 'can_delete_users_with_less_posts_than': 10,
|
|
|
|
+ })
|
|
|
|
+ def test_delete_superadmin(self):
|
|
"""raises 403 error when attempting to delete superadmin"""
|
|
"""raises 403 error when attempting to delete superadmin"""
|
|
- patch_user_acl(
|
|
|
|
- self.user, {
|
|
|
|
- 'can_delete_users_newer_than': 10,
|
|
|
|
- 'can_delete_users_with_less_posts_than': 10,
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
self.other_user.is_superuser = True
|
|
self.other_user.is_superuser = True
|
|
self.other_user.save()
|
|
self.other_user.save()
|
|
|
|
|
|
@@ -717,16 +683,12 @@ class UserDeleteTests(AuthenticatedUserTestCase):
|
|
'detail': "You can't delete administrators.",
|
|
'detail': "You can't delete administrators.",
|
|
})
|
|
})
|
|
|
|
|
|
- @patch_user_acl
|
|
|
|
- def test_delete_with_content(self, patch_user_acl):
|
|
|
|
|
|
+ @patch_user_acl({
|
|
|
|
+ 'can_delete_users_newer_than': 10,
|
|
|
|
+ 'can_delete_users_with_less_posts_than': 10,
|
|
|
|
+ })
|
|
|
|
+ def test_delete_with_content(self):
|
|
"""returns 200 and deletes user with content"""
|
|
"""returns 200 and deletes user with content"""
|
|
- patch_user_acl(
|
|
|
|
- self.user, {
|
|
|
|
- 'can_delete_users_newer_than': 10,
|
|
|
|
- 'can_delete_users_with_less_posts_than': 10,
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
response = self.client.post(
|
|
response = self.client.post(
|
|
self.link,
|
|
self.link,
|
|
json.dumps({
|
|
json.dumps({
|
|
@@ -742,16 +704,12 @@ class UserDeleteTests(AuthenticatedUserTestCase):
|
|
self.assertEqual(Thread.objects.count(), self.threads)
|
|
self.assertEqual(Thread.objects.count(), self.threads)
|
|
self.assertEqual(Post.objects.count(), self.posts)
|
|
self.assertEqual(Post.objects.count(), self.posts)
|
|
|
|
|
|
- @patch_user_acl
|
|
|
|
- def test_delete_without_content(self, patch_user_acl):
|
|
|
|
|
|
+ @patch_user_acl({
|
|
|
|
+ 'can_delete_users_newer_than': 10,
|
|
|
|
+ 'can_delete_users_with_less_posts_than': 10,
|
|
|
|
+ })
|
|
|
|
+ def test_delete_without_content(self):
|
|
"""returns 200 and deletes user without content"""
|
|
"""returns 200 and deletes user without content"""
|
|
- patch_user_acl(
|
|
|
|
- self.user, {
|
|
|
|
- 'can_delete_users_newer_than': 10,
|
|
|
|
- 'can_delete_users_with_less_posts_than': 10,
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
response = self.client.post(
|
|
response = self.client.post(
|
|
self.link,
|
|
self.link,
|
|
json.dumps({
|
|
json.dumps({
|