def test_mix_of_broken_and_working_links(self):
        user = factories.User()
        config.authorized_users = [user["name"]]

        maintainer_1 = "*****@*****.**"
        dataset_1 = custom_factories.Dataset(
            maintainer_email=maintainer_1)
        resource_1 = custom_factories.Resource(package_id=dataset_1["id"])
        dataset_2 = custom_factories.Dataset(
            maintainer_email=maintainer_1)
        resource_2 = custom_factories.Resource(package_id=dataset_2["id"])

        maintainer_2 = "*****@*****.**"
        dataset_3 = custom_factories.Dataset(
            maintainer_email=maintainer_2)
        resource_3 = custom_factories.Resource(package_id=dataset_3["id"])
        resource_4 = custom_factories.Resource(package_id=dataset_3["id"])

        maintainer_3 = "*****@*****.**"
        dataset_4 = custom_factories.Dataset(
            maintainer_email=maintainer_3)
        resource_5 = custom_factories.Resource(package_id=dataset_4["id"])
        dataset_5 = custom_factories.Dataset(
            maintainer_email=maintainer_3)
        resource_6 = custom_factories.Resource(package_id=dataset_5["id"])
        resource_7 = custom_factories.Resource(package_id=dataset_5["id"])
        resource_8 = custom_factories.Resource(package_id=dataset_5["id"])

        custom_helpers.make_broken((resource_1, resource_3, resource_4,
                                    resource_5, resource_6, resource_7), user)
        custom_helpers.make_working((resource_2, resource_8), user)

        report = helpers.call_action(
            "ckanext_deadoralive_broken_links_by_email")

        assert len(report) == 3, ("There should be 3 emails listed in the "
                                  "report")

        assert [item["email"] for item in report] == [
            maintainer_3, maintainer_2, maintainer_1], (
                "The items should be sorted most broken datasets first")

        # Check that the num_broken_links for each item is correct.
        assert report[0]["num_broken_links"] == 3
        assert report[1]["num_broken_links"] == 2
        assert report[2]["num_broken_links"] == 1

        # Check maintainer_3's report in detail.
        maintainer_3_report = report[0]
        assert len(maintainer_3_report["datasets_with_broken_links"]) == 2
        broken_datasets = maintainer_3_report["datasets_with_broken_links"]
        assert [dataset["name"] for dataset in broken_datasets] == [
            dataset_5["name"], dataset_4["name"]]
        dataset_5_report = broken_datasets[0]
        assert dataset_5_report["num_broken_links"] == 2
        assert len(dataset_5_report["resources_with_broken_links"]) == 2
        assert [resource_id for resource_id
                in dataset_5_report["resources_with_broken_links"]] == [
                    resource_6["id"], resource_7["id"]]
    def test_mix_of_broken_and_working_links(self):
        user = factories.User()
        config.authorized_users = [user["name"]]

        org_1 = factories.Organization()
        dataset_1 = custom_factories.Dataset(owner_org=org_1["id"])
        dataset_2 = custom_factories.Dataset(owner_org=org_1["id"])
        resource_1 = custom_factories.Resource(package_id=dataset_1["id"])
        resource_2 = custom_factories.Resource(package_id=dataset_2["id"])

        org_2 = factories.Organization()
        dataset_3 = custom_factories.Dataset(owner_org=org_2["id"])
        resource_3 = custom_factories.Resource(package_id=dataset_3["id"])
        resource_4 = custom_factories.Resource(package_id=dataset_3["id"])

        org_3 = factories.Organization()
        dataset_4 = custom_factories.Dataset(owner_org=org_3["id"])
        resource_5 = custom_factories.Resource(package_id=dataset_4["id"])
        dataset_5 = custom_factories.Dataset(owner_org=org_3["id"])
        resource_6 = custom_factories.Resource(package_id=dataset_5["id"])
        resource_7 = custom_factories.Resource(package_id=dataset_5["id"])
        resource_8 = custom_factories.Resource(package_id=dataset_5["id"])

        custom_helpers.make_broken((resource_1, resource_3, resource_4,
                                    resource_5, resource_6, resource_7), user)
        custom_helpers.make_working((resource_2, resource_8), user)

        report = helpers.call_action(
            "ckanext_deadoralive_broken_links_by_organization")

        assert len(report) == 3, ("There should be 3 organizations listed in "
                                  "the report")

        assert [org["name"] for org in report] == [
            org_3["name"], org_2["name"], org_1["name"]
        ], ("The organizations should be sorted most broken datasets first")

        # Check that the num_broken_links for each org is correct.
        assert report[0]["num_broken_links"] == 3
        assert report[1]["num_broken_links"] == 2
        assert report[2]["num_broken_links"] == 1

        # Check org_3's report in detail.
        org_3_report = report[0]
        assert len(org_3_report["datasets_with_broken_links"]) == 2
        org_3_broken_datasets = org_3_report["datasets_with_broken_links"]
        assert [dataset["name"] for dataset in org_3_broken_datasets
                ] == [dataset_5["name"], dataset_4["name"]]
        dataset_5_report = org_3_broken_datasets[0]
        assert dataset_5_report["num_broken_links"] == 2
        assert len(dataset_5_report["resources_with_broken_links"]) == 2
        assert [
            resource_id
            for resource_id in dataset_5_report["resources_with_broken_links"]
        ] == [resource_6["id"], resource_7["id"]]
