예제 #1
0
    def test_05_name_and_version(self):
        """
        Take an example supported article and check just the handler fields
        """
        bmc = BMCPlugin()
        
        record = {}
        record['bibjson'] = {}
        record['provider'] = {}
        record['provider']['url'] = ['http://www.biomedcentral.com/1471-2164/13/425']
        record = models.MessageObject(record=record)

        bmc.license_detect(record)
        
        # for convenience, unwrap the record
        record = record.record
        
        # just barebones checks to make sure the license and provenance objects
        # exist in the first place so the handler fields can be checked
        assert record['bibjson'].has_key('license')
        assert record['bibjson']['license']

        assert 'provenance' in record['bibjson']['license'][-1]

        assert 'handler' in record['bibjson']['license'][-1]['provenance']
        assert record['bibjson']['license'][-1]['provenance']['handler'] == 'bmc'
        assert record['bibjson']['license'][-1]['provenance']['handler_version'] == '0.1'
    def test_06_bmc_standard_OA_license(self):
        record = {}
        record['bibjson'] = {}
        record['provider'] = {}
        
        # TUTORIAL
        # Again, you must provide a dereferenced URL here - that's what your
        # plugin will get!
        record['provider']['url'] = ['http://www.biomedcentral.com/1471-2164/13/425']

        bmc = BMCPlugin()
        bmc.license_detect(record)

        # check if all the important keys were created
        
        # TUTORIAL: You don't need to modify any of these
        assert record['bibjson'].has_key('license')
        assert record['bibjson']['license']

        # NB: some examples may fail the 'url' test since the Open Definition
        # data we're using as the basis for our licenses dictionary does not
        # have 'url' for all licenses. Fix by modifying licenses.py - add the data.
        assert all (key in record['bibjson']['license'][-1] for key in keys_in_license)

        assert all (key in record['bibjson']['license'][-1]['provenance'] for key in keys_in_provenance)

        # some content checks now
        # TUTORIAL: this is what you need to modify to make sure your plugin is
        # recording the right data. Essentially this should match whatever you put
        # into lic_statements in the plugin code and whatever you're expecting
        # for this particular resource.
        assert record['bibjson']['license'][-1]['type'] == 'cc-by'
        assert record['bibjson']['license'][-1]['version'] == '2.0'
        assert 'id' not in record['bibjson']['license'][-1] # should not have "id" - due to bibserver
        assert not record['bibjson']['license'][-1]['jurisdiction']
        assert record['bibjson']['license'][-1]['open_access']
        assert record['bibjson']['license'][-1]['BY']
        assert not record['bibjson']['license'][-1]['NC']
        assert not record['bibjson']['license'][-1]['SA']
        assert not record['bibjson']['license'][-1]['ND']
        # In this case we also expect the plugin to overwrite the ['license']['url']
        # property with a more specific one from the license statement.
        assert record['bibjson']['license'][-1]['url'] == 'http://creativecommons.org/licenses/by/2.0'

        # TUTORIAL: you don't need to touch the following tests, EXCEPT for
        # the last one - the human-readable provenance description.
        assert record['bibjson']['license'][-1]['provenance']['agent'] == config.agent
        assert record['bibjson']['license'][-1]['provenance']['source'] == record['provider']['url'][0]
        assert record['bibjson']['license'][-1]['provenance']['date']
        assert record['bibjson']['license'][-1]['provenance']['category'] == 'page_scrape'

        # TUTORIAL: This is what you need to change - this is the license
        # statement from lic_statements that you expect to have been present
        # on this resource's page.
        lic_statement = 'This is an Open Access article distributed under the terms of the Creative Commons Attribution License (<a href=\'http://creativecommons.org/licenses/by/2.0\'>http://creativecommons.org/licenses/by/2.0</a>), which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.' \
        
        # TUTORIAL: this is essentially some boilerplate text that you should not change
        assert record['bibjson']['license'][-1]['provenance']['description'] == 'License decided by scraping the resource at ' + record['provider']['url'][0] + ' and looking for the following license statement: "' + lic_statement + '".'
예제 #3
0
    def test_07_unknown(self):
        old_get = requests.get
        requests.get = get_unknown
        bmc = BMCPlugin()
        
        record = {}
        record['bibjson'] = {}
        record['provider'] = {}
        record['provider']['url'] = ['http://unknown']
        
        bmc.license_detect(record)

        # check if all the important keys were created
        assert "license" not in record['bibjson']
        
        requests.get = old_get
