Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
fix: raise ImproperlyConfigured for all unguessable storages
Browse files Browse the repository at this point in the history
  • Loading branch information
antonagestam committed Oct 6, 2019
1 parent e65bc15 commit c1a1430
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 15 deletions.
7 changes: 4 additions & 3 deletions collectfast/strategies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ def load_strategy(klass: Union[str, type, object]) -> Type[Strategy]:


def _resolves_to_subclass(subclass_ref: str, superclass_ref: str) -> bool:
subclass = locate(subclass_ref)
assert isinstance(subclass, type)
try:
subclass = locate(subclass_ref)
assert isinstance(subclass, type)
superclass = locate(superclass_ref)
assert isinstance(superclass, type)
except (ImportError, AssertionError) as e:
Expand All @@ -176,5 +176,6 @@ def guess_strategy(storage: str) -> str:
if _resolves_to_subclass(storage, _BOTO3_STORAGE):
return _BOTO3_STRATEGY
raise ImproperlyConfigured(
"No strategy configured, please make sure COLLECTFAST_STRATEGY is set."
"Collectfast failed to guess strategy, please make sure "
"COLLECTFAST_STRATEGY is set."
)
10 changes: 0 additions & 10 deletions collectfast/tests/no_preload_metadata.py

This file was deleted.

21 changes: 19 additions & 2 deletions collectfast/tests/strategies/test_guess_strategy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from unittest import TestCase

from django.core.exceptions import ImproperlyConfigured

from collectfast.strategies.base import _BOTO3_STORAGE
from collectfast.strategies.base import _BOTO3_STRATEGY
from collectfast.strategies.base import _BOTO_STORAGE
Expand All @@ -24,14 +26,29 @@ def test_guesses_boto3_from_exact(case):
def test_guesses_boto_from_subclass(case):
# type: (TestCase) -> None
case.assertEqual(
guess_strategy("collectfast.tests.boto_subclass.CustomStorage"), _BOTO_STRATEGY
guess_strategy("collectfast.tests.test_storages.boto_subclass.CustomStorage"),
_BOTO_STRATEGY,
)


@test
def test_guesses_boto3_from_subclass(case):
# type: (TestCase) -> None
case.assertEqual(
guess_strategy("collectfast.tests.boto3_subclass.CustomStorage"),
guess_strategy("collectfast.tests.test_storages.boto3_subclass.CustomStorage"),
_BOTO3_STRATEGY,
)


@test
def test_raises_improperly_configured_for_unguessable_class(case):
# type: (TestCase) -> None
with case.assertRaises(ImproperlyConfigured):
guess_strategy("collectfast.tests.test_storages.unguessable.UnguessableStorage")


@test
def test_raises_improperly_configured_for_invalid_type(case):
# type: (TestCase) -> None
with case.assertRaises(ImproperlyConfigured):
guess_strategy("collectfast.tests.test_storages.unguessable.NotAType")
Empty file.
5 changes: 5 additions & 0 deletions collectfast/tests/test_storages/unguessable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class UnguessableStorage:
pass


NotAType = 1
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ source = collectfast

[coverage:report]
omit = */tests/*
exclude_lines =
pragma: no cover
# Don't complain if tests don't hit defensive assertion code:
\.\.\.

[metadata]
license_file = LICENSE

0 comments on commit c1a1430

Please sign in to comment.