Exemple #3
0
    def test_mix_of_broken_and_working_links(self):
        user = factories.User()
        config.authorized_users = [user["name"]]

        org_1 = factories.Organization()
        dataset_1 = custom_factories.Dataset(owner_org=org_1["id"])
        dataset_2 = custom_factories.Dataset(owner_org=org_1["id"])
        resource_1 = custom_factories.Resource(package_id=dataset_1["id"])
        resource_2 = custom_factories.Resource(package_id=dataset_2["id"])

        org_2 = factories.Organization()
        dataset_3 = custom_factories.Dataset(owner_org=org_2["id"])
        resource_3 = custom_factories.Resource(package_id=dataset_3["id"])
        resource_4 = custom_factories.Resource(package_id=dataset_3["id"])

        org_3 = factories.Organization()
        dataset_4 = custom_factories.Dataset(owner_org=org_3["id"])
        resource_5 = custom_factories.Resource(package_id=dataset_4["id"])
        dataset_5 = custom_factories.Dataset(owner_org=org_3["id"])
        resource_6 = custom_factories.Resource(package_id=dataset_5["id"])
        resource_7 = custom_factories.Resource(package_id=dataset_5["id"])
        resource_8 = custom_factories.Resource(package_id=dataset_5["id"])

        custom_helpers.make_broken((resource_1, resource_3, resource_4,
                                    resource_5, resource_6, resource_7),
                                   user)
        custom_helpers.make_working((resource_2, resource_8), user)

        report = helpers.call_action(
            "ckanext_deadoralive_broken_links_by_organization")

        assert len(report) == 3, ("There should be 3 organizations listed in "
                                  "the report")

        assert [org["name"] for org in report] == [
            org_3["name"], org_2["name"], org_1["name"]], (
                "The organizations should be sorted most broken datasets first")

        # Check that the num_broken_links for each org is correct.
        assert report[0]["num_broken_links"] == 3
        assert report[1]["num_broken_links"] == 2
        assert report[2]["num_broken_links"] == 1

        # Check org_3's report in detail.
        org_3_report = report[0]
        assert len(org_3_report["datasets_with_broken_links"]) == 2
        org_3_broken_datasets = org_3_report["datasets_with_broken_links"]
        assert [dataset["name"] for dataset in org_3_broken_datasets] == [
            dataset_5["name"], dataset_4["name"]]
        dataset_5_report = org_3_broken_datasets[0]
        assert dataset_5_report["num_broken_links"] == 2
        assert len(dataset_5_report["resources_with_broken_links"]) == 2
        assert [resource_id for resource_id
                in dataset_5_report["resources_with_broken_links"]] == [
                    resource_6["id"], resource_7["id"]]
    def test_broken_links_by_email(self):
        sysadmin = custom_factories.Sysadmin()
        extra_environ = {'REMOTE_USER': str(sysadmin["name"])}

        maintainer_1 = "*****@*****.**"
        dataset_1 = custom_factories.Dataset(
            maintainer_email=maintainer_1)
        resource_1 = custom_factories.Resource(package_id=dataset_1["id"])
        dataset_2 = custom_factories.Dataset(
            maintainer_email=maintainer_1)
        resource_2 = custom_factories.Resource(package_id=dataset_2["id"])

        maintainer_2 = "*****@*****.**"
        dataset_3 = custom_factories.Dataset(
            maintainer_email=maintainer_2)
        resource_3 = custom_factories.Resource(package_id=dataset_3["id"])
        resource_4 = custom_factories.Resource(package_id=dataset_3["id"])

        maintainer_3 = "*****@*****.**"
        dataset_4 = custom_factories.Dataset(
            maintainer_email=maintainer_3)
        resource_5 = custom_factories.Resource(package_id=dataset_4["id"])
        dataset_5 = custom_factories.Dataset(
            maintainer_email=maintainer_3)
        resource_6 = custom_factories.Resource(package_id=dataset_5["id"])
        resource_7 = custom_factories.Resource(package_id=dataset_5["id"])
        resource_8 = custom_factories.Resource(package_id=dataset_5["id"])

        custom_helpers.make_broken((resource_1, resource_3, resource_4,
                                    resource_5, resource_6, resource_7),
                                   user=sysadmin)
        custom_helpers.make_working((resource_2, resource_8), user=sysadmin)

        response = self.app.get("/ckan-admin/broken_links",
                                extra_environ=extra_environ)

        assert maintainer_1 in response
        assert maintainer_2 in response
        assert maintainer_3 in response
        assert dataset_1["name"] in response
        assert dataset_2["name"] not in response
        assert dataset_3["name"] in response
        assert dataset_4["name"] in response
        assert dataset_5["name"] in response
