Example #1
0
def test_html_get_links(mockRequest):
    sampleFile = open(os.path.join('tests', 'samples', 'schema_index_sample.html'), 'rb')
    expected_links = ['http://www.dmtf.org/standards/redfish',
                      'https://testing.mock/schemas/AccountService.v1_3_0.json',
                      'https://testing.mock/schemas/AccountService_v1.xml',
                      'https://testing.mock/schemas/ActionInfo.v1_0_3.json',
                      'https://testing.mock/schemas/ActionInfo_v1.xml']
    mockRequest.urlopen.return_value = sampleFile
    links = DocGenUtilities.html_get_links("https://testing.mock/foo.html");
    links.sort()
    assert links == expected_links
def test_html_get_links(mockRequest):
    sampleFile = open(
        os.path.join('tests', 'samples', 'schema_index_sample.html'), 'rb')
    expected_links = [
        'http://www.dmtf.org/standards/redfish',
        'https://testing.mock/schemas/AccountService.v1_3_0.json',
        'https://testing.mock/schemas/AccountService_v1.xml',
        'https://testing.mock/schemas/ActionInfo.v1_0_3.json',
        'https://testing.mock/schemas/ActionInfo_v1.xml'
    ]
    mockRequest.urlopen.return_value = sampleFile
    links = DocGenUtilities.html_get_links("https://testing.mock/foo.html")
    links.sort()
    assert links == expected_links
    def get_versioned_uri(self,
                          base_name,
                          repo,
                          min_version,
                          is_local_file=False):
        """ Get a versioned URI for the base_name schema.
        Parameters:
         base_name     -- Base name of the schema, e.g., "Resource"
         repo          -- URI of the the repo where the schema is expected to be found.
         min_version   -- Minimum acceptable version.
         is_local_file -- Find file on local system.

        If a matching URI is found among links at the repo address, it will be returned.
        If not, a URI will be composed based on repo, base_name, and version. (This
        may succeed if the repo does not provide a directory index.)

        Versions must match on the major version, with minor.errata equal to or greater than
        what is specified in min_version.
        """

        versioned_uri = None

        if is_local_file:
            repo_links = DocGenUtilities.local_get_links(repo)
        else:
            repo_links = DocGenUtilities.html_get_links(repo)

        if repo_links:
            minversion_parts = re.findall('(\d+)', min_version)

            candidate = None
            candidate_strength = 0
            for rl in repo_links:
                base = base_name + '.'
                if rl.startswith(repo) and base in rl and rl.endswith('.json'):
                    parts = rl[0:-5].rsplit(base, 1)
                    if len(parts) == 2:
                        suffix = parts[1]
                        version_parts = re.findall('(\d+)', suffix)
                        # Major version must match; minor.errata must be >=.
                        if version_parts[0] != minversion_parts[0]:
                            continue
                        if version_parts[1] > minversion_parts[1]:
                            strength = self.version_index(version_parts)
                            if strength > candidate_strength:
                                candidate_strength = strength
                                candidate = rl
                            continue
                        if version_parts[1] == minversion_parts[1]:
                            if len(version_parts) == 3 and len(
                                    minversion_parts) == 3:
                                if version_parts[2] >= minversion_parts[2]:
                                    strength = self.version_index(
                                        version_parts)
                                    if strength > candidate_strength:
                                        candidate_strength = strength
                                        candidate = rl
                            elif len(version_parts) == 2:
                                strength = self.version_index(version_parts)
                                if strength > candidate_strength:
                                    candidate_strength = strength
                                    candidate = rl
            if candidate:
                versioned_uri = candidate

        elif is_local_file:
            # Build URI from repo, name, and minversion:
            versioned_uri = '/'.join([repo, base_name
                                      ]) + '.v' + min_version + '.json'

        return versioned_uri