예제 #1
0
    def configure(self, config_):
        results.create_database_table()

        # Update the class variables for the config settings with the values
        # from the config file, *if* they're in the config file.
        config.recheck_resources_after = toolkit.asint(
            config_.get("ckanext.deadoralive.recheck_resources_after",
                        config.recheck_resources_after))
        config.resend_pending_resources_after = toolkit.asint(
            config_.get("ckanext.deadoralive.resend_pending_resources_after",
                        config.resend_pending_resources_after))
        config.broken_resource_min_fails = toolkit.asint(
            config_.get("ckanext.deadoralive.broken_resource_min_fails",
                        config.broken_resource_min_fails))
        config.broken_resource_min_hours = toolkit.asint(
            config_.get("ckanext.deadoralive.broken_resource_min_hours",
                        config.broken_resource_min_hours))
        config.authorized_users = toolkit.aslist(
            config_.get("ckanext.deadoralive.authorized_users",
                        config.authorized_users))
예제 #2
0
    def configure(self, config_):
        results.create_database_table()

        # Update the class variables for the config settings with the values
        # from the config file, *if* they're in the config file.
        config.recheck_resources_after = toolkit.asint(config_.get(
            "ckanext.deadoralive.recheck_resources_after",
            config.recheck_resources_after))
        config.resend_pending_resources_after = toolkit.asint(
            config_.get(
                "ckanext.deadoralive.resend_pending_resources_after",
                config.resend_pending_resources_after))
        config.broken_resource_min_fails = toolkit.asint(
            config_.get(
                "ckanext.deadoralive.broken_resource_min_fails",
                config.broken_resource_min_fails))
        config.broken_resource_min_hours = toolkit.asint(
            config_.get(
                "ckanext.deadoralive.broken_resource_min_hours",
                config.broken_resource_min_hours))
        config.authorized_users = toolkit.aslist(
            config_.get(
                "ckanext.deadoralive.authorized_users",
                config.authorized_users))
 def setup(self):
     results.create_database_table()
     helpers.reset_db()
