Ejemplo n.º 1
0
 def test_2_parameter(self):
     assert_equal(extension_variants('http://dept.gov.uk/coins-data-1996.csv?callback=1'),
                  ['csv'])
Ejemplo n.º 2
0
 def test_3_none(self):
     assert_equal(extension_variants('http://dept.gov.uk/coins-data-1996'),
                  [])
Ejemplo n.º 3
0
 def test_0_normal(self):
     assert_equal(extension_variants('http://dept.gov.uk/coins-data-1996.csv'),
                  ['csv'])
Ejemplo n.º 4
0
 def test_1_multiple(self):
     assert_equal(extension_variants('http://dept.gov.uk/coins.data.1996.csv.zip'),
                  ['csv.zip', 'zip'])
Ejemplo n.º 5
0
 def test_3_none(self):
     assert_equal(extension_variants('http://dept.gov.uk/coins-data-1996'),
                  [])
Ejemplo n.º 6
0
 def test_2_parameter(self):
     assert_equal(
         extension_variants(
             'http://dept.gov.uk/coins-data-1996.csv?callback=1'), ['csv'])
Ejemplo n.º 7
0
 def test_1_multiple(self):
     assert_equal(
         extension_variants('http://dept.gov.uk/coins.data.1996.csv.zip'),
         ['csv.zip', 'zip'])
Ejemplo n.º 8
0
 def test_0_normal(self):
     assert_equal(
         extension_variants('http://dept.gov.uk/coins-data-1996.csv'),
         ['csv'])
Ejemplo n.º 9
0
    def custom_resource_score(self, resource, resource_score):
        resource_score_format = resource_score.get('format').upper(
        ) if resource_score.get('format') is not None else ''
        resource_format = resource.format.upper(
        ) if resource.format is not None else ''
        # If resource openness_score is 3 and format is CSV
        if resource_score.get('openness_score',
                              0) == 3 and resource_score_format == 'CSV':
            # If resource has a JSON schema which validated successfully, set score to 4
            if hasattr(resource, 'extras') and resource.extras.get(
                    'schema', None) and resource.extras.get(
                        'validation_status', '').lower() == 'success':
                resource_score['openness_score'] = 4
                resource_score['openness_score_reason'] = toolkit._(
                    'Content of file appeared to be format "{0}" which receives openness score: {1}.'
                    .format(resource_score_format,
                            resource_score.get('openness_score', '')))

        if resource_score.get('openness_score', 0) > 0:
            # QA cannot determine file formats that are not part of its own
            # 'resource_format_openness_scores.json' file and CKAN resource_formats.json file
            # The below are dataqld specific file formats that are not part of the default
            # CKAN resource_formats.json file and need custom scoring

            # If QA believes the resource is a TIFF file, check the resource format selected,
            # if it's GEOTIFF apply custom score
            if resource_score_format == 'TIFF' and resource_format == 'GEOTIFF':
                resource_score['openness_score'] = resource_score[
                    'openness_score'] = qa_lib.resource_format_scores().get(
                        resource_format)
                resource_score['openness_score_reason'] = toolkit._(
                    'Content of file appeared to be format "{0}" which receives openness score: {1}.'
                    .format(resource_format,
                            resource_score.get('openness_score', '')))

            # If QA believes the resource is a ZIP file, check the resource format selected,
            # if it's GDB apply custom score
            if resource_score_format == 'ZIP' and 'GDB' in resource_format:
                resource_score['format'] = 'GDB'
                resource_score[
                    'openness_score'] = qa_lib.resource_format_scores().get(
                        resource_score['format'])
                resource_score['openness_score_reason'] = toolkit._(
                    'Content of file appeared to be format "{0}" which receives openness score: {1}.'
                    .format(resource_format,
                            resource_score.get('openness_score', '')))

            # QA by default does not know how to handle GPKG formats, check the
            # resource format selected and extension, if it's GPKG apply custom score
            if 'GPKG' in resource_format:
                if resource.url_type == 'upload' and 'GPKG' in os.path.splitext(resource.url)[1].upper() \
                        or resource.url_type == 'url' and 'GPKG' in (ext.upper() for ext in
                                                                     qa_tasks.extension_variants(resource.url)):
                    resource_score['format'] = 'GPKG'
                    resource_score[
                        'openness_score'] = qa_lib.resource_format_scores(
                        ).get(resource_score['format'])
                    resource_score['openness_score_reason'] = toolkit._(
                        'Content of file appeared to be format "{0}" which receives openness score: {1}.'
                        .format(resource_format,
                                resource_score.get('openness_score', '')))

        return resource_score