예제 #1
0
    def test_invalid_create_repo(self):
        """Create a repository with empty name and description"""
        with self.assertRaises(IntegrityError) as ex:
            api.create_repo(None, "description", self.user.id)
        self.assertIn("name", ex.exception.args[0])

        with self.assertRaises(IntegrityError) as ex:
            api.create_repo("name", None, self.user.id)
        self.assertIn("description", ex.exception.args[0])
예제 #2
0
파일: test_api.py 프로젝트: olabi/lore
    def test_repository_exact_match(self):
        """
        Test that repository slug matches exactly
        """
        test_repo = create_repo("test", "testing", self.user.id)
        testing_repo = create_repo("testing", "testing", self.user.id)

        # Should start off with nothing in testing_repo.
        self.assertEqual(construct_queryset(test_repo.slug).count(), 0)
        self.assertEqual(construct_queryset(testing_repo.slug).count(), 0)
        self.import_course_tarball(test_repo)

        # We imported into 'test' so 'testing' shouldn't contain anything.
        self.assertTrue(construct_queryset(test_repo.slug).count() > 0)
        self.assertEqual(construct_queryset(testing_repo.slug).count(), 0)
예제 #3
0
    def test_nested_leaves(self):
        """
        Test that nested leaves are not imported.
        """
        template = """
<course org="DevOps" course="0.001" url_name="2015_Summer"
    semester="2015_Summer">
  <chapter>
    <sequential>
      <vertical>
        <{tag}><{tag}></{tag}></{tag}>
      </vertical>
    </sequential>
  </chapter>
</course>
"""

        for tag in ("html", "problem", "discussion", "video"):
            repo = create_repo(
                "{tag}_repo".format(tag=tag), "...", self.user.id)
            xml = etree.fromstring(template.format(tag=tag))
            bundle = XBundle(
                keep_urls=True, keep_studio_urls=True, preserve_url_name=True
            )
            bundle.set_course(xml)

            import_course(bundle, repo.id, self.user.id, "")

            self.assertEqual(
                LearningResource.objects.filter(
                    learning_resource_type__name=tag
                ).count(),
                1
            )
예제 #4
0
    def test_create_repo_with_recreate_index(self):
        """
        Test that we can create a new repo and that the refresh_index command
        indexes appropriately. Note that this test has custom setUp
        and tearDown code.
        """
        # When user installs LORE they must call refresh_index
        # or recreate_index to create the index.
        call_command("recreate_index")

        repo = create_repo("new repo", "new repo", self.user.id)
        search_url = "{api_base}repositories/{repo_slug}/search/".format(
            api_base=API_BASE, repo_slug=repo.slug)

        resp = self.client.get(search_url)
        self.assertEqual(resp.status_code, HTTP_200_OK)
        result = json.loads(resp.content.decode('utf-8'))
        self.assertEqual(0, result['count'])

        # Import. This should index the resources automatically.
        import_course_from_file(self.get_course_zip(), repo.id, self.user.id)

        resp = self.client.get(search_url)
        self.assertEqual(resp.status_code, HTTP_200_OK)
        result = json.loads(resp.content.decode('utf-8'))
        self.assertTrue(result['count'] > 0)
예제 #5
0
    def test_create_repo_with_recreate_index(self):
        """
        Test that we can create a new repo and that the refresh_index command
        indexes appropriately. Note that this test has custom setUp
        and tearDown code.
        """
        # When user installs LORE they must call refresh_index
        # or recreate_index to create the index.
        call_command("recreate_index")

        repo = create_repo("new repo", "new repo", self.user.id)
        search_url = "{api_base}repositories/{repo_slug}/search/".format(
            api_base=API_BASE,
            repo_slug=repo.slug
        )

        resp = self.client.get(search_url)
        self.assertEqual(resp.status_code, HTTP_200_OK)
        result = json.loads(resp.content.decode('utf-8'))
        self.assertEqual(0, result['count'])

        # Import. This should index the resources automatically.
        import_course_from_file(self.get_course_zip(), repo.id, self.user.id)

        resp = self.client.get(search_url)
        self.assertEqual(resp.status_code, HTTP_200_OK)
        result = json.loads(resp.content.decode('utf-8'))
        self.assertTrue(result['count'] > 0)
