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

Commit

Permalink
Fixed bug in update_rates command and added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
synasius committed Oct 17, 2013
1 parent 90afaba commit c09b7ea
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions djmoney_rates/management/commands/update_rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class Command(BaseCommand):
def handle(self, *args, **options):
if args:
try:
backend_class = import_from_string(args, "")
backend_class = import_from_string(args[0], "")
except ImportError:
raise CommandError("Cannot find custom backend %s. Is it correct" % args)
raise CommandError("Cannot find custom backend %s. Is it correct" % args[0])
else:
backend_class = money_rates_settings.DEFAULT_BACKEND

Expand Down
29 changes: 29 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from __future__ import unicode_literals

import unittest

from django.core.management import call_command
from django.core.management.base import CommandError

from djmoney_rates.backends import BaseRateBackend
from djmoney_rates.models import Rate, RateSource


class CustomBackend(BaseRateBackend):
source_name = "custom-backend"
base_currency = "USD"

def get_rates(self):
return {"PLN": 3.07, "EUR": 0.74}


class TestCommands(unittest.TestCase):
def test_fail_when_custom_backend_do_not_exists(self):
with self.assertRaises(CommandError):
call_command("update_rates", "fake.custom.Backend")

def test_custom_backend_used_when_specified(self):
call_command("update_rates", "tests.test_commands.CustomBackend")

self.assertEqual(1, RateSource.objects.filter(name="custom-backend").count())
self.assertEqual(2, Rate.objects.filter(source__name="custom-backend").count())

0 comments on commit c09b7ea

Please sign in to comment.