|
19 | 19 | from contentcuration.tasks import apply_channel_changes_task |
20 | 20 | from contentcuration.tests import testdata |
21 | 21 | from contentcuration.tests.base import StudioAPITestCase |
| 22 | +from contentcuration.tests.helpers import reverse_with_query |
22 | 23 | from contentcuration.tests.viewsets.base import generate_create_event |
23 | 24 | from contentcuration.tests.viewsets.base import generate_delete_event |
24 | 25 | from contentcuration.tests.viewsets.base import generate_deploy_channel_event |
@@ -673,6 +674,168 @@ def test_fetch_admin_channels_invalid_filter(self): |
673 | 674 | ) |
674 | 675 | self.assertEqual(response.status_code, 200, response.content) |
675 | 676 |
|
| 677 | + def test_admin_channel_detail__latest_community_library_submission__exists(self): |
| 678 | + older_submission = testdata.community_library_submission() |
| 679 | + older_submission.channel.version = 2 |
| 680 | + older_submission.channel_version = 1 |
| 681 | + older_submission.status = community_library_submission.STATUS_LIVE |
| 682 | + older_submission.channel.save() |
| 683 | + older_submission.save() |
| 684 | + |
| 685 | + latest_submission = CommunityLibrarySubmission.objects.create( |
| 686 | + channel=older_submission.channel, |
| 687 | + channel_version=2, |
| 688 | + author=older_submission.author, |
| 689 | + ) |
| 690 | + |
| 691 | + self.client.force_authenticate(self.admin_user) |
| 692 | + response = self.client.get( |
| 693 | + reverse( |
| 694 | + "admin-channels-detail", kwargs={"pk": older_submission.channel.id} |
| 695 | + ), |
| 696 | + format="json", |
| 697 | + ) |
| 698 | + self.assertEqual(response.status_code, 200, response.content) |
| 699 | + self.assertEqual( |
| 700 | + response.data["latest_community_library_submission_id"], |
| 701 | + latest_submission.id, |
| 702 | + ) |
| 703 | + self.assertEqual( |
| 704 | + response.data["latest_community_library_submission_status"], |
| 705 | + community_library_submission.STATUS_PENDING, |
| 706 | + ) |
| 707 | + self.assertTrue(response.data["has_any_live_community_library_submission"]) |
| 708 | + |
| 709 | + def test_admin_channel_detail__latest_community_library_submission__none_exist( |
| 710 | + self, |
| 711 | + ): |
| 712 | + channel = testdata.channel() |
| 713 | + |
| 714 | + self.client.force_authenticate(self.admin_user) |
| 715 | + response = self.client.get( |
| 716 | + reverse("admin-channels-detail", kwargs={"pk": channel.id}), |
| 717 | + format="json", |
| 718 | + ) |
| 719 | + self.assertEqual(response.status_code, 200, response.content) |
| 720 | + self.assertIsNone(response.data["latest_community_library_submission_id"]) |
| 721 | + self.assertIsNone(response.data["latest_community_library_submission_status"]) |
| 722 | + self.assertFalse(response.data["has_any_live_community_library_submission"]) |
| 723 | + |
| 724 | + def test_admin_channel_filter__latest_community_library_submission_status__any( |
| 725 | + self, |
| 726 | + ): |
| 727 | + self.client.force_authenticate(user=self.admin_user) |
| 728 | + |
| 729 | + submission = testdata.community_library_submission() |
| 730 | + |
| 731 | + response = self.client.get( |
| 732 | + reverse_with_query( |
| 733 | + "admin-channels-list", |
| 734 | + query={ |
| 735 | + "id__in": submission.channel.id, |
| 736 | + }, |
| 737 | + ), |
| 738 | + format="json", |
| 739 | + ) |
| 740 | + self.assertEqual(response.status_code, 200, response.content) |
| 741 | + self.assertEqual(len(response.data), 1) |
| 742 | + |
| 743 | + def test_admin_channel_filter__latest_community_library_submission_status__multiple( |
| 744 | + self, |
| 745 | + ): |
| 746 | + self.client.force_authenticate(user=self.admin_user) |
| 747 | + |
| 748 | + submission1 = testdata.community_library_submission() |
| 749 | + submission1.status = community_library_submission.STATUS_LIVE |
| 750 | + submission1.save() |
| 751 | + |
| 752 | + submission2 = testdata.community_library_submission() |
| 753 | + submission2.status = community_library_submission.STATUS_PENDING |
| 754 | + submission2.save() |
| 755 | + |
| 756 | + submission3 = testdata.community_library_submission() |
| 757 | + submission3.status = community_library_submission.STATUS_APPROVED |
| 758 | + submission3.save() |
| 759 | + |
| 760 | + response = self.client.get( |
| 761 | + reverse_with_query( |
| 762 | + "admin-channels-list", |
| 763 | + query=[ |
| 764 | + ( |
| 765 | + "latest_community_library_submission_status", |
| 766 | + community_library_submission.STATUS_LIVE, |
| 767 | + ), |
| 768 | + ( |
| 769 | + "latest_community_library_submission_status", |
| 770 | + community_library_submission.STATUS_PENDING, |
| 771 | + ), |
| 772 | + ], |
| 773 | + ), |
| 774 | + format="json", |
| 775 | + ) |
| 776 | + self.assertEqual(response.status_code, 200, response.content) |
| 777 | + self.assertCountEqual( |
| 778 | + [ch["id"] for ch in response.data], |
| 779 | + [ |
| 780 | + submission1.channel.id, |
| 781 | + submission2.channel.id, |
| 782 | + ], |
| 783 | + ) |
| 784 | + |
| 785 | + def test_admin_channel_filter__community_library_live(self): |
| 786 | + self.client.force_authenticate(user=self.admin_user) |
| 787 | + |
| 788 | + submission1 = testdata.community_library_submission() |
| 789 | + submission1.channel.version = 2 |
| 790 | + submission1.channel.save() |
| 791 | + submission1.status = community_library_submission.STATUS_LIVE |
| 792 | + submission1.channel_version = 1 |
| 793 | + submission1.save() |
| 794 | + |
| 795 | + CommunityLibrarySubmission.objects.create( |
| 796 | + channel=submission1.channel, |
| 797 | + channel_version=2, |
| 798 | + author=submission1.author, |
| 799 | + status=community_library_submission.STATUS_PENDING, |
| 800 | + ) |
| 801 | + |
| 802 | + other_channel_submission = testdata.community_library_submission() |
| 803 | + other_channel_submission.status = community_library_submission.STATUS_PENDING |
| 804 | + other_channel_submission.save() |
| 805 | + |
| 806 | + response = self.client.get( |
| 807 | + reverse_with_query( |
| 808 | + "admin-channels-list", |
| 809 | + query={"community_library_live": True}, |
| 810 | + ), |
| 811 | + format="json", |
| 812 | + ) |
| 813 | + self.assertEqual(response.status_code, 200, response.content) |
| 814 | + self.assertCountEqual( |
| 815 | + [ch["id"] for ch in response.data], |
| 816 | + [submission1.channel.id], |
| 817 | + ) |
| 818 | + |
| 819 | + def test_admin_channel_filter__has_community_library_submission(self): |
| 820 | + self.client.force_authenticate(user=self.admin_user) |
| 821 | + |
| 822 | + submission = testdata.community_library_submission() |
| 823 | + |
| 824 | + testdata.channel() # Another channel without submission |
| 825 | + |
| 826 | + response = self.client.get( |
| 827 | + reverse_with_query( |
| 828 | + "admin-channels-list", |
| 829 | + query={"has_community_library_submission": True}, |
| 830 | + ), |
| 831 | + format="json", |
| 832 | + ) |
| 833 | + self.assertEqual(response.status_code, 200, response.content) |
| 834 | + self.assertCountEqual( |
| 835 | + [ch["id"] for ch in response.data], |
| 836 | + [submission.channel.id], |
| 837 | + ) |
| 838 | + |
676 | 839 | def test_create_channel(self): |
677 | 840 | user = testdata.user() |
678 | 841 | self.client.force_authenticate(user=user) |
|
0 commit comments