예제 #6
0
파일: test_utils.py 프로젝트: olabi/lore
    def test_sync_permissions(self):
        """
        test the syncpermission
        """
        repo = create_repo(self.repo_name, self.repo_desc, self.user.id)

        # Get default permissions before wiping.
        admin = Group.objects.get(name=self.group_admin)
        self.check_group_permission(
            repo,
            admin,
            RepoPermission.administrator_permissions()
        )
        with patch.object(utils, 'roles_init_new_repo') as mock_method:
            mock_method.return_value = None
            utils.sync_groups_permissions()
        # Get default permissions after wiping.
        self.check_group_permission(
            repo,
            admin,
            []
        )
        # Restore permissions the first call of sync_groups_permissions
        # will not do anything because the permissions have been already wiped.
        utils.sync_groups_permissions()
        self.check_group_permission(
            repo,
            admin,
            RepoPermission.administrator_permissions()
        )
예제 #7
0
    def test_repository_facet(self):
        """
        Verify that searches stay within repository.
        """
        repo2 = create_repo("repo2", "repo2", self.user.id)
        self.import_course_tarball(repo2)
        self.assertEqual(1, self.get_results()['count'])

        self.import_course_tarball(self.repo)
        self.assertEqual(19, self.get_results()['count'])
예제 #8
0
파일: test_search.py 프로젝트: mitodl/lore
    def test_repository_facet(self):
        """
        Verify that searches stay within repository.
        """
        repo2 = create_repo("repo2", "repo2", self.user.id)
        self.import_course_tarball(repo2)
        self.assertEqual(1, self.get_results()['count'])

        self.import_course_tarball(self.repo)
        self.assertEqual(19, self.get_results()['count'])
예제 #9
0
파일: test_models.py 프로젝트: olabi/lore
 def test_vocab_created(self):
     """
     At the moment there are no vocabularies automatically created
     though that will change soon.
     """
     repo = create_repo(
         name="Ford Prefect",
         description="Mostly harmless.",
         user_id=self.user.id
     )
     self.assertEqual(len(get_vocabularies(repo.id)), 0)
예제 #10
0
    def test_create_repo_without_reindex(self):
        """
        Test that user gets an error message if they have never reindexed.
        """
        repo = create_repo("new repo", "new repo", self.user.id)
        search_url = "{api_base}repositories/{repo_slug}/search/".format(
            api_base=API_BASE, repo_slug=repo.slug)

        # When user installs LORE they must call refresh_index to create the
        # index, else they get this error message.
        with self.assertRaises(ReindexException):
            self.client.get(search_url)
예제 #11
0
    def test_create_repo_without_reindex(self):
        """
        Test that user gets an error message if they have never reindexed.
        """
        repo = create_repo("new repo", "new repo", self.user.id)
        search_url = "{api_base}repositories/{repo_slug}/search/".format(
            api_base=API_BASE,
            repo_slug=repo.slug
        )

        # When user installs LORE they must call refresh_index to create the
        # index, else they get this error message.
        with self.assertRaises(ReindexException):
            self.client.get(search_url)
예제 #12
0
    def test_single_repo(self):
        """
        Search should only return records for one repository
        at a time.
        """
        resp = self.client.get(reverse("repositories", args=(self.repo.slug,)))
        self.assertContains(resp, self.resource.title)

        # Make a new repo with no content.
        new_repo = create_repo("other", "whatever", self.user.id)
        assign_user_to_repo_group(
            self.user,
            new_repo,
            GroupTypes.REPO_ADMINISTRATOR
        )
        resp = self.client.get(reverse("repositories", args=(new_repo.slug,)))
        self.assertNotContains(resp, self.resource.title)
