Ejemplo n.º 1
0
    def test_entity_update_indexerror(self):
        """
        Test that we can't update a package if Solr is down.
        """
        bad_solr_url = "http://127.0.0.1/badsolrurl"
        original_settings = SolrSettings.get()[0]
        try:
            SolrSettings.init(bad_solr_url)

            assert_raises(search.SearchIndexError, self.assert_package_update_ok, "name", "post")
        finally:
            SolrSettings.init(original_settings)
Ejemplo n.º 2
0
    def test_entity_update_indexerror(self):
        """
        Test that we can't update a package if Solr is down.
        """
        bad_solr_url = 'http://example.com/badsolrurl'
        original_settings = SolrSettings.get()[0]
        try:
            SolrSettings.init(bad_solr_url)

            assert_raises(search.SearchIndexError,
                          self.assert_package_update_ok, 'name', 'post')
        finally:
            SolrSettings.init(original_settings)
Ejemplo n.º 3
0
    def test_entity_update_indexerror(self):
        """
        Test that we can't update a package if Solr is down.
        """
        bad_solr_url = 'http://example.com/badsolrurl'
        original_settings = SolrSettings.get()[0]
        try:
            SolrSettings.init(bad_solr_url)

            assert_raises(
                search.SearchIndexError, self.assert_package_update_ok, 'name', 'post'
            )
        finally:
            SolrSettings.init(original_settings)
Ejemplo n.º 4
0
    def test_entity_update_indexerror(self):
        """
        Test that we can't update a package if Solr is down.
        """
        bad_solr_url = 'http://127.0.0.1/badsolrurl'
        original_settings = SolrSettings.get()[0]
        try:
            SolrSettings.init(bad_solr_url)
            plugins.load('synchronous_search')

            assert_raises(search.SearchIndexError,
                          self.assert_package_update_ok, 'name', 'post')
        finally:
            plugins.unload('synchronous_search')
            SolrSettings.init(original_settings)
Ejemplo n.º 5
0
    def test_entity_update_indexerror(self):
        """
        Test that we can't update a package if Solr is down.
        """
        bad_solr_url = 'http://127.0.0.1/badsolrurl'
        original_settings = SolrSettings.get()[0]
        try:
            SolrSettings.init(bad_solr_url)
            plugins.load('synchronous_search')

            assert_raises(
                search.SearchIndexError, self.assert_package_update_ok, 'name', 'post'
            )
        finally:
            plugins.unload('synchronous_search')
            SolrSettings.init(original_settings)
Ejemplo n.º 6
0
def assert_solr_schema_is_the_dgu_variant():
    '''
        Checks if the schema version of the SOLR server is compatible
        with DGU.

        Based on ckan.lib.search.check_solr_schema_version
    '''

    import urllib2
    from ckan.lib.search.common import is_available, SolrSettings
    from ckan.lib.search import SOLR_SCHEMA_FILE_OFFSET

    if not is_available():
        # Something is wrong with the SOLR server
        log.warn('Problems were found while connecting to the SOLR server')
        return False

    # Request the schema XML file to extract the version
    solr_url, solr_user, solr_password = SolrSettings.get()
    http_auth = None
    if solr_user is not None and solr_password is not None:
        http_auth = solr_user + ':' + solr_password
        http_auth = 'Basic ' + http_auth.encode('base64').strip()

    url = solr_url.strip('/') + SOLR_SCHEMA_FILE_OFFSET

    req = urllib2.Request(url=url)
    if http_auth:
        req.add_header('Authorization', http_auth)

    solr_schema = urllib2.urlopen(req).read()
    assert 'DGU variant' in solr_schema, 'Change your development.ini to use the DGU schema.'
Ejemplo n.º 7
0
def assert_solr_schema_is_the_dgu_variant():
    '''
        Checks if the schema version of the SOLR server is compatible
        with DGU.

        Based on ckan.lib.search.check_solr_schema_version
    '''

    import urllib2
    from ckan.lib.search.common import is_available, SolrSettings
    from ckan.lib.search import SOLR_SCHEMA_FILE_OFFSET

    if not is_available():
        # Something is wrong with the SOLR server
        log.warn('Problems were found while connecting to the SOLR server')
        return False

    # Request the schema XML file to extract the version
    solr_url, solr_user, solr_password = SolrSettings.get()
    http_auth = None
    if solr_user is not None and solr_password is not None:
        http_auth = solr_user + ':' + solr_password
        http_auth = 'Basic ' + http_auth.encode('base64').strip()

    url = solr_url.strip('/') + SOLR_SCHEMA_FILE_OFFSET

    req = urllib2.Request(url=url)
    if http_auth:
        req.add_header('Authorization', http_auth)

    solr_schema = urllib2.urlopen(req).read()
    assert 'DGU variant' in solr_schema, 'Change your development.ini to use the DGU schema.'
