示例#1
0
 def setUpClass(cls):
     super(ContentLibraryContentTestMixin, cls).setUpClass()
     # Create a couple students that the tests can use
     cls.student_a = UserFactory.create(username="******",
                                        email="*****@*****.**",
                                        password="******")
     cls.student_b = UserFactory.create(username="******",
                                        email="*****@*****.**",
                                        password="******")
     # Create a collection using Blockstore API directly only because there
     # is not yet any Studio REST API for doing so:
     cls.collection = blockstore_api.create_collection(
         "Content Library Test Collection")
     # Create an organization
     cls.organization = Organization.objects.create(
         name="Content Libraries Tachyon Exploration & Survey Team",
         short_name="CL-TEST",
     )
     cls.library = library_api.create_library(
         collection_uuid=cls.collection.uuid,
         org=cls.organization,
         slug=cls.__name__,
         title=(cls.__name__ + " Test Lib"),
         description="",
     )
示例#2
0
 def post(self, request):
     """
     Create a new content library.
     """
     if not request.user.has_perm(permissions.CAN_CREATE_CONTENT_LIBRARY):
         raise PermissionDenied
     serializer = ContentLibraryMetadataSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     data = dict(serializer.validated_data)
     # Converting this over because using the reserved names 'type' and 'license' would shadow the built-in
     # definitions elsewhere.
     data['library_type'] = data.pop('type')
     data['library_license'] = data.pop('license')
     # Get the organization short_name out of the "key.org" pseudo-field that the serializer added:
     org_name = data["key"]["org"]
     # Move "slug" out of the "key.slug" pseudo-field that the serializer added:
     data["slug"] = data.pop("key")["slug"]
     try:
         org = Organization.objects.get(short_name=org_name)
     except Organization.DoesNotExist:
         raise ValidationError(
             detail={
                 "org": "No such organization '{}' found.".format(org_name)
             })
     try:
         result = api.create_library(org=org, **data)
     except api.LibraryAlreadyExists:
         raise ValidationError(
             detail={"slug": "A library with that ID already exists."})
     # Grant the current user admin permissions on the library:
     api.set_library_user_permissions(result.key, request.user,
                                      api.AccessLevel.ADMIN_LEVEL)
     return Response(ContentLibraryMetadataSerializer(result).data)
示例#3
0
    def setUp(self):
        super().setUp()
        # Create a couple students that the tests can use
        self.student_a = UserFactory.create(username="******", email="*****@*****.**", password="******")
        self.student_b = UserFactory.create(username="******", email="*****@*****.**", password="******")

        # Create a collection using Blockstore API directly only because there
        # is not yet any Studio REST API for doing so:
        self.collection = blockstore_api.create_collection("Content Library Test Collection")
        # Create an organization
        self.organization = Organization.objects.create(
            name="Content Libraries Tachyon Exploration & Survey Team",
            short_name="CL-TEST",
        )
        _, slug = self.id().rsplit('.', 1)
        self.library = library_api.create_library(
            collection_uuid=self.collection.uuid,
            library_type=COMPLEX,
            org=self.organization,
            slug=slugify(slug),
            title=(f"{slug} Test Lib"),
            description="",
            allow_public_learning=True,
            allow_public_read=False,
            library_license=ALL_RIGHTS_RESERVED,
        )
示例#4
0
 def test_identical_olx(self):
     """
     Test library blocks with children that also have identical OLX. Since
     the blockstore runtime caches authored field data based on the hash of
     the OLX, this can catch some potential bugs, especially given that the
     "children" field stores usage IDs, not definition IDs.
     """
     # Create a unit containing a <problem>
     unit_block_key = library_api.create_library_block(self.library.key, "unit", "u1").usage_key
     library_api.create_library_block_child(unit_block_key, "problem", "p1")
     library_api.publish_changes(self.library.key)
     # Now do the same in a different library:
     library2 = library_api.create_library(
         collection_uuid=self.collection.uuid,
         org=self.organization,
         slug="idolx",
         title=("Identical OLX Test Lib 2"),
         description="",
         library_type=COMPLEX,
         allow_public_learning=True,
         allow_public_read=False,
         library_license=CC_4_BY,
     )
     unit_block2_key = library_api.create_library_block(library2.key, "unit", "u1").usage_key
     library_api.create_library_block_child(unit_block2_key, "problem", "p1")
     library_api.publish_changes(library2.key)
     # Load both blocks:
     unit_block = xblock_api.load_block(unit_block_key, self.student_a)
     unit_block2 = xblock_api.load_block(unit_block2_key, self.student_a)
     assert library_api.get_library_block_olx(unit_block_key) == library_api.get_library_block_olx(unit_block2_key)
     assert unit_block.children != unit_block2.children
 def setUpClass(cls):
     """
     Create some XBlocks in a content library for use in any tests
     """
     super().setUpClass()
     # Create a couple libraries and blocks that can be used for these tests:
     cls.collection = blockstore_api.create_collection("Pathway Test Collection")
     cls.organization = Organization.objects.create(name="TestOrg", short_name="TestOrg")
     cls.lib1 = library_api.create_library(
         collection_uuid=cls.collection.uuid,
         org=cls.organization,
         slug="lx-pathway-lib1",
         title="Pathway Test Lib",
         description="",
         allow_public_learning=True,
         allow_public_read=True,
         library_type='complex',
         library_license='',
     )
     cls.problem_block1_id = library_api.create_library_block(cls.lib1.key, "problem", "p1").usage_key
     library_api.publish_changes(cls.lib1.key)
     cls.lib2 = library_api.create_library(
         collection_uuid=cls.collection.uuid,
         org=cls.organization,
         slug="lx-pathway-lib2",
         title="Pathway Test Lib 2",
         description="",
         allow_public_learning=True,
         allow_public_read=True,
         library_type='complex',
         library_license='',
     )
     cls.html_block2_id = library_api.create_library_block(cls.lib2.key, "html", "h2").usage_key
     library_api.publish_changes(cls.lib2.key)
     # Create some users:
     cls.user = UserFactory(username='******', password='******')
     cls.other_user = UserFactory(username='******', password='******')