Repository: joshuadavidthomas/django-bird (python)

Issue:
Asset static url not quite right
Not sure exactly how to phrase this, but the static url output by `Asset` and `BirdAssetFinder` is not quite right. Here's an example of one, from an application I have running in Docker:

```python
In [26]: x
Out[26]: Asset(path=PosixPath('/app/templates/bird/modal/modal.js'), type=<AssetType.JS: 'js'>)

In [27]: x.relative_path
Out[27]: PosixPath('bird/modal/modal.js')

In [28]: x.absolute_path
Out[28]: PosixPath('/app/templates/bird/modal/modal.js')

In [29]: BirdAssetFinder().find("bird/modal/modal.js")
Out[29]: '/app/templates/bird/modal/modal.js'

In [30]: finders.find("bird/modal/modal.js")
Out[30]: '/app/templates/bird/modal/modal.js'

In [31]: x.url
Out[31]: '/app/templates/bird/modal/modal.js'
```

When used in the `{% bird:js %}` tag, the url is set to the absolute path above instead of being put under the static root.

Pull request description:
Update `Asset` to use `StaticFilesStorage`
closes #164 

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e676461..e899a78 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,6 +18,9 @@ and this project attempts to adhere to [Semantic Versioning](https://semver.org/
 
 ## [Unreleased]
 
+### Fixed
+- Fixed asset URL generation to properly use Django's static file storage system instead of raw file paths.
+
 ## [0.13.0]
 
 🚨 This release contains some breaking changes. See the Deprecated and Removed sections for more information. 🚨
diff --git a/src/django_bird/staticfiles.py b/src/django_bird/staticfiles.py
index c8fdc01..ea4c1f5 100644
--- a/src/django_bird/staticfiles.py
+++ b/src/django_bird/staticfiles.py
@@ -13,6 +13,7 @@ from typing import overload
 
 from django.contrib.staticfiles import finders
 from django.contrib.staticfiles.finders import BaseFinder
+from django.contrib.staticfiles.storage import StaticFilesStorage
 from django.core.checks import CheckMessage
 from django.core.files.storage import FileSystemStorage
 from django.urls import reverse
@@ -85,7 +86,7 @@ class Asset:
 
     @property
     def storage(self):
-        storage = FileSystemStorage(location=str(self.template_dir))
+        storage = StaticFilesStorage(location=str(self.template_dir))
         storage.prefix = DjangoBirdAppConfig.label  # type: ignore[attr-defined]
         return storage
 
@@ -101,8 +102,10 @@ class Asset:
 
     @property
     def url(self) -> str:
-        path = finders.find(str(self.relative_path))
-        return path or reverse(
+        static_path = finders.find(str(self.relative_path))
+        if static_path is not None:
+            return self.storage.url(static_path)
+        return reverse(
             "django_bird:asset",
             kwargs={
                 "component_name": self.path.stem,


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
index 5e35917..5e7401d 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -34,7 +34,9 @@ def pytest_configure(config):
 TEST_SETTINGS = {
     "INSTALLED_APPS": [
         "django_bird",
+        "django.contrib.staticfiles",
     ],
+    "STATIC_URL": "/static/",
     "TEMPLATES": [
         {
             "BACKEND": "django.template.backends.django.DjangoTemplates",
diff --git a/tests/test_staticfiles.py b/tests/test_staticfiles.py
index 8c8a1c0..e352ca3 100644
--- a/tests/test_staticfiles.py
+++ b/tests/test_staticfiles.py
@@ -72,7 +72,10 @@ class TestAssetClass:
         component = Component.from_name(button.name)
         asset = component.get_asset(button_css.file.name)
 
-        assert str(asset.storage.location) in str(button_css.file)
+        with override_settings(
+            STATIC_URL="/static/",
+        ):
+            assert str(asset.storage.location) in str(button_css.file)
 
     def test_template_dir(self, templates_dir):
         button = TestComponent(
@@ -152,7 +155,7 @@ class TestAssetClass:
         component = Component.from_name(button.name)
         asset = component.get_asset(button_css.file.name)
 
-        assert asset.url == str(button_css.file)
+        assert asset.url == f"/static{button_css.file.parent}/{button_css.file.name}"
 
     def test_url_with_reverse_fallback(self, templates_dir):
         button = TestComponent(
@@ -415,14 +418,6 @@ class TestFindersFind:
 
 
 class TestStaticCollection:
-    @pytest.fixture(autouse=True)
-    def staticfiles_app(self):
-        with override_settings(
-            INSTALLED_APPS=settings.INSTALLED_APPS + ["django.contrib.staticfiles"],
-            STATIC_URL="/static/",
-        ):
-            yield
-
     @pytest.fixture
     def static_root(self, tmp_path):
         static_dir = tmp_path / "static"
@@ -554,14 +549,6 @@ class TestStaticCollection:
 
 
 class TestStaticTemplateTag:
-    @pytest.fixture(autouse=True)
-    def staticfiles_app(self):
-        with override_settings(
-            INSTALLED_APPS=settings.INSTALLED_APPS + ["django.contrib.staticfiles"],
-            STATIC_URL="/static/",
-        ):
-            yield
-
     def test_static_tag(self, templates_dir):
         button = TestComponent(
             name="button", content="<button>Click me</button>"