|
18 | 18 | from contentcuration.models import Channel |
19 | 19 | from contentcuration.models import ChannelHistory |
20 | 20 | from contentcuration.models import ChannelSet |
| 21 | +from contentcuration.models import CommunityLibrarySubmission |
21 | 22 | from contentcuration.models import ContentNode |
22 | 23 | from contentcuration.models import CONTENTNODE_TREE_ID_CACHE_KEY |
23 | 24 | from contentcuration.models import File |
@@ -547,6 +548,130 @@ def test_make_content_id_unique(self): |
547 | 548 | self.assertNotEqual(copied_node_old_content_id, copied_node.content_id) |
548 | 549 |
|
549 | 550 |
|
| 551 | +class CommunityLibrarySubmissionTestCase(PermissionQuerysetTestCase): |
| 552 | + @property |
| 553 | + def base_queryset(self): |
| 554 | + return CommunityLibrarySubmission.objects.all() |
| 555 | + |
| 556 | + def test_create_submission(self): |
| 557 | + # Smoke test |
| 558 | + channel = testdata.channel() |
| 559 | + author = testdata.user() |
| 560 | + channel.editors.add(author) |
| 561 | + channel.save() |
| 562 | + |
| 563 | + country = testdata.country() |
| 564 | + |
| 565 | + submission = CommunityLibrarySubmission.objects.create( |
| 566 | + description="Test submission", |
| 567 | + channel=channel, |
| 568 | + channel_version=1, |
| 569 | + author=author, |
| 570 | + categories=["test_category"], |
| 571 | + status=CommunityLibrarySubmission.Status.PENDING, |
| 572 | + ) |
| 573 | + submission.countries.add(country) |
| 574 | + |
| 575 | + submission.full_clean() |
| 576 | + submission.save() |
| 577 | + |
| 578 | + def test_filter_view_queryset__anonymous(self): |
| 579 | + _ = testdata.community_library_submission() |
| 580 | + |
| 581 | + queryset = CommunityLibrarySubmission.filter_view_queryset( |
| 582 | + self.base_queryset, user=self.anonymous_user |
| 583 | + ) |
| 584 | + self.assertFalse(queryset.exists()) |
| 585 | + |
| 586 | + def test_filter_view_queryset__forbidden_user(self): |
| 587 | + _ = testdata.community_library_submission() |
| 588 | + |
| 589 | + queryset = CommunityLibrarySubmission.filter_view_queryset( |
| 590 | + self.base_queryset, user=self.forbidden_user |
| 591 | + ) |
| 592 | + self.assertFalse(queryset.exists()) |
| 593 | + |
| 594 | + def test_filter_view_queryset__channel_editor(self): |
| 595 | + submission_a = testdata.community_library_submission() |
| 596 | + submission_b = testdata.community_library_submission() |
| 597 | + |
| 598 | + user = testdata.user() |
| 599 | + submission_a.channel.editors.add(user) |
| 600 | + submission_a.save() |
| 601 | + |
| 602 | + queryset = CommunityLibrarySubmission.filter_view_queryset( |
| 603 | + self.base_queryset, user=user |
| 604 | + ) |
| 605 | + self.assertQuerysetContains(queryset, pk=submission_a.id) |
| 606 | + self.assertQuerysetDoesNotContain(queryset, pk=submission_b.id) |
| 607 | + |
| 608 | + def test_filter_view_queryset__admin(self): |
| 609 | + submission_a = testdata.community_library_submission() |
| 610 | + |
| 611 | + queryset = CommunityLibrarySubmission.filter_view_queryset( |
| 612 | + self.base_queryset, user=self.admin_user |
| 613 | + ) |
| 614 | + self.assertQuerysetContains(queryset, pk=submission_a.id) |
| 615 | + |
| 616 | + def test_filter_edit_queryset__anonymous(self): |
| 617 | + _ = testdata.community_library_submission() |
| 618 | + |
| 619 | + queryset = CommunityLibrarySubmission.filter_edit_queryset( |
| 620 | + self.base_queryset, user=self.anonymous_user |
| 621 | + ) |
| 622 | + self.assertFalse(queryset.exists()) |
| 623 | + |
| 624 | + def test_filter_edit_queryset__forbidden_user(self): |
| 625 | + _ = testdata.community_library_submission() |
| 626 | + |
| 627 | + queryset = CommunityLibrarySubmission.filter_edit_queryset( |
| 628 | + self.base_queryset, user=self.forbidden_user |
| 629 | + ) |
| 630 | + self.assertFalse(queryset.exists()) |
| 631 | + |
| 632 | + def test_filter_edit_queryset__channel_editor(self): |
| 633 | + submission = testdata.community_library_submission() |
| 634 | + |
| 635 | + user = testdata.user() |
| 636 | + submission.channel.editors.add(user) |
| 637 | + submission.save() |
| 638 | + |
| 639 | + queryset = CommunityLibrarySubmission.filter_edit_queryset( |
| 640 | + self.base_queryset, user=user |
| 641 | + ) |
| 642 | + self.assertFalse(queryset.exists()) |
| 643 | + |
| 644 | + def test_filter_edit_queryset__author__channel_editor(self): |
| 645 | + submission_a = testdata.community_library_submission() |
| 646 | + submission_b = testdata.community_library_submission() |
| 647 | + |
| 648 | + queryset = CommunityLibrarySubmission.filter_edit_queryset( |
| 649 | + self.base_queryset, user=submission_a.author |
| 650 | + ) |
| 651 | + self.assertQuerysetContains(queryset, pk=submission_a.id) |
| 652 | + self.assertQuerysetDoesNotContain(queryset, pk=submission_b.id) |
| 653 | + |
| 654 | + def test_filter_edit_queryset__author__not_channel_editor(self): |
| 655 | + submission = testdata.community_library_submission() |
| 656 | + |
| 657 | + user = testdata.user(email="new@user.com") |
| 658 | + submission.author = user |
| 659 | + submission.save() |
| 660 | + |
| 661 | + queryset = CommunityLibrarySubmission.filter_edit_queryset( |
| 662 | + self.base_queryset, user=user |
| 663 | + ) |
| 664 | + self.assertFalse(queryset.exists()) |
| 665 | + |
| 666 | + def test_filter_edit_queryset__admin(self): |
| 667 | + submission_a = testdata.community_library_submission() |
| 668 | + |
| 669 | + queryset = CommunityLibrarySubmission.filter_edit_queryset( |
| 670 | + self.base_queryset, user=self.admin_user |
| 671 | + ) |
| 672 | + self.assertQuerysetContains(queryset, pk=submission_a.id) |
| 673 | + |
| 674 | + |
550 | 675 | class AssessmentItemTestCase(PermissionQuerysetTestCase): |
551 | 676 | @property |
552 | 677 | def base_queryset(self): |
|
0 commit comments