Пример #1
0
    def test_name_collision(self):
        """
        Test that collisions won't happen for terms. Vocabularies can't
        have the same name so we don't test that here.
        """
        vocab1 = Vocabulary.objects.create(repository=self.repo,
                                           required=False,
                                           weight=1,
                                           name='voc with spaces 1',
                                           multi_terms=True)
        vocab2 = Vocabulary.objects.create(repository=self.repo,
                                           required=False,
                                           weight=1,
                                           name='voc with spaces 2',
                                           multi_terms=True)
        vocab1.learning_resource_types = [self.resource.learning_resource_type]
        vocab2.learning_resource_types = [self.resource.learning_resource_type]
        vocab1_key = vocab1.index_key
        vocab2_key = vocab2.index_key

        term1 = Term.objects.create(label='tortoise 1',
                                    weight=1,
                                    vocabulary=vocab1)
        term2 = Term.objects.create(label='tortoise 1',
                                    weight=1,
                                    vocabulary=vocab2)

        # Some reindexing is skipped by dealing with models directly.
        recreate_index()

        self.patch_learning_resource(self.repo.slug, self.resource.id,
                                     {"terms": [term2.slug]})
        self.assertEqual(
            self.get_results(selected_facets=[
                "{v}_exact:{t}".format(v=vocab1_key, t=term1.id)
            ])['count'], 0)
        self.assertEqual(
            self.get_results(selected_facets=[
                "{v}_exact:{t}".format(v=vocab2_key, t=term2.id)
            ])['count'], 1)

        self.patch_learning_resource(self.repo.slug, self.resource.id,
                                     {"terms": [term1.slug]})
        self.assertEqual(
            self.get_results(selected_facets=[
                "{v}_exact:{t}".format(v=vocab1_key, t=term1.id)
            ])['count'], 1)
        self.assertEqual(
            self.get_results(selected_facets=[
                "{v}_exact:{t}".format(v=vocab2_key, t=term2.id)
            ])['count'], 0)
Пример #2
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()
Пример #3
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()
Пример #4
0
    def test_name_collision(self):
        """
        Test that collisions won't happen for terms. Vocabularies can't
        have the same name so we don't test that here.
        """
        vocab1 = Vocabulary.objects.create(
            repository=self.repo,
            required=False,
            weight=1,
            name='voc with spaces 1',
            multi_terms=True
        )
        vocab2 = Vocabulary.objects.create(
            repository=self.repo,
            required=False,
            weight=1,
            name='voc with spaces 2',
            multi_terms=True
        )
        vocab1.learning_resource_types = [self.resource.learning_resource_type]
        vocab2.learning_resource_types = [self.resource.learning_resource_type]
        vocab1_key = vocab1.index_key
        vocab2_key = vocab2.index_key

        term1 = Term.objects.create(
            label='tortoise 1',
            weight=1,
            vocabulary=vocab1
        )
        term2 = Term.objects.create(
            label='tortoise 1',
            weight=1,
            vocabulary=vocab2
        )

        # Some reindexing is skipped by dealing with models directly.
        recreate_index()

        self.patch_learning_resource(self.repo.slug, self.resource.id, {
            "terms": [term2.slug]
        })
        self.assertEqual(
            self.get_results(selected_facets=["{v}_exact:{t}".format(
                v=vocab1_key,
                t=term1.id
            )])['count'],
            0
        )
        self.assertEqual(
            self.get_results(selected_facets=["{v}_exact:{t}".format(
                v=vocab2_key,
                t=term2.id
            )])['count'],
            1
        )

        self.patch_learning_resource(self.repo.slug, self.resource.id, {
            "terms": [term1.slug]
        })
        self.assertEqual(
            self.get_results(selected_facets=["{v}_exact:{t}".format(
                v=vocab1_key,
                t=term1.id
            )])['count'],
            1
        )
        self.assertEqual(
            self.get_results(selected_facets=["{v}_exact:{t}".format(
                v=vocab2_key,
                t=term2.id
            )])['count'],
            0
        )
Пример #5
0
 def handle(self, *args, **options):
     """Command for recreate_index"""
     recreate_index()