-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests and docs for config classes
This commit adds a few basic tests to check things work as expected.
- Loading branch information
1 parent
9df0ce6
commit b62b46e
Showing
3 changed files
with
83 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from django.conf import settings | ||
from django.core.exceptions import ImproperlyConfigured | ||
|
||
from django.test import TestCase | ||
from django.test.utils import override_settings | ||
|
||
from adyen.config import get_config | ||
|
||
|
||
@override_settings( | ||
ADYEN_IDENTIFIER='foo', | ||
ADYEN_SECRET_KEY='foo', | ||
ADYEN_ACTION_URL='foo', | ||
ADYEN_SKIN_CODE='foo', | ||
) | ||
class FromSettingsTestCase(TestCase): | ||
""" | ||
This test case tests the FromSettings confic class, which just fetches its | ||
values from the Django settings. | ||
""" | ||
|
||
def test_is_default(self): | ||
assert 'FromSettingsConfig' in get_config().__class__.__name__ | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
maiksprenger
Author
Member
|
||
|
||
def test_value_passing_works(self): | ||
assert get_config().get_action_url() == 'foo' | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
maiksprenger
Author
Member
|
||
|
||
# https://docs.djangoproject.com/en/1.8/topics/testing/tools/#django.test.modify_settings | ||
# Override settings is needed to let us delete settings on a per-test basis. | ||
@override_settings() | ||
def test_complains_when_not_fully_configured(self): | ||
# If the setting is missing, a proper exception is raised | ||
del settings.ADYEN_ACTION_URL | ||
with self.assertRaises(ImproperlyConfigured): | ||
get_config() | ||
|
||
|
||
class DummyConfigClass: | ||
|
||
def get_action_url(self): | ||
return 'foo' | ||
|
||
|
||
@override_settings(ADYEN_CONFIG_CLASS='tests.test_config.DummyConfigClass') | ||
class CustomConfigClassTestCase(TestCase): | ||
""" | ||
This test case checks that it's possible to replace the FromSettings confic class | ||
by one's own, and that it is used to fetch values as expected. | ||
""" | ||
|
||
def test_class_gets_picked_up(self): | ||
assert 'DummyConfigClass' in get_config().__class__.__name__ | ||
|
||
@override_settings(ADYEN_ACTION_URL='bar') | ||
def test_settings_ignored(self): | ||
""" | ||
Check that we indeed ignore Django settings (apart from the config class). | ||
""" | ||
assert get_config().get_action_url() == 'foo' | ||
|
||
|
assert isinstance(get_config(), FromSettingsConfig)
would be semantically more appropriate, wouldn't it?