コード例 #1
0
    def test_multiple_copy_channel_ids(self):
        """
        This test ensures that as we copy nodes across various channels, that their original_channel_id and
        source_channel_id values are properly updated.
        """
        title = "Dolly"
        num_nodes = 10
        topic, _created = ContentKind.objects.get_or_create(kind="Topic")
        new_node = ContentNode.objects.create(title="Heyo!", parent=self.channel.main_tree, kind=topic)
        self.channel.save()
        # assert self.channel.main_tree.get_root() == self.channel.main_tree
        # assert self.channel.main_tree.get_channel() == self.channel
        _create_nodes(num_nodes, title, parent=new_node)

        assert self.channel.main_tree.changed is True
        assert self.channel.main_tree.get_channel() == self.channel

        assert self.channel.main_tree.parent is None
        _check_nodes(new_node, title, original_channel_id=self.channel.id, source_channel_id=self.channel.id, channel=self.channel)

        channels = [
            self.channel,
            testdata.channel(),
            testdata.channel(),
            testdata.channel(),
            testdata.channel()
        ]

        copy_node_root = new_node
        for i in range(1, len(channels)):
            print("Copying channel {} nodes to channel {}".format(i - 1, i))
            channel = channels[i]
            prev_channel = channels[i - 1]

            prev_channel.main_tree._mark_unchanged()
            prev_channel.main_tree.changed = False
            assert prev_channel.main_tree.get_changed_fields() == {}
            prev_channel.main_tree.save()
            prev_channel.main_tree.refresh_from_db()
            assert prev_channel.main_tree.changed is False

            # simulate a clean, right-after-publish state to ensure only new channel is marked as change
            channel.main_tree.changed = False
            channel.main_tree.save()
            channel.main_tree.refresh_from_db()
            assert channel.main_tree.changed is False

            # make sure we always copy the copy we made in the previous go around :)
            copy_node_root = nodes.duplicate_node_bulk(copy_node_root, parent=channel.main_tree)

            _check_nodes(copy_node_root, original_channel_id=self.channel.id, source_channel_id=prev_channel.id, channel=channel)
            channel.main_tree.refresh_from_db()
            assert channel.main_tree.changed is True
            assert channel.main_tree.get_descendants().filter(changed=True).exists()

            prev_channel.main_tree.refresh_from_db()
            assert prev_channel.main_tree.changed is False
コード例 #2
0
    def test_duplicate_nodes(self):
        """
        Ensures that when we copy nodes, the new channel gets marked as changed but the old channel doesn't,
        and that the nodes point to the new channel.
        """
        num_nodes = 10
        title = "Dolly"
        topic, _created = ContentKind.objects.get_or_create(kind="Topic")
        self.channel.main_tree = ContentNode.objects.create(title="Heyo!",
                                                            kind=topic)
        self.channel.save()
        # assert self.channel.main_tree.get_root() == self.channel.main_tree
        # assert self.channel.main_tree.get_channel() == self.channel
        _create_nodes(num_nodes, title, parent=self.channel.main_tree)

        assert self.channel.main_tree.changed is True
        assert self.channel.main_tree.get_channel() == self.channel

        assert self.channel.main_tree.parent is None
        _check_nodes(self.channel.main_tree,
                     title,
                     original_channel_id=self.channel.id,
                     source_channel_id=self.channel.id,
                     channel=self.channel)

        new_channel = testdata.channel()

        # simulate a clean, right-after-publish state to ensure only new channel is marked as change
        self.channel.main_tree.changed = False
        self.channel.main_tree.save()
        self.channel.main_tree.refresh_from_db()
        assert self.channel.main_tree.changed is False

        new_channel.main_tree.changed = False
        new_channel.main_tree.save()
        new_channel.main_tree.refresh_from_db()
        assert new_channel.main_tree.changed is False

        new_tree = nodes.duplicate_node_bulk(self.channel.main_tree,
                                             parent=new_channel.main_tree)

        _check_nodes(new_tree,
                     title,
                     original_channel_id=self.channel.id,
                     source_channel_id=self.channel.id,
                     channel=new_channel)
        new_channel.main_tree.refresh_from_db()
        assert new_channel.main_tree.changed is True

        self.channel.main_tree.refresh_from_db()
        assert self.channel.main_tree.changed is False
