Skip to content

Commit

Permalink
Add test case for autoimporting package listings
Browse files Browse the repository at this point in the history
Add a test case which ensures the ecosystem schema autolisted package
IDs field is imported correctly
  • Loading branch information
Oksamies authored and MythicManiac committed Sep 5, 2024
1 parent fc42ad3 commit e3d3f8e
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions django/thunderstore/schema_import/tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
PackageCategory,
PackageListingSection,
)
from thunderstore.repository.models import PackageInstaller
from thunderstore.schema_import.schema import Schema, SchemaPackageInstaller
from thunderstore.community.models.package_listing import PackageListing
from thunderstore.repository.models import Package, PackageInstaller
from thunderstore.schema_import.schema import (
Schema,
SchemaCommunity,
SchemaPackageInstaller,
)
from thunderstore.schema_import.sync import (
get_slogan_from_display_name,
import_schema_communities,
import_schema_package_installers,
)
from thunderstore.schema_import.tasks import sync_ecosystem_schema
Expand All @@ -30,12 +36,14 @@ def test_schema_sync():
assert Community.objects.count() == 0
assert PackageCategory.objects.count() == 0
assert PackageListingSection.objects.count() == 0
assert PackageListing.objects.filter(is_auto_imported=True).count() == 0

sync_ecosystem_schema.delay()

com_count = Community.objects.count()
cat_count = PackageCategory.objects.count()
sec_count = PackageListingSection.objects.count()

assert com_count > 0
assert cat_count > 0
assert sec_count > 0
Expand Down Expand Up @@ -65,3 +73,23 @@ def test_import_schema_installers():
import_schema_package_installers(schema)
assert PackageInstaller.objects.count() == 1
assert PackageInstaller.objects.first().identifier == "foo"


@pytest.mark.django_db
def test_import_autolisted_packages(active_package: Package):
schema = Schema(
schemaVersion="0.0.1",
games=dict(),
communities={
"test": SchemaCommunity(
displayName="Test community",
categories=dict(),
sections=dict(),
autolistPackageIds=[active_package.full_package_name],
),
},
packageInstallers=dict(),
)
assert PackageListing.objects.filter(is_auto_imported=True).count() == 0
import_schema_communities(schema)
assert PackageListing.objects.filter(is_auto_imported=True).count() == 1

0 comments on commit e3d3f8e

Please sign in to comment.