test_thread_patch_api.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. import json
  2. from datetime import timedelta
  3. from django.utils import six, timezone
  4. from misago.acl.testutils import override_acl
  5. from misago.categories.models import Category
  6. from .test_threads_api import ThreadsApiTestCase
  7. class ThreadPatchApiTestCase(ThreadsApiTestCase):
  8. def patch(self, api_link, ops):
  9. return self.client.patch(
  10. api_link, json.dumps(ops), content_type="application/json")
  11. class ThreadAddAclApiTests(ThreadPatchApiTestCase):
  12. def test_add_acl_true(self):
  13. """api adds current thread's acl to response"""
  14. response = self.patch(self.api_link, [
  15. {'op': 'add', 'path': 'acl', 'value': True}
  16. ])
  17. self.assertEqual(response.status_code, 200)
  18. response_json = response.json()
  19. self.assertTrue(response_json['acl'])
  20. def test_add_acl_false(self):
  21. """if value is false, api won't add acl to the response, but will set empty key"""
  22. response = self.patch(self.api_link, [
  23. {'op': 'add', 'path': 'acl', 'value': False}
  24. ])
  25. self.assertEqual(response.status_code, 200)
  26. response_json = response.json()
  27. self.assertIsNone(response_json['acl'])
  28. class ThreadChangeTitleApiTests(ThreadPatchApiTestCase):
  29. def test_change_thread_title(self):
  30. """api makes it possible to change thread title"""
  31. self.override_acl({
  32. 'can_edit_threads': 2
  33. })
  34. response = self.patch(self.api_link, [
  35. {'op': 'replace', 'path': 'title', 'value': "Lorem ipsum change!"}
  36. ])
  37. self.assertEqual(response.status_code, 200)
  38. thread_json = self.get_thread_json()
  39. self.assertEqual(thread_json['title'], "Lorem ipsum change!")
  40. def test_change_thread_title_no_permission(self):
  41. """api validates permission to change title"""
  42. self.override_acl({
  43. 'can_edit_threads': 0
  44. })
  45. response = self.patch(self.api_link, [
  46. {'op': 'replace', 'path': 'title', 'value': "Lorem ipsum change!"}
  47. ])
  48. self.assertEqual(response.status_code, 400)
  49. response_json = response.json()
  50. self.assertEqual(response_json['detail'][0],
  51. "You can't edit threads in this category.")
  52. def test_change_thread_title_after_edit_time(self):
  53. """api cleans, validates and rejects too short title"""
  54. self.override_acl({
  55. 'thread_edit_time': 1,
  56. 'can_edit_threads': 1
  57. })
  58. self.thread.starter = self.user
  59. self.thread.started_on = timezone.now() - timedelta(minutes=10)
  60. self.thread.save()
  61. response = self.patch(self.api_link, [
  62. {'op': 'replace', 'path': 'title', 'value': "Lorem ipsum change!"}
  63. ])
  64. self.assertEqual(response.status_code, 400)
  65. response_json = response.json()
  66. self.assertEqual(response_json['detail'][0],
  67. "You can't edit threads that are older than 1 minute.")
  68. def test_change_thread_title_invalid(self):
  69. """api cleans, validates and rejects too short title"""
  70. self.override_acl({
  71. 'can_edit_threads': 2
  72. })
  73. response = self.patch(self.api_link, [
  74. {'op': 'replace', 'path': 'title', 'value': 12}
  75. ])
  76. self.assertEqual(response.status_code, 400)
  77. response_json = response.json()
  78. self.assertEqual(response_json['detail'][0],
  79. "Thread title should be at least 5 characters long (it has 2).")
  80. class ThreadPinGloballyApiTests(ThreadPatchApiTestCase):
  81. def test_pin_thread(self):
  82. """api makes it possible to pin globally thread"""
  83. self.override_acl({
  84. 'can_pin_threads': 2
  85. })
  86. response = self.patch(self.api_link, [
  87. {'op': 'replace', 'path': 'weight', 'value': 2}
  88. ])
  89. self.assertEqual(response.status_code, 200)
  90. thread_json = self.get_thread_json()
  91. self.assertEqual(thread_json['weight'], 2)
  92. def test_unpin_thread(self):
  93. """api makes it possible to unpin thread"""
  94. self.thread.weight = 2
  95. self.thread.save()
  96. thread_json = self.get_thread_json()
  97. self.assertEqual(thread_json['weight'], 2)
  98. self.override_acl({
  99. 'can_pin_threads': 2
  100. })
  101. response = self.patch(self.api_link, [
  102. {'op': 'replace', 'path': 'weight', 'value': 0}
  103. ])
  104. self.assertEqual(response.status_code, 200)
  105. thread_json = self.get_thread_json()
  106. self.assertEqual(thread_json['weight'], 0)
  107. def test_pin_thread_no_permission(self):
  108. """api pin thread globally with no permission fails"""
  109. self.override_acl({
  110. 'can_pin_threads': 1
  111. })
  112. response = self.patch(self.api_link, [
  113. {'op': 'replace', 'path': 'weight', 'value': 2}
  114. ])
  115. self.assertEqual(response.status_code, 400)
  116. response_json = response.json()
  117. self.assertEqual(response_json['detail'][0],
  118. "You don't have permission to pin this thread globally.")
  119. thread_json = self.get_thread_json()
  120. self.assertEqual(thread_json['weight'], 0)
  121. def test_unpin_thread_no_permission(self):
  122. """api unpin thread with no permission fails"""
  123. self.thread.weight = 2
  124. self.thread.save()
  125. thread_json = self.get_thread_json()
  126. self.assertEqual(thread_json['weight'], 2)
  127. self.override_acl({
  128. 'can_pin_threads': 1
  129. })
  130. response = self.patch(self.api_link, [
  131. {'op': 'replace', 'path': 'weight', 'value': 1}
  132. ])
  133. self.assertEqual(response.status_code, 400)
  134. response_json = response.json()
  135. self.assertEqual(response_json['detail'][0],
  136. "You don't have permission to change this thread's weight.")
  137. thread_json = self.get_thread_json()
  138. self.assertEqual(thread_json['weight'], 2)
  139. class ThreadPinLocallyApiTests(ThreadPatchApiTestCase):
  140. def test_pin_thread(self):
  141. """api makes it possible to pin locally thread"""
  142. self.override_acl({
  143. 'can_pin_threads': 1
  144. })
  145. response = self.patch(self.api_link, [
  146. {'op': 'replace', 'path': 'weight', 'value': 1}
  147. ])
  148. self.assertEqual(response.status_code, 200)
  149. thread_json = self.get_thread_json()
  150. self.assertEqual(thread_json['weight'], 1)
  151. def test_unpin_thread(self):
  152. """api makes it possible to unpin thread"""
  153. self.thread.weight = 1
  154. self.thread.save()
  155. thread_json = self.get_thread_json()
  156. self.assertEqual(thread_json['weight'], 1)
  157. self.override_acl({
  158. 'can_pin_threads': 1
  159. })
  160. response = self.patch(self.api_link, [
  161. {'op': 'replace', 'path': 'weight', 'value': 0}
  162. ])
  163. self.assertEqual(response.status_code, 200)
  164. thread_json = self.get_thread_json()
  165. self.assertEqual(thread_json['weight'], 0)
  166. def test_pin_thread_no_permission(self):
  167. """api pin thread locally with no permission fails"""
  168. self.override_acl({
  169. 'can_pin_threads': 0
  170. })
  171. response = self.patch(self.api_link, [
  172. {'op': 'replace', 'path': 'weight', 'value': 1}
  173. ])
  174. self.assertEqual(response.status_code, 400)
  175. response_json = response.json()
  176. self.assertEqual(response_json['detail'][0],
  177. "You don't have permission to change this thread's weight.")
  178. thread_json = self.get_thread_json()
  179. self.assertEqual(thread_json['weight'], 0)
  180. def test_unpin_thread_no_permission(self):
  181. """api unpin thread with no permission fails"""
  182. self.thread.weight = 1
  183. self.thread.save()
  184. thread_json = self.get_thread_json()
  185. self.assertEqual(thread_json['weight'], 1)
  186. self.override_acl({
  187. 'can_pin_threads': 0
  188. })
  189. response = self.patch(self.api_link, [
  190. {'op': 'replace', 'path': 'weight', 'value': 0}
  191. ])
  192. self.assertEqual(response.status_code, 400)
  193. response_json = response.json()
  194. self.assertEqual(response_json['detail'][0],
  195. "You don't have permission to change this thread's weight.")
  196. thread_json = self.get_thread_json()
  197. self.assertEqual(thread_json['weight'], 1)
  198. class ThreadMoveApiTests(ThreadPatchApiTestCase):
  199. def setUp(self):
  200. super(ThreadMoveApiTests, self).setUp()
  201. Category(
  202. name='Category B',
  203. slug='category-b',
  204. ).insert_at(self.category, position='last-child', save=True)
  205. self.category_b = Category.objects.get(slug='category-b')
  206. def override_other_acl(self, acl):
  207. other_category_acl = self.user.acl_cache['categories'][self.category.pk].copy()
  208. other_category_acl.update({
  209. 'can_see': 1,
  210. 'can_browse': 1,
  211. 'can_see_all_threads': 1,
  212. 'can_see_own_threads': 0,
  213. 'can_hide_threads': 0,
  214. 'can_approve_content': 0,
  215. })
  216. other_category_acl.update(acl)
  217. categories_acl = self.user.acl_cache['categories']
  218. categories_acl[self.category_b.pk] = other_category_acl
  219. visible_categories = [self.category.pk]
  220. if other_category_acl['can_see']:
  221. visible_categories.append(self.category_b.pk)
  222. override_acl(self.user, {
  223. 'visible_categories': visible_categories,
  224. 'categories': categories_acl,
  225. })
  226. def test_move_thread_no_top(self):
  227. """api moves thread to other category, sets no top category"""
  228. self.override_acl({
  229. 'can_move_threads': True
  230. })
  231. self.override_other_acl({
  232. 'can_start_threads': 2
  233. })
  234. response = self.patch(self.api_link, [
  235. {'op': 'replace', 'path': 'category', 'value': self.category_b.pk},
  236. {'op': 'add', 'path': 'top-category', 'value': self.category_b.pk},
  237. {'op': 'replace', 'path': 'flatten-categories', 'value': None},
  238. ])
  239. self.assertEqual(response.status_code, 200)
  240. self.override_other_acl({})
  241. thread_json = self.get_thread_json()
  242. self.assertEqual(thread_json['category']['id'], self.category_b.pk)
  243. reponse_json = response.json()
  244. self.assertEqual(reponse_json['category'], self.category_b.pk)
  245. self.assertEqual(reponse_json['top_category'], None)
  246. def test_move_thread_with_top(self):
  247. """api moves thread to other category, sets top"""
  248. self.override_acl({
  249. 'can_move_threads': True
  250. })
  251. self.override_other_acl({
  252. 'can_start_threads': 2
  253. })
  254. response = self.patch(self.api_link, [
  255. {'op': 'replace', 'path': 'category', 'value': self.category_b.pk},
  256. {
  257. 'op': 'add',
  258. 'path': 'top-category',
  259. 'value': Category.objects.root_category().pk,
  260. },
  261. {'op': 'replace', 'path': 'flatten-categories', 'value': None},
  262. ])
  263. self.assertEqual(response.status_code, 200)
  264. self.override_other_acl({})
  265. thread_json = self.get_thread_json()
  266. self.assertEqual(thread_json['category']['id'], self.category_b.pk)
  267. reponse_json = response.json()
  268. self.assertEqual(reponse_json['category'], self.category_b.pk)
  269. self.assertEqual(reponse_json['top_category'], self.category.pk)
  270. def test_move_thread_no_permission(self):
  271. """api move thread to other category with no permission fails"""
  272. self.override_acl({
  273. 'can_move_threads': False
  274. })
  275. self.override_other_acl({})
  276. response = self.patch(self.api_link, [
  277. {'op': 'replace', 'path': 'category', 'value': self.category_b.pk}
  278. ])
  279. self.assertEqual(response.status_code, 400)
  280. response_json = response.json()
  281. self.assertEqual(response_json['detail'][0],
  282. "You don't have permission to move this thread.")
  283. self.override_other_acl({})
  284. thread_json = self.get_thread_json()
  285. self.assertEqual(thread_json['category']['id'], self.category.pk)
  286. def test_move_thread_no_category_access(self):
  287. """api move thread to category with no access fails"""
  288. self.override_acl({
  289. 'can_move_threads': True
  290. })
  291. self.override_other_acl({
  292. 'can_see': False
  293. })
  294. response = self.patch(self.api_link, [
  295. {'op': 'replace', 'path': 'category', 'value': self.category_b.pk}
  296. ])
  297. self.assertEqual(response.status_code, 400)
  298. response_json = response.json()
  299. self.assertEqual(response_json['detail'][0], 'NOT FOUND')
  300. self.override_other_acl({})
  301. thread_json = self.get_thread_json()
  302. self.assertEqual(thread_json['category']['id'], self.category.pk)
  303. def test_move_thread_no_category_browse(self):
  304. """api move thread to category with no browsing access fails"""
  305. self.override_acl({
  306. 'can_move_threads': True
  307. })
  308. self.override_other_acl({
  309. 'can_browse': False
  310. })
  311. response = self.patch(self.api_link, [
  312. {'op': 'replace', 'path': 'category', 'value': self.category_b.pk}
  313. ])
  314. self.assertEqual(response.status_code, 400)
  315. response_json = response.json()
  316. self.assertEqual(response_json['detail'][0],
  317. 'You don\'t have permission to browse "Category B" contents.')
  318. self.override_other_acl({})
  319. thread_json = self.get_thread_json()
  320. self.assertEqual(thread_json['category']['id'], self.category.pk)
  321. def test_move_thread_same_category(self):
  322. """api move thread to category it's already in fails"""
  323. self.override_acl({
  324. 'can_move_threads': True
  325. })
  326. self.override_other_acl({
  327. 'can_start_threads': 2
  328. })
  329. response = self.patch(self.api_link, [
  330. {'op': 'replace', 'path': 'category', 'value': self.thread.category_id}
  331. ])
  332. self.assertEqual(response.status_code, 400)
  333. response_json = response.json()
  334. self.assertEqual(response_json['detail'][0],
  335. "You can't move thread to the category it's already in.")
  336. self.override_other_acl({})
  337. thread_json = self.get_thread_json()
  338. self.assertEqual(thread_json['category']['id'], self.category.pk)
  339. def test_thread_flatten_categories(self):
  340. """api flatten thread categories"""
  341. response = self.patch(self.api_link, [
  342. {'op': 'replace', 'path': 'flatten-categories', 'value': None}
  343. ])
  344. self.assertEqual(response.status_code, 200)
  345. response_json = response.json()
  346. self.assertEqual(response_json['category'], self.category.pk)
  347. def test_thread_top_flatten_categories(self):
  348. """api flatten thread with top category"""
  349. self.thread.category = self.category_b
  350. self.thread.save()
  351. self.override_other_acl({})
  352. response = self.patch(self.api_link, [
  353. {
  354. 'op': 'add',
  355. 'path': 'top-category',
  356. 'value': Category.objects.root_category().pk,
  357. },
  358. {'op': 'replace', 'path': 'flatten-categories', 'value': None},
  359. ])
  360. self.assertEqual(response.status_code, 200)
  361. response_json = response.json()
  362. self.assertEqual(response_json['top_category'], self.category.pk)
  363. self.assertEqual(response_json['category'], self.category_b.pk)
  364. class ThreadCloseApiTests(ThreadPatchApiTestCase):
  365. def test_close_thread(self):
  366. """api makes it possible to close thread"""
  367. self.override_acl({
  368. 'can_close_threads': True
  369. })
  370. response = self.patch(self.api_link, [
  371. {'op': 'replace', 'path': 'is-closed', 'value': True}
  372. ])
  373. self.assertEqual(response.status_code, 200)
  374. thread_json = self.get_thread_json()
  375. self.assertTrue(thread_json['is_closed'])
  376. def test_open_thread(self):
  377. """api makes it possible to open thread"""
  378. self.thread.is_closed = True
  379. self.thread.save()
  380. thread_json = self.get_thread_json()
  381. self.assertTrue(thread_json['is_closed'])
  382. self.override_acl({
  383. 'can_close_threads': True
  384. })
  385. response = self.patch(self.api_link, [
  386. {'op': 'replace', 'path': 'is-closed', 'value': False}
  387. ])
  388. self.assertEqual(response.status_code, 200)
  389. thread_json = self.get_thread_json()
  390. self.assertFalse(thread_json['is_closed'])
  391. def test_close_thread_no_permission(self):
  392. """api close thread with no permission fails"""
  393. self.override_acl({
  394. 'can_close_threads': False
  395. })
  396. response = self.patch(self.api_link, [
  397. {'op': 'replace', 'path': 'is-closed', 'value': True}
  398. ])
  399. self.assertEqual(response.status_code, 400)
  400. response_json = response.json()
  401. self.assertEqual(response_json['detail'][0],
  402. "You don't have permission to close this thread.")
  403. thread_json = self.get_thread_json()
  404. self.assertFalse(thread_json['is_closed'])
  405. def test_open_thread_no_permission(self):
  406. """api open thread with no permission fails"""
  407. self.thread.is_closed = True
  408. self.thread.save()
  409. thread_json = self.get_thread_json()
  410. self.assertTrue(thread_json['is_closed'])
  411. self.override_acl({
  412. 'can_close_threads': False
  413. })
  414. response = self.patch(self.api_link, [
  415. {'op': 'replace', 'path': 'is-closed', 'value': False}
  416. ])
  417. self.assertEqual(response.status_code, 400)
  418. response_json = response.json()
  419. self.assertEqual(response_json['detail'][0],
  420. "You don't have permission to open this thread.")
  421. thread_json = self.get_thread_json()
  422. self.assertTrue(thread_json['is_closed'])
  423. class ThreadApproveApiTests(ThreadPatchApiTestCase):
  424. def test_approve_thread(self):
  425. """api makes it possible to approve thread"""
  426. self.thread.is_unapproved = True
  427. self.thread.save()
  428. self.override_acl({
  429. 'can_approve_content': 1
  430. })
  431. response = self.patch(self.api_link, [
  432. {'op': 'replace', 'path': 'is-unapproved', 'value': False}
  433. ])
  434. self.assertEqual(response.status_code, 200)
  435. thread_json = self.get_thread_json()
  436. self.assertFalse(thread_json['is_unapproved'])
  437. def test_unapprove_thread(self):
  438. """api returns permission error on approval removal"""
  439. self.override_acl({
  440. 'can_approve_content': 1
  441. })
  442. response = self.patch(self.api_link, [
  443. {'op': 'replace', 'path': 'is-unapproved', 'value': True}
  444. ])
  445. self.assertEqual(response.status_code, 400)
  446. response_json = response.json()
  447. self.assertEqual(response_json['detail'][0],
  448. "Content approval can't be reversed.")
  449. class ThreadHideApiTests(ThreadPatchApiTestCase):
  450. def test_hide_thread(self):
  451. """api makes it possible to hide thread"""
  452. self.override_acl({
  453. 'can_hide_threads': 1
  454. })
  455. response = self.patch(self.api_link, [
  456. {'op': 'replace', 'path': 'is-hidden', 'value': True}
  457. ])
  458. self.assertEqual(response.status_code, 200)
  459. self.override_acl({
  460. 'can_hide_threads': 1
  461. })
  462. thread_json = self.get_thread_json()
  463. self.assertTrue(thread_json['is_hidden'])
  464. def test_show_thread(self):
  465. """api makes it possible to unhide thread"""
  466. self.thread.is_hidden = True
  467. self.thread.save()
  468. self.override_acl({
  469. 'can_hide_threads': 1
  470. })
  471. thread_json = self.get_thread_json()
  472. self.assertTrue(thread_json['is_hidden'])
  473. self.override_acl({
  474. 'can_hide_threads': 1
  475. })
  476. response = self.patch(self.api_link, [
  477. {'op': 'replace', 'path': 'is-hidden', 'value': False}
  478. ])
  479. self.assertEqual(response.status_code, 200)
  480. self.override_acl({
  481. 'can_hide_threads': 1
  482. })
  483. thread_json = self.get_thread_json()
  484. self.assertFalse(thread_json['is_hidden'])
  485. def test_hide_thread_no_permission(self):
  486. """api hide thread with no permission fails"""
  487. self.override_acl({
  488. 'can_hide_threads': 0
  489. })
  490. response = self.patch(self.api_link, [
  491. {'op': 'replace', 'path': 'is-hidden', 'value': True}
  492. ])
  493. self.assertEqual(response.status_code, 400)
  494. response_json = response.json()
  495. self.assertEqual(response_json['detail'][0],
  496. "You don't have permission to hide this thread.")
  497. thread_json = self.get_thread_json()
  498. self.assertFalse(thread_json['is_hidden'])
  499. def test_show_thread_no_permission(self):
  500. """api unhide thread with no permission fails"""
  501. self.thread.is_hidden = True
  502. self.thread.save()
  503. self.override_acl({
  504. 'can_hide_threads': 1
  505. })
  506. thread_json = self.get_thread_json()
  507. self.assertTrue(thread_json['is_hidden'])
  508. self.override_acl({
  509. 'can_hide_threads': 0
  510. })
  511. response = self.patch(self.api_link, [
  512. {'op': 'replace', 'path': 'is-hidden', 'value': False}
  513. ])
  514. self.assertEqual(response.status_code, 404)
  515. class ThreadSubscribeApiTests(ThreadPatchApiTestCase):
  516. def test_subscribe_thread(self):
  517. """api makes it possible to subscribe thread"""
  518. response = self.patch(self.api_link, [
  519. {'op': 'replace', 'path': 'subscription', 'value': 'notify'}
  520. ])
  521. self.assertEqual(response.status_code, 200)
  522. thread_json = self.get_thread_json()
  523. self.assertFalse(thread_json['subscription'])
  524. subscription = self.user.subscription_set.get(thread=self.thread)
  525. self.assertFalse(subscription.send_email)
  526. def test_subscribe_thread_with_email(self):
  527. """api makes it possible to subscribe thread with emails"""
  528. response = self.patch(self.api_link, [
  529. {'op': 'replace', 'path': 'subscription', 'value': 'email'}
  530. ])
  531. self.assertEqual(response.status_code, 200)
  532. thread_json = self.get_thread_json()
  533. self.assertTrue(thread_json['subscription'])
  534. subscription = self.user.subscription_set.get(thread=self.thread)
  535. self.assertTrue(subscription.send_email)
  536. def test_unsubscribe_thread(self):
  537. """api makes it possible to unsubscribe thread"""
  538. response = self.patch(self.api_link, [
  539. {'op': 'replace', 'path': 'subscription', 'value': 'remove'}
  540. ])
  541. self.assertEqual(response.status_code, 200)
  542. thread_json = self.get_thread_json()
  543. self.assertIsNone(thread_json['subscription'])
  544. self.assertEqual(self.user.subscription_set.count(), 0)
  545. def test_subscribe_as_guest(self):
  546. """api makes it impossible to subscribe thread"""
  547. self.logout_user()
  548. response = self.patch(self.api_link, [
  549. {'op': 'replace', 'path': 'subscription', 'value': 'email'}
  550. ])
  551. self.assertEqual(response.status_code, 403)
  552. def test_subscribe_nonexistant_thread(self):
  553. """api makes it impossible to subscribe nonexistant thread"""
  554. bad_api_link = self.api_link.replace(
  555. six.text_type(self.thread.pk), six.text_type(self.thread.pk + 9))
  556. response = self.patch(bad_api_link, [
  557. {'op': 'replace', 'path': 'subscription', 'value': 'email'}
  558. ])
  559. self.assertEqual(response.status_code, 404)