Skip to content

Commit

Permalink
Fix code style
Browse files Browse the repository at this point in the history
Signed-off-by: Keshav Priyadarshi <[email protected]>
  • Loading branch information
keshav-space committed Sep 19, 2024
1 parent 550c654 commit e1d9073
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 58 deletions.
10 changes: 2 additions & 8 deletions src/fetchcode/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def get_cocoapods_data_from_purl(purl):
gh_repo_name = name
podspec_api_url = f"https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/{hashed_path}/{name}/{tag}/{name}.podspec.json"
podspec_api_response = get_response(podspec_api_url)
podspec_homepage = podspec_api_response.get('homepage')
podspec_homepage = podspec_api_response.get("homepage")

if podspec_homepage.startswith("https://github.com/"):
podspec_homepage_remove_gh_prefix = podspec_homepage.replace("https://github.com/", "")
Expand All @@ -399,13 +399,7 @@ def get_cocoapods_data_from_purl(purl):
gh_repo_name = podspec_homepage_split[-1]

tag_pkg = construct_cocoapods_package(
version_purl,
name,
hashed_path,
cocoapods_org_url,
gh_repo_owner,
gh_repo_name,
tag
version_purl, name, hashed_path, cocoapods_org_url, gh_repo_owner, gh_repo_name, tag
)

yield tag_pkg
Expand Down
10 changes: 1 addition & 9 deletions src/fetchcode/package_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ def get_package_info(cls, gh_purl, package_name):
IPKG_RELEASES = json.loads((DATA / "ipkg_releases.json").read_text(encoding="UTF-8"))



def get_cocoapod_tags(spec, name):
try:
response = utils.get_text_response(spec)
Expand All @@ -309,13 +308,7 @@ def get_cocoapod_tags(spec, name):


def construct_cocoapods_package(
purl,
name,
hashed_path,
cocoapods_org_url,
gh_repo_owner,
gh_repo_name,
tag
purl, name, hashed_path, cocoapods_org_url, gh_repo_owner, gh_repo_name, tag
):
name = name
homepage_url = None
Expand Down Expand Up @@ -394,4 +387,3 @@ def construct_cocoapods_package(
purl_pkg.version = tag

return purl_pkg

36 changes: 18 additions & 18 deletions src/fetchcode/packagedcode_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,23 +238,23 @@ def purl(self):
).to_string()

repository_homepage_url = String(
label='package repository homepage URL.',
help='URL to the page for this package in its package repository. '
'This is typically different from the package homepage URL proper.'
)
label="package repository homepage URL.",
help="URL to the page for this package in its package repository. "
"This is typically different from the package homepage URL proper.",
)

repository_download_url = String(
label='package repository download URL.',
help='download URL to download the actual archive of code of this '
'package in its package repository. '
'This may be different from the actual download URL.'
)
label="package repository download URL.",
help="download URL to download the actual archive of code of this "
"package in its package repository. "
"This may be different from the actual download URL.",
)

api_data_url = String(
label='package repository API URL.',
help='API URL to obtain structured data for this package such as the '
'URL to a JSON or XML api its package repository.'
)
label="package repository API URL.",
help="API URL to obtain structured data for this package such as the "
"URL to a JSON or XML api its package repository.",
)

def set_purl(self, package_url):
"""
Expand All @@ -279,11 +279,11 @@ def to_dict(self, **kwargs):
Return an OrderedDict of primitive Python types.
"""
mapping = attr.asdict(self, dict_factory=OrderedDict)
if not kwargs.get('exclude_properties'):
mapping['purl'] = self.purl
mapping['repository_homepage_url'] = self.repository_homepage_url
mapping['repository_download_url'] = self.repository_download_url
mapping['api_data_url'] = self.api_data_url
if not kwargs.get("exclude_properties"):
mapping["purl"] = self.purl
mapping["repository_homepage_url"] = self.repository_homepage_url
mapping["repository_download_url"] = self.repository_download_url
mapping["api_data_url"] = self.api_data_url
if self.qualifiers:
mapping["qualifiers"] = normalize_qualifiers(self.qualifiers, encode=False)
return mapping
Expand Down
64 changes: 41 additions & 23 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_rubygems_packages(mock_get):
mock_get_01_list_of_versions,
mock_get_02_1st_in_list,
mock_get_03_2nd_in_list,
mock_get_04_3rd_in_list
mock_get_04_3rd_in_list,
]