예제 #4
0
    def test_06_bmc_standard_OA_license3(self):
    	# Same as top but with 'credited' instead of cited
        bmc = BMCPlugin()
        
        record = {}
        record['bibjson'] = {}
        record['provider'] = {}
        record['provider']['url'] = ['http://www.ijbnpa.org/content/11/1/34']
        record = models.MessageObject(record=record)
        
        bmc.license_detect(record)
        
        record = record.record
        
        # check if all the important keys were created
        assert record['bibjson'].has_key('license')
        assert record['bibjson']['license']

        # NB: some examples may fail the 'url' test since the Open Definition
        # data we're using as the basis for our licenses dictionary does not
        # have 'url' for all licenses. Fix by modifying licenses.py - add the data.
        assert all (key in record['bibjson']['license'][-1] for key in keys_in_license)

        assert all (key in record['bibjson']['license'][-1]['provenance'] for key in keys_in_provenance)

        # some content checks now
        assert record['bibjson']['license'][-1]['type'] == 'cc-by'
        assert record['bibjson']['license'][-1]['version'] == '2.0'
        assert 'id' not in record['bibjson']['license'][-1] # should not have "id" - due to bibserver
        assert not record['bibjson']['license'][-1]['jurisdiction']
        assert record['bibjson']['license'][-1]['open_access']
        assert record['bibjson']['license'][-1]['BY']
        assert not record['bibjson']['license'][-1]['NC']
        assert not record['bibjson']['license'][-1]['SA']
        assert not record['bibjson']['license'][-1]['ND']
        # In this case we also expect the BMC plugin to overwrite the ['license']['url']
        # property with a more specific one from the license statement.
        assert record['bibjson']['license'][-1]['url'] == 'http://creativecommons.org/licenses/by/2.0'

        assert record['bibjson']['license'][-1]['provenance']['agent'] == config.agent
        assert record['bibjson']['license'][-1]['provenance']['source'] == record['provider']['url'][0]
        assert record['bibjson']['license'][-1]['provenance']['date']
        assert record['bibjson']['license'][-1]['provenance']['category'] == 'page_scrape'
        assert record['bibjson']['license'][-1]['provenance']['description'] == 'License decided by scraping the resource at http://www.biomedcentral.com/1471-2164/13/425 and looking for the following license statement: "This is an Open Access article distributed under the terms of the Creative Commons Attribution License (<a href=\'http://creativecommons.org/licenses/by/2.0\'>http://creativecommons.org/licenses/by/2.0</a>), which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly credited.".'    
    def test_05_name_and_version(self):
        """
        Take an example supported article and check just the handler fields
        """
        record = {}
        record['bibjson'] = {}
        record['provider'] = {}
        record['provider']['url'] = ['http://www.biomedcentral.com/1471-2164/13/425']
        
        bmc = BMCPlugin()
        bmc.license_detect(record)

        # just barebones checks to make sure the license and provenance objects
        # exist in the first place so the handler fields can be checked
        assert record['bibjson'].has_key('license')
        assert record['bibjson']['license']

        assert 'provenance' in record['bibjson']['license'][-1]

        assert 'handler' in record['bibjson']['license'][-1]['provenance']
        assert record['bibjson']['license'][-1]['provenance']['handler'] == bmc._short_name
        assert record['bibjson']['license'][-1]['provenance']['handler_version'] == bmc.__version__
예제 #6
0
 def test_04_bmc_supports_url_fail(self):
     bmc = BMCPlugin()
     test_urls = ["http://www.plosone.org/", "askjdfsakjdhfsa"]
     for url in test_urls:
         assert not bmc.supports_base_url(url)
예제 #7
0
 def test_03_bmc_supports_url_success(self):
     bmc = BMCPlugin()
     test_urls = ["http://www.biomedcentral.com/983242"]
     for url in test_urls:
         assert bmc.supports_base_url(url)
예제 #8
0
 def test_02_bmc_supports_fail(self):
     bmc = BMCPlugin()
     test_urls = ["http://www.plosone.org/", "askjdfsakjdhfsa"]
     for url in test_urls:
         assert not bmc.supports({"url" : [url]})
예제 #9
0
 def test_01_bmc_supports_success(self):
     bmc = BMCPlugin()
     test_urls = ["http://www.biomedcentral.com/983242"]
     for url in test_urls:
         assert bmc.supports({"url" : [url]})
예제 #10
0
    def __run_resource_and_result_test(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'], 'While testing with ' + path
            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))
예제 #11
0
 def test_02_supports_fail(self):
     p = MyPlugin()
     for url in UNSUPPORTED_URLS:
         assert not p.supports(
             {"url": [url]}), "Failed with URL " + url
예제 #12
0
 def test_01_supports_success(self):
     p = MyPlugin()
     for url in SUPPORTED_URLS:
         assert p.supports({"url": [url]})