예제 #4
0
    def test(self):
        """Test that deadoralive and ckanext-deadoralive work together.

        Add some resources with working and some with broken links to CKAN,
        run deadoralive, check that it added the right results.

        """
        results.create_database_table()

        user = factories.User()

        # FunctionalTestBaseClass has already made self.app for us, but we
        # need one with our authorized_users config setting in it so replace it
        # with our own.
        config["ckanext.deadoralive.authorized_users"] = user["name"]
        self.app = custom_helpers._get_test_app()

        # The URL of the CKAN site we'll be using.
        # We'll be mocking the URLs on this domain that we expect to be sending
        # requests to.
        ckan_url = "http://test.ckan.org"

        # Mock some working and some broken resource URLs.
        # We'll create resources with these URLs in CKAN below.
        url_1 = "http://demo.ckan.org/url_1"
        httpretty.register_uri(httpretty.GET, url_1, status=200),
        url_2 = "http://demo.ckan.org/url_2"
        httpretty.register_uri(httpretty.GET, url_2, status=500),
        url_3 = "http://demo.ckan.org/url_3"
        httpretty.register_uri(httpretty.GET, url_3, status=200),

        # We're also going to mock the CKAN API URLs that deadoralive will be
        # requesting. We'll catch these requests and then forward them to a CKAN
        # test app.
        # FIXME: It would be nice if we could just mock http://test.ckan.org/*
        # and forward all requests on to the test app, but I don't think
        # httpretty supports this.
        get_resource_ids_url = ckan_url + "/deadoralive/get_resources_to_check"
        httpretty.register_uri(httpretty.GET, get_resource_ids_url, body=self._forward_to_test_app)
        httpretty.register_uri(httpretty.POST, get_resource_ids_url, body=self._forward_to_test_app)

        get_url_for_id_url = ckan_url + "/deadoralive/get_url_for_resource_id"
        httpretty.register_uri(httpretty.GET, get_url_for_id_url, body=self._forward_to_test_app)
        httpretty.register_uri(httpretty.POST, get_url_for_id_url, body=self._forward_to_test_app)

        upsert_result_url = ckan_url + "/deadoralive/upsert"
        httpretty.register_uri(httpretty.GET, upsert_result_url, body=self._forward_to_test_app)
        httpretty.register_uri(httpretty.POST, upsert_result_url, body=self._forward_to_test_app)

        # Create the resources in CKAN whose links will be checked.
        resource_1 = custom_factories.Resource(url=url_1)
        resource_2 = custom_factories.Resource(url=url_2)
        resource_3 = custom_factories.Resource(url=url_3)

        # Call deadoralive: It should get the IDs of the three resources from
        # CKAN.  get each resource's URL from CKAN, test each URL, and then post
        # the test results back to CKAN.
        before = datetime.datetime.utcnow()
        deadoralive.deadoralive.main("--url {0} --apikey {1}".format(ckan_url, user["apikey"]).split())
        after = datetime.datetime.utcnow()

        # Now check that the links were checked and the correct results were
        # saved in ckanext-deadoralive's database table.

        # First check the two resources with working links.
        for resource in (resource_1, resource_3):
            result = helpers.call_action("ckanext_deadoralive_get", resource_id=resource["id"])
            assert result["resource_id"] == resource["id"]
            assert result["alive"] is True
            last_checked = datetime.datetime.strptime(result["last_checked"], "%Y-%m-%dT%H:%M:%S.%f")
            assert last_checked > before
            assert last_checked < after
            last_successful = datetime.datetime.strptime(result["last_successful"], "%Y-%m-%dT%H:%M:%S.%f")
            assert last_successful > before
            assert last_successful < after
            assert result["num_fails"] == 0
            assert result["pending"] is False
            assert result["pending_since"] is None
            assert result["status"] == 200
            assert result["reason"] == "OK"

        # Now check the expected result for the resource with a broken link.
        result = helpers.call_action("ckanext_deadoralive_get", resource_id=resource_2["id"])
        assert result["resource_id"] == resource_2["id"]
        assert result["alive"] is False
        last_checked = datetime.datetime.strptime(result["last_checked"], "%Y-%m-%dT%H:%M:%S.%f")
        assert last_checked > before
        assert last_checked < after
        assert result["last_successful"] is None
        assert result["num_fails"] == 1
        assert result["pending"] is False
        assert result["pending_since"] is None
        assert result["status"] == 500
        assert result["reason"] == "Internal Server Error"
    def test(self):
        """Test that deadoralive and ckanext-deadoralive work together.

        Add some resources with working and some with broken links to CKAN,
        run deadoralive, check that it added the right results.

        """
        results.create_database_table()

        user = factories.User()

        # FunctionalTestBaseClass has already made self.app for us, but we
        # need one with our authorized_users config setting in it so replace it
        # with our own.
        config["ckanext.deadoralive.authorized_users"] = user["name"]
        self.app = custom_helpers._get_test_app()

        # The URL of the CKAN site we'll be using.
        # We'll be mocking the URLs on this domain that we expect to be sending
        # requests to.
        ckan_url = "http://test.ckan.org"

        # Mock some working and some broken resource URLs.
        # We'll create resources with these URLs in CKAN below.
        url_1 = "http://demo.ckan.org/url_1"
        httpretty.register_uri(httpretty.GET, url_1, status=200),
        url_2 = "http://demo.ckan.org/url_2"
        httpretty.register_uri(httpretty.GET, url_2, status=500),
        url_3 = "http://demo.ckan.org/url_3"
        httpretty.register_uri(httpretty.GET, url_3, status=200),

        # We're also going to mock the CKAN API URLs that deadoralive will be
        # requesting. We'll catch these requests and then forward them to a CKAN
        # test app.
        # FIXME: It would be nice if we could just mock http://test.ckan.org/*
        # and forward all requests on to the test app, but I don't think
        # httpretty supports this.
        get_resource_ids_url = (ckan_url +
                                "/deadoralive/get_resources_to_check")
        httpretty.register_uri(httpretty.GET,
                               get_resource_ids_url,
                               body=self._forward_to_test_app)
        httpretty.register_uri(httpretty.POST,
                               get_resource_ids_url,
                               body=self._forward_to_test_app)

        get_url_for_id_url = ckan_url + "/deadoralive/get_url_for_resource_id"
        httpretty.register_uri(httpretty.GET,
                               get_url_for_id_url,
                               body=self._forward_to_test_app)
        httpretty.register_uri(httpretty.POST,
                               get_url_for_id_url,
                               body=self._forward_to_test_app)

        upsert_result_url = ckan_url + "/deadoralive/upsert"
        httpretty.register_uri(httpretty.GET,
                               upsert_result_url,
                               body=self._forward_to_test_app)
        httpretty.register_uri(httpretty.POST,
                               upsert_result_url,
                               body=self._forward_to_test_app)

        # Create the resources in CKAN whose links will be checked.
        resource_1 = custom_factories.Resource(url=url_1)
        resource_2 = custom_factories.Resource(url=url_2)
        resource_3 = custom_factories.Resource(url=url_3)

        # Call deadoralive: It should get the IDs of the three resources from
        # CKAN.  get each resource's URL from CKAN, test each URL, and then post
        # the test results back to CKAN.
        before = datetime.datetime.utcnow()
        deadoralive.deadoralive.main("--url {0} --apikey {1}".format(
            ckan_url, user["apikey"]).split())
        after = datetime.datetime.utcnow()

        # Now check that the links were checked and the correct results were
        # saved in ckanext-deadoralive's database table.

        # First check the two resources with working links.
        for resource in (resource_1, resource_3):
            result = helpers.call_action("ckanext_deadoralive_get",
                                         resource_id=resource["id"])
            assert result["resource_id"] == resource["id"]
            assert result["alive"] is True
            last_checked = datetime.datetime.strptime(result["last_checked"],
                                                      "%Y-%m-%dT%H:%M:%S.%f")
            assert last_checked > before
            assert last_checked < after
            last_successful = datetime.datetime.strptime(
                result["last_successful"], "%Y-%m-%dT%H:%M:%S.%f")
            assert last_successful > before
            assert last_successful < after
            assert result["num_fails"] == 0
            assert result["pending"] is False
            assert result["pending_since"] is None
            assert result["status"] == 200
            assert result["reason"] == "OK"

        # Now check the expected result for the resource with a broken link.
        result = helpers.call_action("ckanext_deadoralive_get",
                                     resource_id=resource_2["id"])
        assert result["resource_id"] == resource_2["id"]
        assert result["alive"] is False
        last_checked = datetime.datetime.strptime(result["last_checked"],
                                                  "%Y-%m-%dT%H:%M:%S.%f")
        assert last_checked > before
        assert last_checked < after
        assert result["last_successful"] is None
        assert result["num_fails"] == 1
        assert result["pending"] is False
        assert result["pending_since"] is None
        assert result["status"] == 500
        assert result["reason"] == "Internal Server Error"
예제 #6
0
 def setup(self):
     import ckan.model as model
     model.Session.close_all()
     model.repo.rebuild_db()
     results.create_database_table()
예제 #7
0
 def setup(self):
     results.create_database_table()
     helpers.reset_db()