예제 #13
0
파일: base.py 프로젝트: Ferdi/lore
    def setUp(self):
        """set up"""
        super(LoreTestCase, self).setUp()
        self.user = User.objects.create_user(
            username=self.USERNAME, password=self.PASSWORD
        )
        self.client = Client()
        self.client.login(
            username=self.USERNAME,
            password=self.PASSWORD
        )

        self.repo = create_repo(
            name="test repo",
            description="just a test",
            user_id=self.user.id,
        )
예제 #14
0
 def test_roles_init_new_repo_fake_permission_curator(self):
     """
     Non existing permissions for curator
     """
     with patch.object(api.RepoPermission,
                       'curator_permissions') as mock_method:
         mock_method.return_value = ['fake_permission']
         repo = create_repo(
             name=self.repo_name,
             description=self.repo_desc,
             user_id=self.user.id,
         )
         curator = Group.objects.get(name=self.group_curator)
         self.assertListEqual(
             get_perms(curator, repo),
             []
         )
예제 #15
0
파일: base.py 프로젝트: jetej/lore
    def setUp(self):
        """set up"""
        super(LoreTestCase, self).setUp()
        self.user = User.objects.create_user(
            username=self.USERNAME, password=self.PASSWORD
        )
        add_repo_perm = Permission.objects.get(codename=self.ADD_REPO_PERM)
        self.user.user_permissions.add(add_repo_perm)
        # user without permission to add a repo
        self.user_norepo = User.objects.create_user(
            username=self.USERNAME_NO_REPO, password=self.PASSWORD
        )

        self.repo = create_repo(
            name="test repo",
            description="just a test",
            user_id=self.user.id,
        )
        self.course = create_course(
            org="test-org",
            repo_id=self.repo.id,
            course_number="infinity",
            run="Febtober",
            user_id=self.user.id,
        )
        self.resource = self.create_resource(
            course=self.course,
            parent=None,
            resource_type="example",
            title="silly example",
            content_xml="<blah>blah</blah>",
            mpath="/blah",
            url_name="url_name1",
        )

        assign_user_to_repo_group(
            self.user,
            self.repo,
            GroupTypes.REPO_ADMINISTRATOR
        )
        self.toy_resource_count = 18  # Resources in toy course.
        self.toy_asset_count = 5  # Static assets in toy course.
        self.client = Client()

        self.login(username=self.USERNAME)
예제 #16
0
    def test_sync_permissions(self):
        """
        test the syncpermission
        """
        repo = create_repo(self.repo_name, self.repo_desc, self.user.id)

        # Get default permissions before wiping.
        admin = Group.objects.get(name=self.group_admin)
        self.check_group_permission(repo, admin, RepoPermission.administrator_permissions())
        with patch.object(utils, "roles_init_new_repo") as mock_method:
            mock_method.return_value = None
            utils.sync_groups_permissions()
        # Get default permissions after wiping.
        self.check_group_permission(repo, admin, [])
        # Restore permissions the first call of sync_groups_permissions
        # will not do anything because the permissions have been already wiped.
        utils.sync_groups_permissions()
        self.check_group_permission(repo, admin, RepoPermission.administrator_permissions())
