test_users_api.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. import json
  2. from datetime import timedelta
  3. from django.contrib.auth import get_user_model
  4. from django.urls import reverse
  5. from ...acl.test import patch_user_acl
  6. from ...categories.models import Category
  7. from ...conf.test import override_dynamic_settings
  8. from ...threads.models import Post, Thread
  9. from ...threads.test import post_thread
  10. from ..activepostersranking import build_active_posters_ranking
  11. from ..models import Ban, Rank
  12. from ..test import AuthenticatedUserTestCase, create_test_user
  13. User = get_user_model()
  14. class ActivePostersListTests(AuthenticatedUserTestCase):
  15. """tests for active posters list (GET /users/?list=active)"""
  16. def setUp(self):
  17. super().setUp()
  18. self.link = "/api/users/?list=active"
  19. self.category = Category.objects.all_categories()[:1][0]
  20. self.category.labels = []
  21. def test_empty_list(self):
  22. """empty list is served"""
  23. response = self.client.get(self.link)
  24. self.assertEqual(response.status_code, 200)
  25. self.assertNotContains(response, self.user.username)
  26. response = self.client.get(self.link)
  27. self.assertEqual(response.status_code, 200)
  28. self.assertNotContains(response, self.user.username)
  29. def test_filled_list(self):
  30. """filled list is served"""
  31. post_thread(self.category, poster=self.user)
  32. self.user.posts = 1
  33. self.user.save()
  34. build_active_posters_ranking()
  35. response = self.client.get(self.link)
  36. self.assertEqual(response.status_code, 200)
  37. self.assertContains(response, self.user.username)
  38. self.assertContains(response, '"is_online":true')
  39. self.assertContains(response, '"is_offline":false')
  40. self.logout_user()
  41. build_active_posters_ranking()
  42. response = self.client.get(self.link)
  43. self.assertEqual(response.status_code, 200)
  44. self.assertContains(response, self.user.username)
  45. self.assertContains(response, '"is_online":false')
  46. self.assertContains(response, '"is_offline":true')
  47. class FollowersListTests(AuthenticatedUserTestCase):
  48. """tests for generic list (GET /users/) filtered by followers"""
  49. def setUp(self):
  50. super().setUp()
  51. self.link = "/api/users/%s/followers/"
  52. def test_nonexistent_user(self):
  53. """list for non-existing user returns 404"""
  54. response = self.client.get(self.link % 31242)
  55. self.assertEqual(response.status_code, 404)
  56. def test_empty_list(self):
  57. """user without followers returns 200"""
  58. response = self.client.get(self.link % self.user.pk)
  59. self.assertEqual(response.status_code, 200)
  60. def test_filled_list(self):
  61. """user with followers returns 200"""
  62. follower = create_test_user("TestFollower", "test@follower.com")
  63. self.user.followed_by.add(follower)
  64. response = self.client.get(self.link % self.user.pk)
  65. self.assertEqual(response.status_code, 200)
  66. self.assertContains(response, follower.username)
  67. def test_filled_list_search(self):
  68. """followers list is searchable"""
  69. follower = create_test_user("TestFollower", "test@follower.com")
  70. self.user.followed_by.add(follower)
  71. api_link = self.link % self.user.pk
  72. response = self.client.get("%s?search=%s" % (api_link, "test"))
  73. self.assertEqual(response.status_code, 200)
  74. self.assertContains(response, follower.username)
  75. class FollowsListTests(AuthenticatedUserTestCase):
  76. """tests for generic list (GET /users/) filtered by follows"""
  77. def setUp(self):
  78. super().setUp()
  79. self.link = "/api/users/%s/follows/"
  80. def test_nonexistent_user(self):
  81. """list for non-existing user returns 404"""
  82. response = self.client.get(self.link % 1321)
  83. self.assertEqual(response.status_code, 404)
  84. def test_empty_list(self):
  85. """user without follows returns 200"""
  86. response = self.client.get(self.link % self.user.pk)
  87. self.assertEqual(response.status_code, 200)
  88. def test_filled_list(self):
  89. """user with follows returns 200"""
  90. follower = create_test_user("TestFollower", "test@follower.com")
  91. self.user.follows.add(follower)
  92. response = self.client.get(self.link % self.user.pk)
  93. self.assertEqual(response.status_code, 200)
  94. self.assertContains(response, follower.username)
  95. def test_filled_list_search(self):
  96. """follows list is searchable"""
  97. follower = create_test_user("TestFollower", "test@follower.com")
  98. self.user.follows.add(follower)
  99. api_link = self.link % self.user.pk
  100. response = self.client.get("%s?search=%s" % (api_link, "test"))
  101. self.assertEqual(response.status_code, 200)
  102. self.assertContains(response, follower.username)
  103. class RankListTests(AuthenticatedUserTestCase):
  104. """tests for generic list (GET /users/) filtered by rank"""
  105. def setUp(self):
  106. super().setUp()
  107. self.link = "/api/users/?rank=%s"
  108. def test_nonexistent_rank(self):
  109. """list for non-existing rank returns 404"""
  110. response = self.client.get(self.link % 1421)
  111. self.assertEqual(response.status_code, 404)
  112. def test_empty_list(self):
  113. """tab rank without members returns 200"""
  114. test_rank = Rank.objects.create(name="Test rank", slug="test-rank", is_tab=True)
  115. response = self.client.get(self.link % test_rank.pk)
  116. self.assertEqual(response.status_code, 200)
  117. def test_disabled_list(self):
  118. """non-tab rank returns 404"""
  119. self.user.rank.is_tab = False
  120. self.user.rank.save()
  121. response = self.client.get(self.link % self.user.rank.pk)
  122. self.assertEqual(response.status_code, 404)
  123. def test_list_search(self):
  124. """rank list is not searchable"""
  125. api_link = self.link % self.user.rank.pk
  126. response = self.client.get("%s&name=%s" % (api_link, "test"))
  127. self.assertEqual(response.status_code, 404)
  128. def test_filled_list(self):
  129. """tab rank with members return 200"""
  130. self.user.rank.is_tab = True
  131. self.user.rank.save()
  132. response = self.client.get(self.link % self.user.rank.pk)
  133. self.assertEqual(response.status_code, 200)
  134. self.assertContains(response, self.user.username)
  135. def test_disabled_users(self):
  136. """api follows disabled users visibility"""
  137. rank = Rank.objects.create(name="Test rank", slug="test-rank", is_tab=True)
  138. user = create_test_user(
  139. "DisabledUser", "disabled@example.com", rank=rank, is_active=False
  140. )
  141. response = self.client.get(self.link % rank.pk)
  142. self.assertNotContains(response, user.get_absolute_url())
  143. # api shows disabled accounts to staff
  144. self.user.is_staff = True
  145. self.user.save()
  146. response = self.client.get(self.link % rank.pk)
  147. self.assertContains(response, user.get_absolute_url())
  148. class SearchNamesListTests(AuthenticatedUserTestCase):
  149. """tests for generic list (GET /users/) filtered by username disallowing searches"""
  150. def setUp(self):
  151. super().setUp()
  152. self.link = "/api/users/?&name="
  153. def test_empty_list(self):
  154. """empty list returns 404"""
  155. response = self.client.get(self.link + "this-user-is-fake")
  156. self.assertEqual(response.status_code, 404)
  157. def test_filled_list(self):
  158. """results list returns 404"""
  159. response = self.client.get(self.link + self.user.slug)
  160. self.assertEqual(response.status_code, 404)
  161. class UserRetrieveTests(AuthenticatedUserTestCase):
  162. def setUp(self):
  163. super().setUp()
  164. self.other_user = create_test_user("OtherUser", "otheruser@example.com")
  165. self.link = reverse("misago:api:user-detail", kwargs={"pk": self.other_user.pk})
  166. def test_get_user(self):
  167. """api user retrieve endpoint has no showstoppers"""
  168. response = self.client.get(self.link)
  169. self.assertEqual(response.status_code, 200)
  170. def test_disabled_user(self):
  171. """api user retrieve handles disabled users"""
  172. self.user.is_staff = False
  173. self.user.save()
  174. self.other_user.is_active = False
  175. self.other_user.save()
  176. response = self.client.get(self.link)
  177. self.assertEqual(response.status_code, 404)
  178. self.user.is_staff = True
  179. self.user.save()
  180. response = self.client.get(self.link)
  181. self.assertEqual(response.status_code, 200)
  182. class UserForumOptionsTests(AuthenticatedUserTestCase):
  183. """tests for user forum options RPC (POST to /api/users/1/forum-options/)"""
  184. def setUp(self):
  185. super().setUp()
  186. self.link = "/api/users/%s/forum-options/" % self.user.pk
  187. def test_empty_request(self):
  188. """empty request is handled"""
  189. response = self.client.post(self.link)
  190. self.assertEqual(response.status_code, 400)
  191. self.assertEqual(
  192. response.json(),
  193. {
  194. "limits_private_thread_invites_to": ["This field is required."],
  195. "subscribe_to_started_threads": ["This field is required."],
  196. "subscribe_to_replied_threads": ["This field is required."],
  197. },
  198. )
  199. def test_change_forum_invalid_ranges(self):
  200. """api validates ranges for fields"""
  201. response = self.client.post(
  202. self.link,
  203. data={
  204. "limits_private_thread_invites_to": 541,
  205. "subscribe_to_started_threads": 44,
  206. "subscribe_to_replied_threads": 321,
  207. },
  208. )
  209. self.assertEqual(response.status_code, 400)
  210. self.assertEqual(
  211. response.json(),
  212. {
  213. "limits_private_thread_invites_to": ['"541" is not a valid choice.'],
  214. "subscribe_to_started_threads": ['"44" is not a valid choice.'],
  215. "subscribe_to_replied_threads": ['"321" is not a valid choice.'],
  216. },
  217. )
  218. def test_change_forum_options(self):
  219. """forum options are changed"""
  220. response = self.client.post(
  221. self.link,
  222. data={
  223. "limits_private_thread_invites_to": 1,
  224. "subscribe_to_started_threads": 2,
  225. "subscribe_to_replied_threads": 1,
  226. },
  227. )
  228. self.assertEqual(response.status_code, 200)
  229. self.reload_user()
  230. self.assertFalse(self.user.is_hiding_presence)
  231. self.assertEqual(self.user.limits_private_thread_invites_to, 1)
  232. self.assertEqual(self.user.subscribe_to_started_threads, 2)
  233. self.assertEqual(self.user.subscribe_to_replied_threads, 1)
  234. response = self.client.post(
  235. self.link,
  236. data={
  237. "is_hiding_presence": True,
  238. "limits_private_thread_invites_to": 1,
  239. "subscribe_to_started_threads": 2,
  240. "subscribe_to_replied_threads": 1,
  241. },
  242. )
  243. self.assertEqual(response.status_code, 200)
  244. self.reload_user()
  245. self.assertTrue(self.user.is_hiding_presence)
  246. self.assertEqual(self.user.limits_private_thread_invites_to, 1)
  247. self.assertEqual(self.user.subscribe_to_started_threads, 2)
  248. self.assertEqual(self.user.subscribe_to_replied_threads, 1)
  249. response = self.client.post(
  250. self.link,
  251. data={
  252. "is_hiding_presence": False,
  253. "limits_private_thread_invites_to": 1,
  254. "subscribe_to_started_threads": 2,
  255. "subscribe_to_replied_threads": 1,
  256. },
  257. )
  258. self.assertEqual(response.status_code, 200)
  259. self.reload_user()
  260. self.assertFalse(self.user.is_hiding_presence)
  261. self.assertEqual(self.user.limits_private_thread_invites_to, 1)
  262. self.assertEqual(self.user.subscribe_to_started_threads, 2)
  263. self.assertEqual(self.user.subscribe_to_replied_threads, 1)
  264. class UserFollowTests(AuthenticatedUserTestCase):
  265. """tests for user follow RPC (POST to /api/users/1/follow/)"""
  266. def setUp(self):
  267. super().setUp()
  268. self.other_user = create_test_user("OtherUser", "otheruser@example.com")
  269. self.link = "/api/users/%s/follow/" % self.other_user.pk
  270. def test_follow_unauthenticated(self):
  271. """you have to sign in to follow users"""
  272. self.logout_user()
  273. response = self.client.post(self.link)
  274. self.assertEqual(response.status_code, 403)
  275. self.assertEqual(
  276. response.json(), {"detail": "This action is not available to guests."}
  277. )
  278. def test_follow_myself(self):
  279. """you can't follow yourself"""
  280. response = self.client.post("/api/users/%s/follow/" % self.user.pk)
  281. self.assertEqual(response.status_code, 403)
  282. self.assertEqual(
  283. response.json(), {"detail": "You can't add yourself to followed."}
  284. )
  285. @patch_user_acl({"can_follow_users": 0})
  286. def test_cant_follow(self):
  287. """no permission to follow users"""
  288. response = self.client.post(self.link)
  289. self.assertEqual(response.status_code, 403)
  290. self.assertEqual(response.json(), {"detail": "You can't follow other users."})
  291. def test_follow(self):
  292. """follow and unfollow other user"""
  293. response = self.client.post(self.link)
  294. self.assertEqual(response.status_code, 200)
  295. self.user.refresh_from_db()
  296. self.assertEqual(self.user.followers, 0)
  297. self.assertEqual(self.user.following, 1)
  298. self.assertEqual(self.user.follows.count(), 1)
  299. self.assertEqual(self.user.followed_by.count(), 0)
  300. self.other_user.refresh_from_db()
  301. self.assertEqual(self.other_user.followers, 1)
  302. self.assertEqual(self.other_user.following, 0)
  303. self.assertEqual(self.other_user.follows.count(), 0)
  304. self.assertEqual(self.other_user.followed_by.count(), 1)
  305. response = self.client.post(self.link)
  306. self.assertEqual(response.status_code, 200)
  307. self.user.refresh_from_db()
  308. self.assertEqual(self.user.followers, 0)
  309. self.assertEqual(self.user.following, 0)
  310. self.assertEqual(self.user.follows.count(), 0)
  311. self.assertEqual(self.user.followed_by.count(), 0)
  312. self.other_user.refresh_from_db()
  313. self.assertEqual(self.other_user.followers, 0)
  314. self.assertEqual(self.other_user.following, 0)
  315. self.assertEqual(self.other_user.follows.count(), 0)
  316. self.assertEqual(self.other_user.followed_by.count(), 0)
  317. class UserBanTests(AuthenticatedUserTestCase):
  318. """tests for ban endpoint (GET to /api/users/1/ban/)"""
  319. def setUp(self):
  320. super().setUp()
  321. self.other_user = create_test_user("OtherUser", "otheruser@example.com")
  322. self.link = "/api/users/%s/ban/" % self.other_user.pk
  323. @patch_user_acl({"can_see_ban_details": 0})
  324. def test_no_permission(self):
  325. """user has no permission to access ban"""
  326. response = self.client.get(self.link)
  327. self.assertEqual(response.status_code, 403)
  328. self.assertEqual(
  329. response.json(), {"detail": "You can't see users bans details."}
  330. )
  331. @patch_user_acl({"can_see_ban_details": 1})
  332. def test_no_ban(self):
  333. """api returns empty json"""
  334. response = self.client.get(self.link)
  335. self.assertEqual(response.status_code, 200)
  336. self.assertEqual(response.json(), {})
  337. @patch_user_acl({"can_see_ban_details": 1})
  338. def test_ban_details(self):
  339. """api returns ban json"""
  340. Ban.objects.create(
  341. check_type=Ban.USERNAME,
  342. banned_value=self.other_user.username,
  343. user_message="Nope!",
  344. )
  345. response = self.client.get(self.link)
  346. self.assertEqual(response.status_code, 200)
  347. ban_json = response.json()
  348. self.assertEqual(ban_json["user_message"]["plain"], "Nope!")
  349. self.assertEqual(ban_json["user_message"]["html"], "<p>Nope!</p>")
  350. class UserDeleteOwnAccountTests(AuthenticatedUserTestCase):
  351. """
  352. tests for user request own account delete RPC
  353. (POST to /api/users/1/delete-own-account/)
  354. """
  355. def setUp(self):
  356. super().setUp()
  357. self.api_link = "/api/users/%s/delete-own-account/" % self.user.pk
  358. @override_dynamic_settings(allow_delete_own_account=False)
  359. def test_delete_own_account_feature_disabled(self):
  360. """
  361. raises 403 error when attempting to delete own account but feature is disabled
  362. """
  363. response = self.client.post(self.api_link, {"password": self.USER_PASSWORD})
  364. self.assertEqual(response.status_code, 403)
  365. self.assertEqual(response.json(), {"detail": "You can't delete your account."})
  366. self.reload_user()
  367. self.assertTrue(self.user.is_active)
  368. self.assertFalse(self.user.is_deleting_account)
  369. @override_dynamic_settings(allow_delete_own_account=True)
  370. def test_delete_own_account_is_staff(self):
  371. """raises 403 error when attempting to delete own account as admin"""
  372. self.user.is_staff = True
  373. self.user.save()
  374. response = self.client.post(self.api_link, {"password": self.USER_PASSWORD})
  375. self.assertEqual(response.status_code, 403)
  376. self.assertEqual(
  377. response.json(),
  378. {
  379. "detail": (
  380. "You can't delete your account because you are an administrator."
  381. )
  382. },
  383. )
  384. self.reload_user()
  385. self.assertTrue(self.user.is_active)
  386. self.assertFalse(self.user.is_deleting_account)
  387. @override_dynamic_settings(allow_delete_own_account=True)
  388. def test_delete_own_account_is_superuser(self):
  389. """raises 403 error when attempting to delete own account as superadmin"""
  390. self.user.is_superuser = True
  391. self.user.save()
  392. response = self.client.post(self.api_link, {"password": self.USER_PASSWORD})
  393. self.assertEqual(response.status_code, 403)
  394. self.assertEqual(
  395. response.json(),
  396. {
  397. "detail": (
  398. "You can't delete your account because you are an administrator."
  399. )
  400. },
  401. )
  402. self.reload_user()
  403. self.assertTrue(self.user.is_active)
  404. self.assertFalse(self.user.is_deleting_account)
  405. @override_dynamic_settings(allow_delete_own_account=True)
  406. def test_delete_own_account_invalid_password(self):
  407. """
  408. raises 400 error when attempting to delete own account with invalid password
  409. """
  410. response = self.client.post(self.api_link, {"password": "hello"})
  411. self.assertEqual(response.status_code, 400)
  412. self.assertEqual(
  413. response.json(), {"password": ["Entered password is invalid."]}
  414. )
  415. self.reload_user()
  416. self.assertTrue(self.user.is_active)
  417. self.assertFalse(self.user.is_deleting_account)
  418. @override_dynamic_settings(allow_delete_own_account=True)
  419. def test_delete_own_account(self):
  420. """deactivates account and marks it for deletion"""
  421. response = self.client.post(self.api_link, {"password": self.USER_PASSWORD})
  422. self.assertEqual(response.status_code, 200)
  423. self.reload_user()
  424. self.assertFalse(self.user.is_active)
  425. self.assertTrue(self.user.is_deleting_account)
  426. class UserDeleteTests(AuthenticatedUserTestCase):
  427. """tests for user delete RPC (POST to /api/users/1/delete/)"""
  428. def setUp(self):
  429. super().setUp()
  430. self.other_user = create_test_user("OtherUser", "otheruser@example.com")
  431. self.link = "/api/users/%s/delete/" % self.other_user.pk
  432. self.threads = Thread.objects.count()
  433. self.posts = Post.objects.count()
  434. self.category = Category.objects.all_categories()[:1][0]
  435. post_thread(self.category, poster=self.other_user)
  436. self.other_user.posts = 1
  437. self.other_user.threads = 1
  438. self.other_user.save()
  439. @patch_user_acl(
  440. {"can_delete_users_newer_than": 0, "can_delete_users_with_less_posts_than": 0}
  441. )
  442. def test_delete_no_permission(self):
  443. """raises 403 error when no permission to delete"""
  444. response = self.client.post(self.link)
  445. self.assertEqual(response.status_code, 403)
  446. self.assertEqual(response.json(), {"detail": "You can't delete users."})
  447. @patch_user_acl(
  448. {"can_delete_users_newer_than": 0, "can_delete_users_with_less_posts_than": 5}
  449. )
  450. def test_delete_too_many_posts(self):
  451. """raises 403 error when user has too many posts"""
  452. self.other_user.posts = 6
  453. self.other_user.save()
  454. response = self.client.post(self.link)
  455. self.assertEqual(response.status_code, 403)
  456. self.assertEqual(
  457. response.json(),
  458. {"detail": "You can't delete users that made more than 5 posts."},
  459. )
  460. @patch_user_acl(
  461. {"can_delete_users_newer_than": 5, "can_delete_users_with_less_posts_than": 0}
  462. )
  463. def test_delete_too_old_member(self):
  464. """raises 403 error when user is too old"""
  465. self.other_user.joined_on -= timedelta(days=6)
  466. self.other_user.save()
  467. response = self.client.post(self.link)
  468. self.assertEqual(response.status_code, 403)
  469. self.assertEqual(response.status_code, 403)
  470. self.assertEqual(
  471. response.json(),
  472. {"detail": "You can't delete users that are members for more than 5 days."},
  473. )
  474. @patch_user_acl(
  475. {"can_delete_users_newer_than": 10, "can_delete_users_with_less_posts_than": 10}
  476. )
  477. def test_delete_self(self):
  478. """raises 403 error when attempting to delete oneself"""
  479. response = self.client.post("/api/users/%s/delete/" % self.user.pk)
  480. self.assertEqual(response.status_code, 403)
  481. self.assertEqual(response.json(), {"detail": "You can't delete your account."})
  482. @patch_user_acl(
  483. {"can_delete_users_newer_than": 10, "can_delete_users_with_less_posts_than": 10}
  484. )
  485. def test_delete_admin(self):
  486. """raises 403 error when attempting to delete admin"""
  487. self.other_user.is_staff = True
  488. self.other_user.save()
  489. response = self.client.post(self.link)
  490. self.assertEqual(response.status_code, 403)
  491. self.assertEqual(
  492. response.json(), {"detail": "You can't delete administrators."}
  493. )
  494. @patch_user_acl(
  495. {"can_delete_users_newer_than": 10, "can_delete_users_with_less_posts_than": 10}
  496. )
  497. def test_delete_superadmin(self):
  498. """raises 403 error when attempting to delete superadmin"""
  499. self.other_user.is_superuser = True
  500. self.other_user.save()
  501. response = self.client.post(self.link)
  502. self.assertEqual(response.status_code, 403)
  503. self.assertEqual(
  504. response.json(), {"detail": "You can't delete administrators."}
  505. )
  506. @patch_user_acl(
  507. {"can_delete_users_newer_than": 10, "can_delete_users_with_less_posts_than": 10}
  508. )
  509. def test_delete_with_content(self):
  510. """returns 200 and deletes user with content"""
  511. response = self.client.post(
  512. self.link,
  513. json.dumps({"with_content": True}),
  514. content_type="application/json",
  515. )
  516. self.assertEqual(response.status_code, 200)
  517. with self.assertRaises(User.DoesNotExist):
  518. self.other_user.refresh_from_db()
  519. self.assertEqual(Thread.objects.count(), self.threads)
  520. self.assertEqual(Post.objects.count(), self.posts)
  521. @patch_user_acl(
  522. {"can_delete_users_newer_than": 10, "can_delete_users_with_less_posts_than": 10}
  523. )
  524. def test_delete_without_content(self):
  525. """returns 200 and deletes user without content"""
  526. response = self.client.post(
  527. self.link,
  528. json.dumps({"with_content": False}),
  529. content_type="application/json",
  530. )
  531. self.assertEqual(response.status_code, 200)
  532. with self.assertRaises(User.DoesNotExist):
  533. self.other_user.refresh_from_db()
  534. self.assertEqual(Thread.objects.count(), self.threads + 1)
  535. self.assertEqual(Post.objects.count(), self.posts + 2)