|
17 | 17 | from patchwork.models import Check
|
18 | 18 | from patchwork.models import Patch
|
19 | 19 | from patchwork.models import State
|
20 |
| -from patchwork.tests.utils import create_check |
| 20 | +from patchwork.tests.utils import create_attention_set, create_check |
21 | 21 | from patchwork.tests.utils import create_maintainer
|
22 | 22 | from patchwork.tests.utils import create_patch
|
23 | 23 | from patchwork.tests.utils import create_patch_comment
|
@@ -205,6 +205,10 @@ def test_utf8_handling(self):
|
205 | 205 |
|
206 | 206 |
|
207 | 207 | class PatchViewTest(TestCase):
|
| 208 | + def setUp(self): |
| 209 | + self.project = create_project() |
| 210 | + self.maintainer = create_maintainer(self.project) |
| 211 | + |
208 | 212 | def test_redirect(self):
|
209 | 213 | patch = create_patch()
|
210 | 214 |
|
@@ -380,6 +384,122 @@ def test_patch_with_checks(self):
|
380 | 384 | ),
|
381 | 385 | )
|
382 | 386 |
|
| 387 | + def test_patch_with_attention_set(self): |
| 388 | + user = create_user() |
| 389 | + patch = create_patch(project=self.project) |
| 390 | + create_attention_set(patch=patch, user=user) |
| 391 | + create_attention_set(patch=patch, user=self.maintainer) |
| 392 | + |
| 393 | + self.client.login( |
| 394 | + username=self.maintainer.username, |
| 395 | + password=self.maintainer.username, |
| 396 | + ) |
| 397 | + requested_url = reverse( |
| 398 | + 'patch-detail', |
| 399 | + kwargs={ |
| 400 | + 'project_id': patch.project.linkname, |
| 401 | + 'msgid': patch.encoded_msgid, |
| 402 | + }, |
| 403 | + ) |
| 404 | + response = self.client.get(requested_url) |
| 405 | + |
| 406 | + # the response should contain attention set list |
| 407 | + self.assertContains(response, '<h2>Users pending actions</h2>') |
| 408 | + |
| 409 | + # and it should show the existing users in the list |
| 410 | + self.assertEqual( |
| 411 | + response.content.decode().count( |
| 412 | + f'{self.maintainer.username} ({self.maintainer.email})' |
| 413 | + ), |
| 414 | + 1, |
| 415 | + ) |
| 416 | + self.assertEqual( |
| 417 | + response.content.decode().count(f'{user.username} ({user.email})'), |
| 418 | + 1, |
| 419 | + ) |
| 420 | + |
| 421 | + # should display remove button for all |
| 422 | + self.assertEqual( |
| 423 | + response.content.decode().count('glyphicon-trash'), |
| 424 | + 2, |
| 425 | + ) |
| 426 | + |
| 427 | + def test_patch_with_anonymous_user_with_attention_list(self): |
| 428 | + # show not show a declare interest button nor remove buttons |
| 429 | + user = create_user() |
| 430 | + patch = create_patch(project=self.project) |
| 431 | + create_attention_set(patch=patch, user=user) |
| 432 | + create_attention_set(patch=patch, user=self.maintainer) |
| 433 | + |
| 434 | + requested_url = reverse( |
| 435 | + 'patch-detail', |
| 436 | + kwargs={ |
| 437 | + 'project_id': patch.project.linkname, |
| 438 | + 'msgid': patch.encoded_msgid, |
| 439 | + }, |
| 440 | + ) |
| 441 | + response = self.client.get(requested_url) |
| 442 | + |
| 443 | + self.assertEqual( |
| 444 | + response.content.decode().count('Declare interest'), |
| 445 | + 0, |
| 446 | + ) |
| 447 | + self.assertEqual( |
| 448 | + response.content.decode().count('glyphicon-trash'), |
| 449 | + 0, |
| 450 | + ) |
| 451 | + |
| 452 | + def test_patch_with_user_not_in_attention_list(self): |
| 453 | + # a declare interest button should be displayed |
| 454 | + patch = create_patch(project=self.project) |
| 455 | + |
| 456 | + self.client.login( |
| 457 | + username=self.maintainer.username, |
| 458 | + password=self.maintainer.username, |
| 459 | + ) |
| 460 | + requested_url = reverse( |
| 461 | + 'patch-detail', |
| 462 | + kwargs={ |
| 463 | + 'project_id': patch.project.linkname, |
| 464 | + 'msgid': patch.encoded_msgid, |
| 465 | + }, |
| 466 | + ) |
| 467 | + response = self.client.get(requested_url) |
| 468 | + |
| 469 | + self.assertEqual( |
| 470 | + response.content.decode().count('Declare interest'), |
| 471 | + 1, |
| 472 | + ) |
| 473 | + |
| 474 | + def test_patch_with_user_in_attention_list(self): |
| 475 | + # a remove button should be displayed if he is authenticated |
| 476 | + # should not show option for other users |
| 477 | + user = create_user() |
| 478 | + patch = create_patch(project=self.project) |
| 479 | + create_attention_set(patch=patch, user=user) |
| 480 | + create_attention_set(patch=patch, user=self.maintainer) |
| 481 | + |
| 482 | + self.client.login( |
| 483 | + username=user.username, |
| 484 | + password=user.username, |
| 485 | + ) |
| 486 | + requested_url = reverse( |
| 487 | + 'patch-detail', |
| 488 | + kwargs={ |
| 489 | + 'project_id': patch.project.linkname, |
| 490 | + 'msgid': patch.encoded_msgid, |
| 491 | + }, |
| 492 | + ) |
| 493 | + response = self.client.get(requested_url) |
| 494 | + self.assertEqual( |
| 495 | + response.content.decode().count(f'{user.username} ({user.email})'), |
| 496 | + 1, |
| 497 | + ) |
| 498 | + self.assertEqual( |
| 499 | + response.content.decode().count('glyphicon-trash'), |
| 500 | + 1, |
| 501 | + ) |
| 502 | + |
383 | 503 |
|
384 | 504 | class PatchUpdateTest(TestCase):
|
385 | 505 | properties_form_id = 'patch-form-properties'
|
|
0 commit comments