예제 #17
0
    def test_parent_preview_link(self):
        """
        Test that if url_name is blank we import the parent's url_name when
        viewing the preview link.
        """
        xml = """
<course org="DevOps" course="0.001" url_name="2015_Summer"
    semester="2015_Summer">
  <chapter>
    <sequential>
      <vertical>
        <html></html>
      </vertical>
    </sequential>
  </chapter>
</course>
"""

        repo = create_repo("html_repo", "...", self.user.id)
        xml = etree.fromstring(xml)
        bundle = XBundle(
            keep_urls=True, keep_studio_urls=True, preserve_url_name=True
        )
        bundle.set_course(xml)

        import_course(bundle, repo.id, self.user.id, "")

        html_resources = LearningResource.objects.filter(
            learning_resource_type__name="html"
        )
        self.assertEqual(html_resources.count(), 1)
        html_resource = html_resources.first()
        self.assertEqual(
            get_preview_url(html_resource),
            "{base}courses/{org}/{course}/{run}/jump_to_id/{url_path}".format(
                base=settings.LORE_PREVIEW_BASE_URL,
                org=html_resource.course.org,
                course=html_resource.course.course_number,
                run=html_resource.course.run,
                url_path="2015_Summer"
            )
        )
예제 #18
0
    def setUp(self):
        """set up"""
        super(LoreTestCase, self).setUp()
        recreate_index()
        self.user = User.objects.create_user(username=self.USERNAME,
                                             password=self.PASSWORD)
        add_repo_perm = Permission.objects.get(codename=self.ADD_REPO_PERM)
        self.user.user_permissions.add(add_repo_perm)
        # user without permission to add a repo
        self.user_norepo = User.objects.create_user(
            username=self.USERNAME_NO_REPO, password=self.PASSWORD)

        self.repo = create_repo(
            name="test repo",
            description="just a test",
            user_id=self.user.id,
        )
        self.course = create_course(
            org="test-org",
            repo_id=self.repo.id,
            course_number="infinity",
            run="Febtober",
            user_id=self.user.id,
        )
        self.resource = self.create_resource(
            course=self.course,
            parent=None,
            resource_type="example",
            title="silly example",
            content_xml="<blah>blah</blah>",
            mpath="/blah",
            url_name="url_name1",
        )

        self.toy_resource_count = 18  # Resources in toy course.
        self.toy_asset_count = 5  # Static assets in toy course.
        self.client = Client()

        self.login(username=self.USERNAME)
        refresh_index()
예제 #19
0
파일: test_search.py 프로젝트: mitodl/lore
    def test_vocab_cross_contamination(self):
        """
        Test that vocabularies only show up in the repositories they belong to.
        """
        repo2 = create_repo("two", "two", self.user.id)
        vocab1 = Vocabulary.objects.create(
            repository=self.repo, required=False, name="vocab1", weight=1
        )
        vocab2 = Vocabulary.objects.create(
            repository=repo2, required=False, name="vocab2", weight=1
        )
        vocab1_key = vocab1.index_key
        vocab2_key = vocab2.index_key

        repo1_counts = self.get_results(
            repo_slug=self.repo.slug)['facet_counts']
        repo2_counts = self.get_results(
            repo_slug=repo2.slug)['facet_counts']

        self.assertTrue(vocab1_key in repo1_counts)
        self.assertFalse(vocab2_key in repo1_counts)
        self.assertFalse(vocab1_key in repo2_counts)
        self.assertTrue(vocab2_key in repo2_counts)
예제 #20
0
파일: test_search.py 프로젝트: olabi/lore
    def test_vocab_cross_contamination(self):
        """
        Test that vocabularies only show up in the repositories they belong to.
        """
        repo2 = create_repo("two", "two", self.user.id)
        vocab1 = Vocabulary.objects.create(
            repository=self.repo, required=False, name="vocab1", weight=1
        )
        vocab2 = Vocabulary.objects.create(
            repository=repo2, required=False, name="vocab2", weight=1
        )
        vocab1_key = vocab1.index_key
        vocab2_key = vocab2.index_key

        repo1_counts = self.get_results(
            repo_slug=self.repo.slug)['facet_counts']
        repo2_counts = self.get_results(
            repo_slug=repo2.slug)['facet_counts']

        self.assertTrue(vocab1_key in repo1_counts)
        self.assertFalse(vocab2_key in repo1_counts)
        self.assertFalse(vocab1_key in repo2_counts)
        self.assertTrue(vocab2_key in repo2_counts)