예제 #1
0
 def test_static_import_integration(self):
     """
     Do integration test to validate course import with static assets.
     """
     original_count = Course.objects.count()
     tarball_file = self.get_course_single_tarball()
     import_file(
         tarball_file, self.repo.id, self.user.id)
     self.assertEqual(
         Course.objects.count(),
         original_count + 1,
     )
     self.assertFalse(os.path.exists(tarball_file))
     course = Course.objects.all().exclude(id=self.course.id)
     self.assertEqual(course.count(), 1)
     assets = StaticAsset.objects.filter(course=course)
     for asset in assets:
         self.addCleanup(default_storage.delete, asset.asset)
     self.assertEqual(assets.count(), self.toy_asset_count)
     for asset in assets:
         base_path = static_asset_basepath(asset, '')
         self.assertIn(
             asset.asset.name.replace(base_path, ''),
             [
                 'test.txt', 'subdir/subtext.txt',
                 'subs_CCxmtcICYNc.srt.sjson',
                 'essays_x250.png', 'webGLDemo.css',
             ]
         )
예제 #2
0
 def test_static_import_integration(self):
     """
     Do integration test to validate course import with static assets.
     """
     original_count = Course.objects.count()
     tarball_file = self.get_course_single_tarball()
     import_file(
         tarball_file, self.repo.id, self.user.id)
     self.assertEqual(
         Course.objects.count(),
         original_count + 1,
     )
     self.assertFalse(os.path.exists(tarball_file))
     course = Course.objects.all().exclude(id=self.course.id)
     self.assertEqual(course.count(), 1)
     assets = StaticAsset.objects.filter(course=course)
     for asset in assets:
         self.addCleanup(default_storage.delete, asset.asset)
     self.assertEqual(assets.count(), self.toy_asset_count)
     for asset in assets:
         base_path = static_asset_basepath(asset, '')
         self.assertIn(
             asset.asset.name.replace(base_path, ''),
             [
                 'test.txt', 'subdir/subtext.txt',
                 'subs_CCxmtcICYNc.srt.sjson',
                 'essays_x250.png', 'webGLDemo.css',
             ]
         )
예제 #3
0
파일: base.py 프로젝트: fatimahseraj/lore
 def import_course_tarball(self, repo):
     """
     Import course.xml into repo and return first LearningResource
     which has any StaticAssets.
     """
     tarball_file = self.get_course_single_tarball()
     import_file(tarball_file, repo.id, self.user.id)
     return get_resources(
         repo.id).annotate(count_assets=Count('static_assets')).filter(
             count_assets__gt=0).first()
예제 #4
0
 def import_course_tarball(self, repo):
     """
     Import course.xml into repo and return first LearningResource
     which has any StaticAssets.
     """
     tarball_file = self.get_course_single_tarball()
     import_file(
         tarball_file, repo.id, self.user.id)
     return get_resources(repo.id).annotate(
         count_assets=Count('static_assets')
     ).filter(count_assets__gt=0).first()
예제 #5
0
 def test_import_task(self):
     """
     Copy of test_import_single that just exercises tasks.py.
     """
     original_count = Course.objects.count()
     import_file(
         self.get_course_single_tarball(), self.repo.id, self.user.id)
     self.assertEqual(
         Course.objects.count(),
         original_count + 1,
     )
예제 #6
0
 def test_import_task(self):
     """
     Copy of test_import_single that just exercises tasks.py.
     """
     original_count = Course.objects.count()
     import_file(
         self.get_course_single_tarball(), self.repo.id, self.user.id)
     self.assertEqual(
         Course.objects.count(),
         original_count + 1,
     )