コード例 #3
0
    def _setup_original_and_deriative_nodes(self):
        # Setup original channel
        self.channel = testdata.channel()  # done in base class but doesn't hurt to do again...
        self.channel.main_tree = self._create_minimal_tree(withsubs=False)
        self.channel.save()

        # Setup derivative channel
        self.new_channel = Channel.objects.create(name='derivative of teschannel', source_id='lkajs')
        self.new_channel.save()
        self.new_channel.main_tree = self._create_empty_tree()
        self.new_channel.main_tree.save()
        new_tree = nodes.duplicate_node_bulk(self.channel.main_tree, parent=self.new_channel.main_tree)
        self.new_channel.main_tree = new_tree
        # self.new_channel.main_tree.save()   #  InvalidMove: A node may not be made a child of any of its descendants.
        self.new_channel.main_tree.refresh_from_db()

        # Return video nodes we need for this test
        orig_video = self.channel.main_tree.children.all()[0]
        cloned_video = self.new_channel.main_tree.children.all()[0]
        return orig_video, cloned_video
コード例 #4
0
    def test_duplicate_nodes(self):
        """
        Ensures that when we copy nodes, the new channel gets marked as changed but the old channel doesn't,
        and that the nodes point to the new channel.
        """
        num_nodes = 10
        title = "Dolly"
        topic, _created = ContentKind.objects.get_or_create(kind="Topic")
        self.channel.main_tree = ContentNode.objects.create(title="Heyo!", kind=topic)
        self.channel.save()
        # assert self.channel.main_tree.get_root() == self.channel.main_tree
        # assert self.channel.main_tree.get_channel() == self.channel
        _create_nodes(num_nodes, title, parent=self.channel.main_tree)

        assert self.channel.main_tree.changed is True
        assert self.channel.main_tree.get_channel() == self.channel

        assert self.channel.main_tree.parent is None
        _check_nodes(self.channel.main_tree, title, original_channel_id=self.channel.id, source_channel_id=self.channel.id, channel=self.channel)

        new_channel = testdata.channel()

        # simulate a clean, right-after-publish state to ensure only new channel is marked as change
        self.channel.main_tree.changed = False
        self.channel.main_tree.save()
        self.channel.main_tree.refresh_from_db()
        assert self.channel.main_tree.changed is False

        new_channel.main_tree.changed = False
        new_channel.main_tree.save()
        new_channel.main_tree.refresh_from_db()
        assert new_channel.main_tree.changed is False

        new_tree = nodes.duplicate_node_bulk(self.channel.main_tree, parent=new_channel.main_tree)

        _check_nodes(new_tree, title, original_channel_id=self.channel.id, source_channel_id=self.channel.id, channel=new_channel)
        new_channel.main_tree.refresh_from_db()
        assert new_channel.main_tree.changed is True

        self.channel.main_tree.refresh_from_db()
        assert self.channel.main_tree.changed is False
コード例 #5
0
    def _setup_original_and_deriative_nodes(self):
        # Setup original channel
        self.channel = testdata.channel(
        )  # done in base class but doesn't hurt to do again...
        self.channel.main_tree = self._create_minimal_tree(withsubs=False)
        self.channel.save()

        # Setup derivative channel
        self.new_channel = Channel.objects.create(
            name='derivative of teschannel', source_id='lkajs')
        self.new_channel.save()
        self.new_channel.main_tree = self._create_empty_tree()
        self.new_channel.main_tree.save()
        new_tree = nodes.duplicate_node_bulk(self.channel.main_tree,
                                             parent=self.new_channel.main_tree)
        self.new_channel.main_tree = new_tree
        # self.new_channel.main_tree.save()   #  InvalidMove: A node may not be made a child of any of its descendants.
        self.new_channel.main_tree.refresh_from_db()

        # Return video nodes we need for this test
        orig_video = self.channel.main_tree.children.all()[0]
        cloned_video = self.new_channel.main_tree.children.all()[0]
        return orig_video, cloned_video
