Skip to content
This repository has been archived by the owner on Feb 28, 2020. It is now read-only.

Commit

Permalink
Tested thrown exceptions values
Browse files Browse the repository at this point in the history
  • Loading branch information
silvanocerza committed Apr 3, 2017
1 parent 324c680 commit ac1f763
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions djmoney_rates/backends.py
Expand Up @@ -28,7 +28,7 @@ def get_source_name(self):
Return the name that identifies the ratings source
"""
if not self.source_name:
raise RateBackendError("'source_name' can't be empty or"
raise RateBackendError("'source_name' can't be empty or "
"you should override 'get_source_name'")

return self.source_name
Expand All @@ -38,7 +38,7 @@ def get_base_currency(self):
Return the base currency to which the rates are referred
"""
if not self.base_currency:
raise RateBackendError("'base_currency' can't be empty or"
raise RateBackendError("'base_currency' can't be empty or "
"you should override 'get_base_currency'")

return self.base_currency
Expand Down
18 changes: 15 additions & 3 deletions tests/test_backends.py
Expand Up @@ -31,9 +31,17 @@ def set_up():
money_rates_settings.OPENEXCHANGE_APP_ID = "fake-app-id"

def test_source_name_empty_is_invalid():
with pytest.raises(RateBackendError):
with pytest.raises(RateBackendError) as exc:
BaseRateBackend().get_source_name()

assert "'source_name' can't be empty or you should override 'get_source_name'" in str(exc.value)

def test_base_currency_empty_is_invalid():
with pytest.raises(RateBackendError) as exc:
BaseRateBackend().get_base_currency()

assert "'base_currency' can't be empty or you should override 'get_base_currency'" in str(exc.value)

@pytest.mark.django_db(transaction=True)
def test_update_rates():
class RateBackend(BaseRateBackend):
Expand All @@ -51,15 +59,19 @@ def get_rates(self):
def test_missing_url_error(set_up):
money_rates_settings.OPENEXCHANGE_URL = ""

with pytest.raises(ImproperlyConfigured):
with pytest.raises(ImproperlyConfigured) as exc:
OpenExchangeBackend()

assert "OPENEXCHANGE_URL setting should not be empty when using OpenExchangeBackend" in str(exc.value)

def test_missing_app_id(set_up):
money_rates_settings.OPENEXCHANGE_APP_ID = ""

with pytest.raises(ImproperlyConfigured):
with pytest.raises(ImproperlyConfigured) as exc:
OpenExchangeBackend()

assert "OPENEXCHANGE_APP_ID setting should not be empty when using OpenExchangeBackend" in str(exc.value)

def test_url_is_correct(set_up):
backend = OpenExchangeBackend()
assert backend.url == "http://openexchangerates.org/api/latest.json?app_id=fake-app-id&base=USD"
Expand Down
4 changes: 3 additions & 1 deletion tests/test_commands.py
Expand Up @@ -18,9 +18,11 @@ def get_rates(self):


def test_fail_when_custom_backend_do_not_exists():
with pytest.raises(CommandError):
with pytest.raises(CommandError) as exc:
call_command("update_rates", "fake.custom.Backend")

assert "Cannot find custom backend fake.custom.Backend. Is it correct" in str(exc.value)

@pytest.mark.django_db(transaction=True)
def test_custom_backend_used_when_specified():
call_command("update_rates", "tests.test_commands.CustomBackend")
Expand Down

0 comments on commit ac1f763

Please sign in to comment.