Skip to content

Commit

Permalink
Fix linting warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
anttimaki committed Oct 12, 2023
1 parent 517276c commit cece83c
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 28 deletions.
17 changes: 11 additions & 6 deletions django/thunderstore/api/cyberstorm/tests/test_community_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@

@pytest.mark.django_db
def test_api_cyberstorm_community_detail_success(
client: APIClient, community_site: CommunitySite
client: APIClient,
community_site: CommunitySite,
):
PackageListingFactory(
community_=community_site.community, package_version_kwargs={"downloads": 0}
community_=community_site.community,
package_version_kwargs={"downloads": 0},
)
PackageListingFactory(
community_=community_site.community, package_version_kwargs={"downloads": 23}
community_=community_site.community,
package_version_kwargs={"downloads": 23},
)
PackageListingFactory(
community_=community_site.community, package_version_kwargs={"downloads": 42}
community_=community_site.community,
package_version_kwargs={"downloads": 42},
)

response = client.get(
Expand All @@ -39,10 +43,11 @@ def test_api_cyberstorm_community_detail_success(

@pytest.mark.django_db
def test_api_cyberstorm_community_detail_failure(
client: APIClient, community_site: CommunitySite
client: APIClient,
community_site: CommunitySite,
):
response = client.get(
f"/api/cyberstorm/community/bad/",
"/api/cyberstorm/community/bad/",
HTTP_HOST=community_site.site.domain,
)
assert response.status_code == 404
24 changes: 15 additions & 9 deletions django/thunderstore/api/cyberstorm/tests/test_community_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@

@pytest.mark.django_db
def test_api_cyberstorm_community_list_get_success(
client: APIClient, community_site: CommunitySite, dummy_image
client: APIClient,
community_site: CommunitySite,
dummy_image,
):

community1 = CommunityFactory()
community2 = CommunityFactory(background_image=dummy_image)
for x in range(10):
for _ in range(10):
PackageListingFactory(
community_=community1, package_version_kwargs={"downloads": 10}
community_=community1,
package_version_kwargs={"downloads": 10},
)
PackageListingFactory(
community_=community2, package_version_kwargs={"downloads": 5}
community_=community2,
package_version_kwargs={"downloads": 5},
)

for x in range(10):
for _ in range(10):
PackageListingFactory(
community_=community1,
package_version_kwargs={"downloads": 3},
Expand Down Expand Up @@ -74,12 +78,13 @@ def test_api_cyberstorm_community_list_only_listed_communities_are_returned(
assert (
len(data["results"]) == 2
) # There is the test community, that is created in api_client
assert not (non_listed.identifier in [c["identifier"] for c in data["results"]])
assert not (non_listed.identifier in (c["identifier"] for c in data["results"]))


@pytest.mark.django_db
def test_api_cyberstorm_community_list_are_ordered_by_identifier_by_default(
api_client: APIClient, community
api_client: APIClient,
community,
) -> None:
a = CommunityFactory(identifier="a")
b = CommunityFactory(identifier="b")
Expand All @@ -96,7 +101,7 @@ def test_api_cyberstorm_community_list_pagination(
api_client: APIClient,
) -> None:

for i in range(25):
for _ in range(25):
CommunityFactory()

total_count = Community.objects.count()
Expand All @@ -123,7 +128,8 @@ def test_api_cyberstorm_community_list_pagination(


def __assert_communities(
data: Dict, communities: Union[Community, List[Community]]
data: Dict,
communities: Union[Community, List[Community]],
) -> None:
"""
Check that expected communities are found in results
Expand Down
10 changes: 5 additions & 5 deletions django/thunderstore/community/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Optional

from django.conf import settings
from django.db.models import Count
from django.templatetags.static import static

from thunderstore.community.models.community import Community
Expand All @@ -28,15 +27,15 @@ def get_community_context(community: Optional[Community]):
"site_icon": url,
"site_icon_width": community.icon_width,
"site_icon_height": community.icon_height,
}
},
)
else:
result.update(
{
"site_icon": f"{settings.PROTOCOL}{settings.PRIMARY_HOST}{static('icon.png')}",
"site_icon_width": "1000",
"site_icon_height": "1000",
}
},
)
return result
else:
Expand All @@ -62,6 +61,7 @@ def community_site(request):
def selectable_communities(request):
return {
"selectable_communities": Community.objects.listed().order_by(
"-aggregated_fields__package_count", "datetime_created"
)
"-aggregated_fields__package_count",
"datetime_created",
),
}
4 changes: 2 additions & 2 deletions django/thunderstore/community/models/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def save(self, *args, **kwargs):
+ (
"icon_width",
"icon_height",
)
),
)
if not self.background_image:
self.background_image_width = 0
Expand All @@ -115,7 +115,7 @@ def save(self, *args, **kwargs):
+ (
"background_image_width",
"background_image_height",
)
),
)
return super().save(*args, **kwargs)

Expand Down
9 changes: 5 additions & 4 deletions django/thunderstore/community/tests/test_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ def test_community_get_community_filepath(community: Community) -> None:


@pytest.mark.django_db
@pytest.mark.parametrize("require_approval", (False, True))
@pytest.mark.parametrize("require_approval", [False, True])
def test_community_valid_review_statuses(
community: Community, require_approval: bool
community: Community,
require_approval: bool,
) -> None:
community.require_package_listing_approval = require_approval
community.save()
Expand All @@ -127,7 +128,7 @@ def test_community_valid_review_statuses(


@pytest.mark.django_db
@pytest.mark.parametrize("has_site", (False, True))
@pytest.mark.parametrize("has_site", [False, True])
def test_community_full_url(
community: Community,
has_site: bool,
Expand All @@ -141,7 +142,7 @@ def test_community_full_url(


@pytest.mark.django_db
@pytest.mark.parametrize("has_site", (False, True))
@pytest.mark.parametrize("has_site", [False, True])
def test_community_should_use_old_urls(
community: Community,
has_site: bool,
Expand Down
3 changes: 2 additions & 1 deletion django/thunderstore/core/tests/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def test_celery_task_removal_handled_correctly(celery_app):
@pytest.mark.django_db
@override_settings(CELERY_ALWAYS_EAGER=True)
def test_celery_post(
celery_app: celery.Celery, http_server: Generator[str, None, None]
celery_app: celery.Celery,
http_server: Generator[str, None, None],
):
celery_response = celery_post.delay("http://localhost:8888")
assert celery_response.state == "SUCCESS"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def get_queryset(self) -> QuerySet[Community]:
)

def serialize_results(
self, queryset: QuerySet[Community]
self,
queryset: QuerySet[Community],
) -> FrontPageContentSerializer:
communities = [
{
Expand Down

0 comments on commit cece83c

Please sign in to comment.