예제 #1
0
 def test_200_post(self):
     main_tree = TreeBuilder(user=self.user)
     staging_tree = TreeBuilder(user=self.user)
     self.channel.main_tree = main_tree.root
     self.channel.staging_tree = staging_tree.root
     self.channel.save()
     response = self.post(reverse_lazy("activate_channel"),
                          {"channel_id": self.channel.id})
     self.assertEqual(response.status_code, 200)
예제 #2
0
 def test_200_no_change_in_space(self):
     main_tree = TreeBuilder(user=self.user)
     staging_tree = TreeBuilder(user=self.user)
     self.channel.main_tree = main_tree.root
     self.channel.staging_tree = staging_tree.root
     self.channel.save()
     self.user.disk_space = self.user.get_space_used(
         active_files=self.user.get_user_active_files())
     self.user.save()
     response = self.post(reverse_lazy("activate_channel"),
                          {"channel_id": self.channel.id})
     self.assertEqual(response.status_code, 200)
예제 #3
0
    def generate_random_channels(self, num_channels=1):
        for i in range(num_channels):
            new_channel = create_channel(
                "The Potatoes Info Saga Part {}".format(i),
                editors=[self.editor])

            new_channel.main_tree = TreeBuilder(user=self.editor).root

            print("Created channel with {} nodes".format(
                new_channel.main_tree.get_descendants().count()))

            # make sure we have a trash tree so that can be tested with real data as well.
            new_channel.trash_tree = TreeBuilder(user=self.editor).root
            print("Created channel with id {}".format(new_channel.pk))
예제 #4
0
    def test_duplicate_nodes_with_assessment_item_file(self):
        """
        Ensures that when we copy nodes with tags they get copied
        """
        new_channel = testdata.channel()

        tree = TreeBuilder(tags=True)
        self.channel.main_tree = tree.root
        self.channel.save()

        exercise = (self.channel.main_tree.get_descendants().filter(
            kind_id=content_kinds.EXERCISE).first())

        ai = exercise.assessment_items.first()

        file = testdata.fileobj_exercise_image()

        file.assessment_item = ai
        file.save()

        self.channel.main_tree.copy_to(new_channel.main_tree, batch_size=1000)

        _check_node_copy(
            self.channel.main_tree,
            new_channel.main_tree.get_children().last(),
            original_channel_id=self.channel.id,
            channel=new_channel,
        )
예제 #5
0
    def test_duplicate_nodes_with_tags(self):
        """
        Ensures that when we copy nodes with tags they get copied
        """
        new_channel = testdata.channel()

        tree = TreeBuilder(tags=True)
        self.channel.main_tree = tree.root
        self.channel.save()

        # Add a legacy tag with a set channel to test the tag copying behaviour.
        legacy_tag = ContentTag.objects.create(tag_name="test",
                                               channel=self.channel)
        # Add an identical tag without a set channel to make sure it gets reused.
        ContentTag.objects.create(tag_name="test")

        num_test_tags_before = ContentTag.objects.filter(
            tag_name="test").count()

        self.channel.main_tree.get_children().first().tags.add(legacy_tag)

        self.channel.main_tree.copy_to(new_channel.main_tree, batch_size=1000)

        _check_node_copy(
            self.channel.main_tree,
            new_channel.main_tree.get_children().last(),
            original_channel_id=self.channel.id,
            channel=new_channel,
        )

        self.assertEqual(num_test_tags_before,
                         ContentTag.objects.filter(tag_name="test").count())
예제 #6
0
    def setUp(self):
        super(NodeOperationsTestCase, self).setUp()

        self.channel = testdata.channel()
        tree = TreeBuilder()
        self.channel.main_tree = tree.root
        self.channel.save()
예제 #7
0
 def test_404_no_permission(self):
     new_channel = Channel.objects.create()
     staging_tree = TreeBuilder(user=self.user, levels=1)
     new_channel.staging_tree = staging_tree.root
     new_channel.save()
     response = self.post(reverse_lazy("activate_channel"),
                          {"channel_id": new_channel.id})
     self.assertEqual(response.status_code, 404)
예제 #8
0
    def handle(self, *args, **options):

        self.editor = create_user("*****@*****.**", "ivanisthe1", "Ivan",
                                  "NeoBot")

        self.editor.clipboard_tree.get_descendants().delete()

        with ContentNode.objects.delay_mptt_updates():
            print("Creating channel...")
            self.generate_random_channels()

            # Make sure we have a channel with a lot of root topics to test initial channel load.
            one_hundred = create_channel("The one with a lot of root topics")
            one_hundred.main_tree = TreeBuilder(levels=1,
                                                num_children=100,
                                                user=self.editor,
                                                resources=False).root

            # Generate a clipboard tree, intentionally large.
            self.editor.clipboard_tree = TreeBuilder(levels=2,
                                                     num_children=25,
                                                     user=self.editor).root
            print("Created clipboard with {} nodes".format(
                self.editor.clipboard_tree.get_descendants().count()))