|
|
@@ -5,6 +5,11 @@ from django.test import TestCase
|
|
5
|
5
|
from django import template
|
|
6
|
6
|
|
|
7
|
7
|
|
|
|
8
|
+def render(template_string, ctx):
|
|
|
9
|
+ tpl = template.Template(template_string)
|
|
|
10
|
+ return tpl.render(template.Context(ctx))
|
|
|
11
|
+
|
|
|
12
|
+
|
|
8
|
13
|
class TestCurrencyFilter(TestCase):
|
|
9
|
14
|
|
|
10
|
15
|
def setUp(self):
|
|
|
@@ -28,3 +33,26 @@ class TestCurrencyFilter(TestCase):
|
|
28
|
33
|
self.template.render(template.Context({
|
|
29
|
34
|
'price': ''
|
|
30
|
35
|
}))
|
|
|
36
|
+
|
|
|
37
|
+
|
|
|
38
|
+class TestCurrencyTag(TestCase):
|
|
|
39
|
+
|
|
|
40
|
+ def test_renders_uk_price_correctly(self):
|
|
|
41
|
+ ctx = {'price': D('10.23')}
|
|
|
42
|
+ out = render("{% load currency_tags %}{% currency price 'GBP' %}", ctx)
|
|
|
43
|
+ self.assertTrue(u'£10.23' in out)
|
|
|
44
|
+
|
|
|
45
|
+ def test_renders_us_price_correctly(self):
|
|
|
46
|
+ ctx = {
|
|
|
47
|
+ 'price': D('10.23'),
|
|
|
48
|
+ 'currency': 'USD'
|
|
|
49
|
+ }
|
|
|
50
|
+ out = render(
|
|
|
51
|
+ "{% load currency_tags %}{% currency price currency %}", ctx)
|
|
|
52
|
+ self.assertTrue(u'$10.23' in out)
|
|
|
53
|
+
|
|
|
54
|
+ def test_uses_default_currency(self):
|
|
|
55
|
+ ctx = {'price': D('10.23')}
|
|
|
56
|
+ out = render(
|
|
|
57
|
+ "{% load currency_tags %}{% currency price currency %}", ctx)
|
|
|
58
|
+ self.assertTrue(u'£10.23' in out)
|