Exemple #5
0
    def test_broken_links_by_email(self):
        sysadmin = custom_factories.Sysadmin()
        extra_environ = {'REMOTE_USER': str(sysadmin["name"])}

        maintainer_1 = "*****@*****.**"
        dataset_1 = custom_factories.Dataset(maintainer_email=maintainer_1)
        resource_1 = custom_factories.Resource(package_id=dataset_1["id"])
        dataset_2 = custom_factories.Dataset(maintainer_email=maintainer_1)
        resource_2 = custom_factories.Resource(package_id=dataset_2["id"])

        maintainer_2 = "*****@*****.**"
        dataset_3 = custom_factories.Dataset(maintainer_email=maintainer_2)
        resource_3 = custom_factories.Resource(package_id=dataset_3["id"])
        resource_4 = custom_factories.Resource(package_id=dataset_3["id"])

        maintainer_3 = "*****@*****.**"
        dataset_4 = custom_factories.Dataset(maintainer_email=maintainer_3)
        resource_5 = custom_factories.Resource(package_id=dataset_4["id"])
        dataset_5 = custom_factories.Dataset(maintainer_email=maintainer_3)
        resource_6 = custom_factories.Resource(package_id=dataset_5["id"])
        resource_7 = custom_factories.Resource(package_id=dataset_5["id"])
        resource_8 = custom_factories.Resource(package_id=dataset_5["id"])

        custom_helpers.make_broken((resource_1, resource_3, resource_4,
                                    resource_5, resource_6, resource_7),
                                   user=sysadmin)
        custom_helpers.make_working((resource_2, resource_8), user=sysadmin)

        response = self.app.get("/ckan-admin/broken_links",
                                extra_environ=extra_environ)

        assert maintainer_1 in response
        assert maintainer_2 in response
        assert maintainer_3 in response
        assert dataset_1["name"] in response
        assert dataset_2["name"] not in response
        assert dataset_3["name"] in response
        assert dataset_4["name"] in response
        assert dataset_5["name"] in response
    def test_broken_links_by_organization(self):
        user = factories.User()
        config.authorized_users = [user["name"]]

        org_1 = factories.Organization()
        dataset_1 = custom_factories.Dataset(owner_org=org_1["id"])
        dataset_2 = custom_factories.Dataset(owner_org=org_1["id"])
        resource_1 = custom_factories.Resource(package_id=dataset_1["id"])
        resource_2 = custom_factories.Resource(package_id=dataset_2["id"])

        org_2 = factories.Organization()
        dataset_3 = custom_factories.Dataset(owner_org=org_2["id"])
        resource_3 = custom_factories.Resource(package_id=dataset_3["id"])
        resource_4 = custom_factories.Resource(package_id=dataset_3["id"])

        org_3 = factories.Organization()
        dataset_4 = custom_factories.Dataset(owner_org=org_3["id"])
        resource_5 = custom_factories.Resource(package_id=dataset_4["id"])
        dataset_5 = custom_factories.Dataset(owner_org=org_3["id"])
        resource_6 = custom_factories.Resource(package_id=dataset_5["id"])
        resource_7 = custom_factories.Resource(package_id=dataset_5["id"])
        resource_8 = custom_factories.Resource(package_id=dataset_5["id"])

        custom_helpers.make_broken((resource_1, resource_3, resource_4,
                                    resource_5, resource_6, resource_7),
                                   user=user)
        custom_helpers.make_working((resource_2, resource_8), user=user)

        response = self.app.get("/organization/broken_links")

        assert org_1["name"] in response
        assert org_2["name"] in response
        assert org_3["name"] in response
        assert dataset_1["name"] in response
        assert dataset_2["name"] not in response
        assert dataset_3["name"] in response
        assert dataset_4["name"] in response
        assert dataset_5["name"] in response