コード例 #6
0
    def handle(self, *args, **options):
        # Validate email
        email = options["email"]
        password = options["password"]
        if not re.match(r"[^@]+@[^@]+\.[^@]+", email):
            print("{} is not a valid email".format(email))
            sys.exit()

        # create the minio bucket
        ensure_storage_bucket_public()

        # create the cache table
        call_command("createcachetable")

        # Run migrations
        call_command('migrate')

        # Run loadconstants
        call_command('loadconstants')

        # Set up user as admin
        admin = create_user(email, password, "Admin", "User", admin=True)

        # Create other users
        user1 = create_user("*****@*****.**", "a", "User", "A")
        user2 = create_user("*****@*****.**", "b", "User", "B")
        user3 = create_user("*****@*****.**", "c", "User", "C")

        # Create channels

        channel1 = create_channel("Published Channel", DESCRIPTION, editors=[admin], bookmarkers=[user1, user2], public=True)
        channel2 = create_channel("Ricecooker Channel", DESCRIPTION, editors=[admin, user1], bookmarkers=[user2], viewers=[user3])
        channel3 = create_channel("Empty Channel", editors=[user3], viewers=[user2])
        channel4 = create_channel("Imported Channel", editors=[admin])

        # Invite admin to channel 3
        invitation, _new = Invitation.objects.get_or_create(
            invited=admin,
            sender=user3,
            channel=channel3,
            email=admin.email,
        )
        invitation.share_mode = "edit"
        invitation.save()

        # Create pool of tags
        tags = []
        for t in TAGS:
            tag, _new = ContentTag.objects.get_or_create(tag_name=t, channel=channel1)

        # Generate file objects
        document_file = create_file("Sample Document", format_presets.DOCUMENT, file_formats.PDF, user=admin)
        video_file = create_file("Sample Video", format_presets.VIDEO_HIGH_RES, file_formats.MP4, user=admin)
        subtitle_file = create_file("Sample Subtitle", format_presets.VIDEO_SUBTITLE, file_formats.VTT, user=admin)
        audio_file = create_file("Sample Audio", format_presets.AUDIO, file_formats.MP3, user=admin)
        html5_file = create_file("Sample HTML", format_presets.HTML5_ZIP, file_formats.HTML5, user=admin)

        # Populate channel 1 with content and publish
        generate_tree(channel1.main_tree, document_file, video_file, subtitle_file, audio_file, html5_file, user=admin, tags=tags)
        call_command('exportchannel', channel1.pk)

        # Populate channel 2 with staged content
        channel2.ricecooker_version = "0.0.0"
        channel2.save()
        generate_tree(channel2.staging_tree, document_file, video_file, subtitle_file, audio_file, html5_file, user=admin, tags=tags)

        # Import content from channel 1 into channel 4
        duplicate_node_bulk(channel1.main_tree.children.first(), parent=channel4.main_tree)

        print("\n\n\nSETUP DONE: Log in as admin to view data (email: {}, password: {})\n\n\n".format(email, password))
