def test_03_resource_and_result(self):
        global CURRENT_REQUEST

        # go through each file and result object
        for path, comparison in RESOURCE_AND_RESULT.iteritems():
            # construct a request object, using the provenance/source url as the provider url
            record = {}
            record["bibjson"] = {}
            record["provider"] = {}
            record["provider"]["url"] = [comparison["provenance"]["source"]]
            record = models.MessageObject(record=record)

            # set the current request so that the monkey patch knows how to respond
            CURRENT_REQUEST = comparison["provenance"]["source"]

            # run the plugin
            p = MyPlugin()
            p.license_detect(record)

            record = record.record

            # check if all the top-level keys were created
            assert "bibjson" in record
            assert "license" in record["bibjson"]
            assert record["bibjson"]["license"] is not None
            assert len(record["bibjson"]["license"]) == 1  # only 1
            # license was detected

            # The rules for the comparison licence object are:
            # - if a key has a value, there resulting object's value must match exactly
            # - if a key has been omitted, it will not be tested
            # - if a key's value is the empty string, the resulting object's key's value must be the empty string
            # - if a key's value is None, the resulting object MUST NOT have the key or MUST be the empty string
            # - if a key's value is -1, the resulting object MUST have the key
            licence = record["bibjson"]["license"][0]
            for key, value in comparison.iteritems():
                if key == "provenance":
                    # for better layout of code, let's do provenance separately
                    continue
                if value is None:
                    # the resulting object MUST NOT have the key or MUST be the empty string
                    assert key not in licence or licence.get(key) == "", ((key, value), licence.get(key))
                elif value == -1:
                    # the resulting object MUST have the key
                    assert key in licence, ((key, value), licence.get(key))
                else:
                    # the resulting object must match the comparison object
                    assert value == licence.get(key), ((key, value), licence.get(key))

            prov = licence.get("provenance", {})
            for key, value in comparison.get("provenance", {}).iteritems():
                if value is None:
                    # the resulting object MUST NOT have the key
                    assert key not in prov or prov.get(key) == "", ((key, value), prov.get(key))
                elif value == -1:
                    # the resulting object MUST have the key
                    assert key in prov, ((key, value), prov.get(key))
                else:
                    # the resulting object must match the comparison object
                    assert value == prov.get(key), ((key, value), prov.get(key))
 def test_02_supports_fail(self):
     p = MyPlugin()
     for url in UNSUPPORTED_URLS:
         assert not p.supports({"url": [url]})
 def test_01_supports_success(self):
     p = MyPlugin()
     for url in SUPPORTED_URLS:
         assert p.supports({"url": [url]})