Skip to content

Commit

Permalink
Remove source from BooleanField
Browse files Browse the repository at this point in the history
Remove the source property from the is_removed BooleanField
as it is not required.

Implement an additional test for testing the DependencySerializer's
endpoint.

Refs. TS-2275
  • Loading branch information
Roffenlund committed Jan 16, 2025
1 parent 04e9869 commit 5a07af2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 39 additions & 0 deletions django/thunderstore/api/cyberstorm/tests/test_package_listing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime
from typing import Optional
from unittest.mock import patch, PropertyMock

import pytest
from rest_framework.test import APIClient
Expand All @@ -9,11 +10,13 @@
get_custom_package_listing,
)
from thunderstore.community.factories import (
Community,
CommunityFactory,
PackageCategoryFactory,
PackageListingFactory,
)
from thunderstore.repository.factories import (
NamespaceFactory,
PackageRatingFactory,
PackageVersionFactory,
TeamMemberFactory,
Expand Down Expand Up @@ -334,3 +337,39 @@ def test_dependency_serializer__when_dependency_is_not_active__censors_icon_and_

def _date_to_z(value: datetime) -> str:
return value.strftime("%Y-%m-%dT%H:%M:%S.%fZ")


@pytest.mark.django_db
@pytest.mark.parametrize("return_val", [True, False])
def test_package_listing_is_removed(
return_val: bool,
api_client: APIClient,
community: Community,
) -> None:
package = "Mod"
target_ns = NamespaceFactory()

target_dependency = PackageListingFactory(
community_=community,
package_kwargs={"name": package, "namespace": target_ns},
)

target_package = PackageListingFactory(community_=community)
target_package.package.latest.dependencies.set(
[target_dependency.package.latest.id],
)

community_id = target_package.community.identifier
namespace = target_package.package.namespace.name
package_name = target_package.package.name

url = f"/api/cyberstorm/listing/{community_id}/{namespace}/{package_name}/"

path = "thunderstore.repository.models.package_version.PackageVersion.is_removed"
with patch(path, new_callable=PropertyMock) as is_removed_property:
is_removed_property.return_value = return_val
response = api_client.get(url)
response_dependencies = response.json()["dependencies"][0]

assert "is_removed" in response_dependencies
assert response_dependencies["is_removed"] == return_val
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class DependencySerializer(serializers.Serializer):
name = serializers.CharField()
namespace = serializers.CharField(source="package.namespace.name")
version_number = serializers.CharField()
is_removed = serializers.BooleanField(source="is_removed")
is_removed = serializers.BooleanField()

def get_description(self, obj: PackageVersion) -> str:
return (
Expand Down

0 comments on commit 5a07af2

Please sign in to comment.