Skip to content

Commit

Permalink
fix: stupid type()
Browse files Browse the repository at this point in the history
  • Loading branch information
z0z0r4 committed Jan 25, 2025
1 parent 00b036b commit f6921d0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
8 changes: 4 additions & 4 deletions modrinth_api_wrapper/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def search_project(
params={
"query": query,
"facets": facets,
"index": index if type(index) is str else index.value,
"index": index.value if isinstance(index, SearchIndex) else index,
"offset": offset,
"limit": limit,
},
Expand Down Expand Up @@ -116,7 +116,7 @@ def get_versions_from_hashes(
headers=self.headers,
json={
"hashes": hashes,
"algorithm": algorithm if type(algorithm) is str else algorithm.value,
"algorithm": algorithm.value if isinstance(algorithm, Algorithm) else algorithm,
},
)
return {key: Version(**item) for key, item in res.items()}
Expand Down Expand Up @@ -154,7 +154,7 @@ def get_latest_versions_from_hashes(
headers=self.headers,
json={
"hashes": hashes,
"algorithm": algorithm if type(algorithm) is str else algorithm.value,
"algorithm": algorithm.value if isinstance(algorithm, Algorithm) else algorithm,
"hashes": hashes,
"loaders": loaders,
"game_versions": game_versions,
Expand All @@ -163,6 +163,6 @@ def get_latest_versions_from_hashes(
return {key: Version(**item) for key, item in res.items()}

def get_tag(self, tag: Union[Tag, str]) -> Union[List, Dict]:
url = f"{self.endpoint}/v2/tag/{tag.value if type(tag) is Tag else tag}"
url = f"{self.endpoint}/v2/tag/{tag.value if isinstance(tag, Tag) else tag}"
res = request(url, headers=self.headers)
return res
33 changes: 16 additions & 17 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,68 +35,68 @@
@pytest.mark.search
def test_search_project():
result = client.search_project(query="sodium")
assert type(result) == SearchResult
assert isinstance(result, SearchResult)


@pytest.mark.project
def test_get_project():
for project_id in PROJECT_IDS:
project = client.get_project(project_id=project_id)
assert type(project) == Project
assert isinstance(project, Project)


@pytest.mark.project
def test_get_projects():
projects = client.get_projects(ids=PROJECT_IDS)
for project in projects:
assert type(project) == Project
assert isinstance(project, Project)
projects = client.get_projects(ids=SLUGS)
for project in projects:
assert type(project) == Project
assert isinstance(project, Project)


@pytest.mark.version
def test_get_project_versions():
for project_id in PROJECT_IDS:
versions = client.list_project_versions(project_id=project_id)
for version in versions:
assert type(version) == Version
assert isinstance(version, Version)


@pytest.mark.version
def test_get_version():
for version_id in VERSION_IDS:
version = client.get_version(version_id=version_id)
assert type(version) == Version
assert isinstance(version, Version)


@pytest.mark.version
def test_get_versions():
versions = client.get_versions(version_ids=VERSION_IDS)
for version in versions:
assert type(version) == Version
assert isinstance(version, Version)


@pytest.mark.version_file
def test_get_version_from_hash():
for sha1 in SHA1:
version = client.get_version_from_hash(sha1=sha1)
assert type(version) == Version
assert isinstance(version, Version)
for sha512 in SHA512:
version = client.get_version_from_hash(sha512=sha512)
assert type(version) == Version
assert isinstance(version, Version)


@pytest.mark.version_file
def test_get_versions_from_hashes():
versions = client.get_versions_from_hashes(hashes=SHA1, algorithm=Algorithm.SHA1)
for version in versions.values():
assert type(version) == Version
assert isinstance(version, Version)
versions = client.get_versions_from_hashes(
hashes=SHA512, algorithm=Algorithm.SHA512
)
for version in versions.values():
assert type(version) == Version
assert isinstance(version, Version)


@pytest.mark.version_file
Expand All @@ -105,12 +105,12 @@ def test_get_latest_version_from_hash():
version = client.get_latest_version_from_hash(
sha1=sha1, loaders=["fabric"], game_versions=["1.16.5"]
)
assert type(version) == Version
assert isinstance(version, Version)
for sha512 in SHA512:
version = client.get_latest_version_from_hash(
sha512=sha512, loaders=["fabric"], game_versions=["1.16.5"]
)
assert type(version) == Version
assert isinstance(version, Version)


@pytest.mark.version_file
Expand All @@ -122,20 +122,19 @@ def test_get_latest_versions_from_hashes():
game_versions=["1.16.5"],
)
for version in versions.values():
assert type(version) == Version
assert isinstance(version, Version)
versions = client.get_latest_versions_from_hashes(
hashes=SHA512,
algorithm=Algorithm.SHA512,
loaders=["fabric"],
game_versions=["1.16.5"],
)
for version in versions.values():
assert type(version) == Version
assert isinstance(version, Version)


@pytest.mark.tag
def test_get_tag():

for tag_name in TAG_NAMES:
tag = client.get_tag(tag=tag_name)
assert type(tag) == list or dict
assert isinstance(tag, (list, dict))

0 comments on commit f6921d0

Please sign in to comment.