예제 #7
0
    def setUp(self):
        super(TestExport, self).setUp()

        # Add some LearningResources on top of the default to make things
        # interesting.
        tarball_file = self.get_course_single_tarball()
        import_file(tarball_file, self.repo.id, self.user.id)

        # Add a resource with a '/' in the title and too many characters.
        course = self.repo.course_set.first()
        resource = create_resource(
            course=course,
            resource_type=LearningResourceType.objects.first().name,
            title="//x"*300,
            content_xml="",
            mpath="",
            url_name=None,
            parent=None,
            dpath=''
        )
        update_description_path(resource)

        # Add static assets.
        with TemporaryFile() as temp1:
            with TemporaryFile() as temp2:
                temp1.write(b"file1")
                temp2.write(b"file2")
                file1 = File(temp1, name="iamafile1.txt")
                file2 = File(temp2, name="iamafile2.txt")

                asset1 = create_static_asset(course.id, file1)
                resource.static_assets.add(asset1)

                # If url_name is missing we should just use id in filename.
                resource.url_name = None
                resource.save()

                asset2 = create_static_asset(course.id, file2)
                self.resource.static_assets.add(asset2)
예제 #8
0
    def setUp(self):
        super(TestExport, self).setUp()

        # Add some LearningResources on top of the default to make things
        # interesting.
        tarball_file = self.get_course_single_tarball()
        import_file(tarball_file, self.repo.id, self.user.id)

        # Add a resource with a '/' in the title and too many characters.
        course = self.repo.course_set.first()
        resource = create_resource(
            course=course,
            resource_type=LearningResourceType.objects.first().name,
            title="//x" * 300,
            content_xml="",
            mpath="",
            url_name=None,
            parent=None,
            dpath='')
        update_description_path(resource)

        # Add static assets.
        with TemporaryFile() as temp1:
            with TemporaryFile() as temp2:
                temp1.write(b"file1")
                temp2.write(b"file2")
                file1 = File(temp1, name="iamafile1.txt")
                file2 = File(temp2, name="iamafile2.txt")

                asset1 = create_static_asset(course.id, file1)
                resource.static_assets.add(asset1)

                # If url_name is missing we should just use id in filename.
                resource.url_name = None
                resource.save()

                asset2 = create_static_asset(course.id, file2)
                self.resource.static_assets.add(asset2)
    def test_missing_learning_resource(self):
        """Test for an invalid LearningResource id."""
        repo_slug1 = self.repo.slug
        resource1 = self.import_course_tarball(self.repo)
        lr1_id = resource1.id

        # import from a different course so it's not a duplicate course
        zip_file = self.get_course_zip()
        new_repo_dict = self.create_repository()
        repo_slug2 = new_repo_dict['slug']
        repo_id2 = new_repo_dict['id']
        import_file(
            zip_file, repo_id2, self.user.id)
        resource2 = get_resources(repo_id2).first()
        lr2_id = resource2.id

        # repo_slug1 should own lr1_id and repo_slug2 should own lr2_id
        self.get_learning_resource(repo_slug1, lr1_id)
        self.get_learning_resource(repo_slug2, lr1_id,
                                   expected_status=HTTP_404_NOT_FOUND)
        self.get_learning_resource(repo_slug1, lr2_id,
                                   expected_status=HTTP_404_NOT_FOUND)
        self.get_learning_resource(repo_slug2, lr2_id)
예제 #10
0
    def test_missing_learning_resource(self):
        """Test for an invalid LearningResource id."""
        repo_slug1 = self.repo.slug
        resource1 = self.import_course_tarball(self.repo)
        lr1_id = resource1.id

        # import from a different course so it's not a duplicate course
        zip_file = self.get_course_zip()
        new_repo_dict = self.create_repository()
        repo_slug2 = new_repo_dict['slug']
        repo_id2 = new_repo_dict['id']
        import_file(
            zip_file, repo_id2, self.user.id)
        resource2 = get_resources(repo_id2).first()
        lr2_id = resource2.id

        # repo_slug1 should own lr1_id and repo_slug2 should own lr2_id
        self.get_learning_resource(repo_slug1, lr1_id)
        self.get_learning_resource(repo_slug2, lr1_id,
                                   expected_status=HTTP_404_NOT_FOUND)
        self.get_learning_resource(repo_slug1, lr2_id,
                                   expected_status=HTTP_404_NOT_FOUND)
        self.get_learning_resource(repo_slug2, lr2_id)
예제 #11
0
파일: test_api.py 프로젝트: olabi/lore
 def import_course_tarball(self, repo):
     """
     Import course into repository.
     """
     tarball_file = self.get_course_single_tarball()
     import_file(tarball_file, repo.id, self.user.id)