Esempio n. 1
0
    def test_index_exception(self):
        """
        Ensure that an exception is thrown if we have not indexed properly.
        """
        # Delete the index
        remove_index()

        search_url = "/api/v1/repositories/{repo}/search/".format(
            repo=self.repo.slug)
        with self.assertRaises(ReindexException):
            self.client.get(search_url)

        # Create a mapping
        with self.assertRaises(ReindexException):
            # Mapping doesn't exist yet
            get_conn()

        conn = get_conn(verify=False)
        conn.indices.create(INDEX_NAME)
        conn.indices.refresh()
        create_mapping()

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

        # Reindex all resources
        resource_ids = LearningResource.objects.values_list("id", flat=True)
        index_resources(resource_ids)

        resp = self.client.get(search_url)
        self.assertEqual(resp.status_code, HTTP_200_OK)
        self.assertEqual(
            json.loads(resp.content.decode('utf-8'))['count'],
            len(resource_ids))
Esempio n. 2
0
 def setUp(self):
     """Override to only remove index."""
     username = '******'
     password = '******'
     self.user = User.objects.create_user(username=username,
                                          password=password)
     self.client.login(username=username, password=password)
     remove_index()
Esempio n. 3
0
 def setUp(self):
     """Override to only remove index."""
     username = '******'
     password = '******'
     self.user = User.objects.create_user(
         username=username, password=password
     )
     self.client.login(username=username, password=password)
     remove_index()
Esempio n. 4
0
    def test_index_exception(self):
        """
        Ensure that an exception is thrown if we have not indexed properly.
        """
        # Delete the index
        remove_index()

        search_url = "/api/v1/repositories/{repo}/search/".format(
            repo=self.repo.slug
        )
        with self.assertRaises(ReindexException):
            self.client.get(search_url)

        # Create a mapping
        with self.assertRaises(ReindexException):
            # Mapping doesn't exist yet
            get_conn()

        conn = get_conn(verify=False)
        conn.indices.create(INDEX_NAME)
        conn.indices.refresh()
        create_mapping()

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

        # Reindex all resources
        resource_ids = LearningResource.objects.values_list("id", flat=True)
        index_resources(resource_ids)

        resp = self.client.get(search_url)
        self.assertEqual(resp.status_code, HTTP_200_OK)
        self.assertEqual(
            json.loads(resp.content.decode('utf-8'))['count'],
            len(resource_ids)
        )
Esempio n. 5
0
 def tearDown(self):
     """Override to only remove index."""
     remove_index()
Esempio n. 6
0
 def tearDown(self):
     """Clean up Elasticsearch and static assets between tests."""
     for static_asset in StaticAsset.objects.all():
         default_storage.delete(static_asset.asset)
     remove_index()
Esempio n. 7
0
 def tearDown(self):
     """Override to only remove index."""
     remove_index()
Esempio n. 8
0
 def tearDown(self):
     """Clean up Elasticsearch and static assets between tests."""
     for static_asset in StaticAsset.objects.all():
         default_storage.delete(static_asset.asset)
     remove_index()