This repository has been archived by the owner on Feb 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug in update_rates command and added tests
- Loading branch information
Showing
2 changed files
with
31 additions
and
2 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
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()) |