コード例 #7
0
    def handle(self, *args, **options):
        # Validate email
        email = options["email"]
        password = options["password"]
        if not re.match(r"[^@]+@[^@]+\.[^@]+", email):
            print "{} is not a valid email".format(email)
            sys.exit()

        # Run migrations
        call_command('migrate')

        # Run loadconstants
        call_command('loadconstants')


        # Set up user as admin
        admin = create_user(email, password, "Admin", "User", admin=True)

        # Create other users
        user1 = create_user("*****@*****.**", "a", "User", "A")
        user2 = create_user("*****@*****.**", "b", "User", "B")
        user3 = create_user("*****@*****.**", "c", "User", "C")

        # Create channels

        channel1 = create_channel("Published Channel", DESCRIPTION, editors=[admin], bookmarkers=[user1, user2], public=True)
        channel2 = create_channel("Ricecooker Channel", DESCRIPTION, editors=[admin, user1], bookmarkers=[user2], viewers=[user3])
        channel3 = create_channel("Empty Channel", editors=[user3], viewers=[user2])
        channel4 = create_channel("Imported Channel", editors=[admin])

        # Invite admin to channel 3
        invitation, _new = Invitation.objects.get_or_create(
            invited = admin,
            sender = user3,
            channel = channel3,
            email = admin.email,
        )
        invitation.share_mode = "edit"
        invitation.save()

        # Create pool of tags
        tags = []
        for t in TAGS:
            tag, _new = ContentTag.objects.get_or_create(tag_name=t, channel=channel1)

        # Generate file objects
        document_file = create_file("Sample Document", format_presets.DOCUMENT, file_formats.PDF, user=admin)
        video_file = create_file("Sample Video", format_presets.VIDEO_HIGH_RES, file_formats.MP4, user=admin)
        subtitle_file = create_file("Sample Subtitle", format_presets.VIDEO_SUBTITLE, file_formats.VTT, user=admin)
        audio_file = create_file("Sample Audio", format_presets.AUDIO, file_formats.MP3, user=admin)
        html5_file = create_file("Sample HTML", format_presets.HTML5_ZIP, file_formats.HTML5, user=admin)

        # Populate channel 1 with content and publish
        generate_tree(channel1.main_tree, document_file, video_file, subtitle_file, audio_file, html5_file, user=admin, tags=tags)
        call_command('exportchannel', channel1.pk)

        # Populate channel 2 with staged content
        channel2.ricecooker_version = "0.0.0"
        channel2.save()
        generate_tree(channel2.staging_tree, document_file, video_file, subtitle_file, audio_file, html5_file, user=admin, tags=tags)

        # Import content from channel 1 into channel 4
        duplicate_node_bulk(channel1.main_tree.children.first(), parent=channel4.main_tree)

        print "\n\n\nSETUP DONE: Log in as admin to view data (email: {}, password: {})\n\n\n".format(email, password)
コード例 #8
0
    def test_multiple_copy_channel_ids(self):
        """
        This test ensures that as we copy nodes across various channels, that their original_channel_id and
        source_channel_id values are properly updated.
        """
        title = "Dolly"
        num_nodes = 10
        topic, _created = ContentKind.objects.get_or_create(kind="Topic")
        new_node = ContentNode.objects.create(title="Heyo!",
                                              parent=self.channel.main_tree,
                                              kind=topic)
        self.channel.save()
        # assert self.channel.main_tree.get_root() == self.channel.main_tree
        # assert self.channel.main_tree.get_channel() == self.channel
        _create_nodes(num_nodes, title, parent=new_node)

        assert self.channel.main_tree.changed is True
        assert self.channel.main_tree.get_channel() == self.channel

        assert self.channel.main_tree.parent is None
        _check_nodes(new_node,
                     title,
                     original_channel_id=self.channel.id,
                     source_channel_id=self.channel.id,
                     channel=self.channel)

        channels = [
            self.channel,
            testdata.channel(),
            testdata.channel(),
            testdata.channel(),
            testdata.channel()
        ]

        copy_node_root = new_node
        for i in range(1, len(channels)):
            print("Copying channel {} nodes to channel {}".format(i - 1, i))
            channel = channels[i]
            prev_channel = channels[i - 1]

            prev_channel.main_tree._mark_unchanged()
            prev_channel.main_tree.changed = False
            assert prev_channel.main_tree.get_changed_fields() == {}
            prev_channel.main_tree.save()
            prev_channel.main_tree.refresh_from_db()
            assert prev_channel.main_tree.changed is False

            # simulate a clean, right-after-publish state to ensure only new channel is marked as change
            channel.main_tree.changed = False
            channel.main_tree.save()
            channel.main_tree.refresh_from_db()
            assert channel.main_tree.changed is False

            # make sure we always copy the copy we made in the previous go around :)
            copy_node_root = nodes.duplicate_node_bulk(
                copy_node_root, parent=channel.main_tree)

            _check_nodes(copy_node_root,
                         original_channel_id=self.channel.id,
                         source_channel_id=prev_channel.id,
                         channel=channel)
            channel.main_tree.refresh_from_db()
            assert channel.main_tree.changed is True
            assert channel.main_tree.get_descendants().filter(
                changed=True).exists()

            prev_channel.main_tree.refresh_from_db()
            assert prev_channel.main_tree.changed is False