Exemple #7
0
    def test_broken_links_by_organization(self):
        user = factories.User()
        config.authorized_users = [user["name"]]

        org_1 = factories.Organization()
        dataset_1 = custom_factories.Dataset(owner_org=org_1["id"])
        dataset_2 = custom_factories.Dataset(owner_org=org_1["id"])
        resource_1 = custom_factories.Resource(package_id=dataset_1["id"])
        resource_2 = custom_factories.Resource(package_id=dataset_2["id"])

        org_2 = factories.Organization()
        dataset_3 = custom_factories.Dataset(owner_org=org_2["id"])
        resource_3 = custom_factories.Resource(package_id=dataset_3["id"])
        resource_4 = custom_factories.Resource(package_id=dataset_3["id"])

        org_3 = factories.Organization()
        dataset_4 = custom_factories.Dataset(owner_org=org_3["id"])
        resource_5 = custom_factories.Resource(package_id=dataset_4["id"])
        dataset_5 = custom_factories.Dataset(owner_org=org_3["id"])
        resource_6 = custom_factories.Resource(package_id=dataset_5["id"])
        resource_7 = custom_factories.Resource(package_id=dataset_5["id"])
        resource_8 = custom_factories.Resource(package_id=dataset_5["id"])

        custom_helpers.make_broken((resource_1, resource_3, resource_4,
                                    resource_5, resource_6, resource_7),
                                   user=user)
        custom_helpers.make_working((resource_2, resource_8), user=user)

        response = self.app.get("/organization/broken_links")

        assert org_1["name"] in response
        assert org_2["name"] in response
        assert org_3["name"] in response
        assert dataset_1["name"] in response
        assert dataset_2["name"] not in response
        assert dataset_3["name"] in response
        assert dataset_4["name"] in response
        assert dataset_5["name"] in response