packages = list(info(purl))
Expand Down Expand Up @@ -140,16 +140,20 @@ def test_cocoapods_packages(
mock_get_hashed_path.return_value = "5/5/b"

mock_get_cocoapod_tags.return_value = [
'0.1.5',
'0.1.4',
'0.1.3',
'0.1.2',
'0.1.1',
'0.1.0',
"0.1.5",
"0.1.4",
"0.1.3",
"0.1.2",
"0.1.1",
"0.1.0",
]

mock_get_response.side_effect = file_json("tests/data/cocoapods/mock_get_response_side_effect.json")
mock_get_github_rest.return_value = load_json("tests/data/cocoapods/mock_get_github_rest_return_value.json")
mock_get_response.side_effect = file_json(
"tests/data/cocoapods/mock_get_response_side_effect.json"
)
mock_get_github_rest.return_value = load_json(
"tests/data/cocoapods/mock_get_github_rest_return_value.json"
)

mock_response = mock.Mock()
mock_response.status_code = 200
Expand Down Expand Up @@ -181,16 +185,20 @@ def test_get_cocoapods_data_from_purl(
mock_get_hashed_path.return_value = "5/5/b"

mock_get_cocoapod_tags.return_value = [
'0.1.5',
'0.1.4',
'0.1.3',
'0.1.2',
'0.1.1',
'0.1.0',
"0.1.5",
"0.1.4",
"0.1.3",
"0.1.2",
"0.1.1",
"0.1.0",
]

mock_get_response.side_effect = file_json("tests/data/cocoapods/mock_get_response_side_effect.json")
mock_get_github_rest.return_value = load_json("tests/data/cocoapods/mock_get_github_rest_return_value.json")
mock_get_response.side_effect = file_json(
"tests/data/cocoapods/mock_get_response_side_effect.json"
)
mock_get_github_rest.return_value = load_json(
"tests/data/cocoapods/mock_get_github_rest_return_value.json"
)

mock_response = mock.Mock()
mock_response.status_code = 200
Expand All @@ -216,7 +224,7 @@ def test_get_cocoapod_tags(mock_get):
hashed_path_underscore = hashed_path.replace("/", "_")
file_prefix = "all_pods_versions_"
spec = f"{api}/{file_prefix}{hashed_path_underscore}.txt"
expected_tags = ['0.1.0', '0.1.1', '0.2.0', '0.3.0']
expected_tags = ["0.1.0", "0.1.1", "0.2.0", "0.3.0"]
tags = get_cocoapod_tags(spec, cocoapods_org_pod_name)
tags = sorted(tags)
assert tags == expected_tags
Expand All @@ -225,16 +233,24 @@ def test_get_cocoapod_tags(mock_get):
@mock.patch("fetchcode.package_util.utils.get_response")
@mock.patch("fetchcode.package_util.utils.make_head_request")
@mock.patch("fetchcode.package_util.utils.get_github_rest")
def test_construct_cocoapods_package(mock_get_github_rest, mock_make_head_request, mock_get_response):
mock_get_github_rest.return_value = "Failed to fetch: https://api.github.com/repos/KevalPatel94/KVLLibraries"
def test_construct_cocoapods_package(
mock_get_github_rest, mock_make_head_request, mock_get_response
):
mock_get_github_rest.return_value = (
"Failed to fetch: https://api.github.com/repos/KevalPatel94/KVLLibraries"
)

mock_response = mock.Mock()
mock_response.status_code = 404
mock_make_head_request.return_value = mock_response

mock_get_response.return_value = load_json("tests/data/cocoapods/get_response_kvllibraries.json")
mock_get_response.return_value = load_json(
"tests/data/cocoapods/get_response_kvllibraries.json"
)

expected_construct_cocoapods_package = load_json("tests/data/cocoapods/expected_construct_cocoapods_package.json")
expected_construct_cocoapods_package = load_json(
"tests/data/cocoapods/expected_construct_cocoapods_package.json"
)

purl = PackageURL.from_string("pkg:cocoapods/KVLLibraries")
name = "KVLLibraries"
Expand All @@ -244,7 +260,9 @@ def test_construct_cocoapods_package(mock_get_github_rest, mock_make_head_reques
gh_repo_name = "KVLLibraries"
tag = "1.1.0"

actual_output = construct_cocoapods_package(purl, name, hashed_path, repository_homepage_url, gh_repo_owner, gh_repo_name, tag)
actual_output = construct_cocoapods_package(
purl, name, hashed_path, repository_homepage_url, gh_repo_owner, gh_repo_name, tag
)
actual = json.dumps(actual_output.to_dict())
expected = json.dumps(expected_construct_cocoapods_package)
assert actual == expected
Expand Down

0 comments on commit e1d9073

Please sign in to comment.