Ejemplo n.º 8
0
    def test_new_indexerror(self, env_user, app):
        bad_solr_url = "http://example.com/badsolrurl"
        solr_url = SolrSettings.get()[0]
        try:
            SolrSettings.init(bad_solr_url)
            new_package_name = u"new-package-missing-solr"

            offset = url_for("dataset.new")
            res = app.get(offset, extra_environ=env_user)
            fv = res.forms["dataset-edit"]
            fv["name"] = new_package_name

            res = fv.submit("save", status=500, extra_environ=env_user)
            assert "Unable to add package to search index" in res, res
        finally:
            SolrSettings.init(solr_url)
Ejemplo n.º 9
0
    def test_register_post_indexerror(self):
        """
        Test that we can't add a package if Solr is down.
        """
        bad_solr_url = 'http://example.com/badsolrurl'
        original_settings = SolrSettings.get()[0]
        try:
            SolrSettings.init(bad_solr_url)

            assert not self.get_package_by_name(self.package_fixture_data['name'])
            offset = self.package_offset()
            data = self.dumps(self.package_fixture_data)

            self.post_json(offset, data, status=500, extra_environ=self.admin_extra_environ)
            model.Session.remove()
        finally:
            SolrSettings.init(original_settings)
Ejemplo n.º 10
0
    def test_new_indexerror(self, env_user, app):
        bad_solr_url = "http://example.com/badsolrurl"
        solr_url = SolrSettings.get()[0]
        try:
            SolrSettings.init(bad_solr_url)
            new_package_name = u"new-package-missing-solr"

            offset = url_for("dataset.new")
            res = app.post(offset,
                           extra_environ=env_user,
                           data={
                               "save": "",
                               "name": new_package_name,
                           })
            assert "Unable to add package to search index" in res, res
        finally:
            SolrSettings.init(solr_url)
Ejemplo n.º 11
0
    def test_register_post_indexerror(self):
        """
        Test that we can't add a package if Solr is down.
        """
        bad_solr_url = 'http://127.0.0.1/badsolrurl'
        original_settings = SolrSettings.get()[0]
        try:
            SolrSettings.init(bad_solr_url)

            assert not self.get_package_by_name(self.package_fixture_data['name'])
            offset = self.package_offset()
            data = self.dumps(self.package_fixture_data)

            self.post_json(offset, data, status=500, extra_environ=self.admin_extra_environ)
            model.Session.remove()
        finally:
            SolrSettings.init(original_settings)
Ejemplo n.º 12
0
    def test_register_post_indexerror(self):
        """
        Test that we can't add a package if Solr is down.
        """
        bad_solr_url = "http://127.0.0.1/badsolrurl"
        original_settings = SolrSettings.get()[0]
        try:
            SolrSettings.init(bad_solr_url)
            plugins.load("synchronous_search")

            assert not self.get_package_by_name(self.package_fixture_data["name"])
            offset = self.package_offset()
            data = self.dumps(self.package_fixture_data)

            self.post_json(offset, data, status=500, extra_environ=self.admin_extra_environ)
            model.Session.remove()
        finally:
            SolrSettings.init(original_settings)
Ejemplo n.º 13
0
    def test_new_indexerror(self):
        bad_solr_url = 'http://127.0.0.1/badsolrurl'
        solr_url = SolrSettings.get()[0]
        try:
            SolrSettings.init(bad_solr_url)
            new_package_name = u'new-package-missing-solr'

            offset = url_for(controller='package', action='new')
            res = self.app.get(offset, extra_environ=self.extra_environ_tester)
            fv = res.forms['dataset-edit']
            fv['name'] = new_package_name

            # this package shouldn't actually be created but
            # add it to the list to purge just in case
            self.pkg_names.append(new_package_name)

            res = fv.submit('save', status=500, extra_environ=self.extra_environ_tester)
            assert 'Unable to add package to search index' in res, res
        finally:
            SolrSettings.init(solr_url)
Ejemplo n.º 14
0
def _get_schema_from_solr(file_offset):
    solr_url, solr_user, solr_password = SolrSettings.get()

    url = solr_url.strip('/') + file_offset

    if solr_user is not None and solr_password is not None:
        response = requests.get(
            url, auth=requests.auth.HTTPBasicAuth(solr_user, solr_password))
    else:
        response = requests.get(url)

    return response
Ejemplo n.º 15
0
def make_connection():
    """
    Creates NGDS Solr Connection based on the values configured in pylons configuration file.
    """

    from ckan.lib.search.common import SolrSettings

    solr_url, solr_user, solr_password = SolrSettings.get()
    assert solr_url is not None
    if solr_user is not None and solr_password is not None:
        return NgdsSolrConnection(solr_url, http_user=solr_user,
                              http_pass=solr_password)
    else:
        return NgdsSolrConnection(solr_url)
Ejemplo n.º 16
0
def _get_schema_from_solr(file_offset):
    solr_url, solr_user, solr_password = SolrSettings.get()

    http_auth = None
    if solr_user is not None and solr_password is not None:
        http_auth = solr_user + ':' + solr_password
        http_auth = 'Basic ' + http_auth.encode('base64').strip()

    url = solr_url.strip('/') + file_offset

    if http_auth:
        response = requests.get(url, headers={'Authorization': http_auth})
    else:
        response = requests.get(url)

    return response