Skip to content

Commit

Permalink
Migrated commands tests
Browse files Browse the repository at this point in the history
  • Loading branch information
silvanocerza committed Feb 12, 2017
1 parent ca904a7 commit 4b1c3d4
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import unicode_literals

import unittest
import pytest

from django.core.management import call_command
from django.core.management.base import CommandError
Expand All @@ -9,7 +9,6 @@
from djmoney_rates.models import Rate, RateSource
from djmoney_rates.settings import money_rates_settings


class CustomBackend(BaseRateBackend):
source_name = "custom-backend"
base_currency = "USD"
Expand All @@ -18,23 +17,24 @@ 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_fail_when_custom_backend_do_not_exists():
with pytest.raises(CommandError):
call_command("update_rates", "fake.custom.Backend")

def test_custom_backend_used_when_specified(self):
call_command("update_rates", "tests.test_commands.CustomBackend")
@pytest.mark.django_db(transaction=True)
def test_custom_backend_used_when_specified():
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())
assert 1 == RateSource.objects.filter(name="custom-backend").count()
assert 2 == Rate.objects.filter(source__name="custom-backend").count()

def test_default_backend_used_when_not_specified(self):
"""
Test that if no backend is passed as parameter, the default one is used
"""
money_rates_settings.DEFAULT_BACKEND = CustomBackend
call_command("update_rates")
@pytest.mark.django_db(transaction=True)
def test_default_backend_used_when_not_specified():
"""
Test that if no backend is passed as parameter, the default one is used
"""
money_rates_settings.DEFAULT_BACKEND = CustomBackend
call_command("update_rates")

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

0 comments on commit 4b1c3d4

Please sign in to comment.