|
11 | 11 | from django.http import HttpRequest |
12 | 12 |
|
13 | 13 | from plugins.consortial_billing import models, plugin_settings |
| 14 | +from plugins.consortial_billing import utils |
14 | 15 | from utils.testing import helpers |
15 | 16 | from press import models as press_models |
16 | 17 | from cms.models import Page |
@@ -72,6 +73,10 @@ def setUpClass(cls): |
72 | 73 | name='Higher', |
73 | 74 | order=1, |
74 | 75 | ) |
| 76 | + cls.level_third = models.SupportLevel.objects.create( |
| 77 | + name='Even Higher', |
| 78 | + order=0, |
| 79 | + ) |
75 | 80 | cls.currency_base = models.Currency.objects.create( |
76 | 81 | code='GBP', |
77 | 82 | region='GBR', |
@@ -100,6 +105,15 @@ def setUpClass(cls): |
100 | 105 | billing_agent=cls.agent_default, |
101 | 106 | base=True, |
102 | 107 | ) |
| 108 | + cls.band_base_country_other = models.Band.objects.create( |
| 109 | + size=cls.size_other, |
| 110 | + country='DE', |
| 111 | + currency=cls.currency_other, |
| 112 | + level=cls.level_third, |
| 113 | + fee=5000, |
| 114 | + billing_agent=cls.agent_default, |
| 115 | + base=True, |
| 116 | + ) |
103 | 117 | cls.band_other_one = models.Band.objects.create( |
104 | 118 | size=cls.size_base, |
105 | 119 | country='GB', |
@@ -192,9 +206,12 @@ def tearDownClass(cls): |
192 | 206 | cls.supporter_one.delete() |
193 | 207 | cls.band_other_two.delete() |
194 | 208 | cls.band_other_one.delete() |
| 209 | + cls.band_base_country_other.delete() |
| 210 | + cls.band_base_level_other.delete() |
195 | 211 | cls.band_base.delete() |
196 | 212 | cls.currency_other.delete() |
197 | 213 | cls.currency_base.delete() |
| 214 | + cls.level_third.delete() |
198 | 215 | cls.level_other.delete() |
199 | 216 | cls.level_base.delete() |
200 | 217 | cls.size_other.delete() |
@@ -242,23 +259,33 @@ def test_billing_agent_save(self): |
242 | 259 | self.assertFalse(other_has_country) |
243 | 260 | self.assertFalse(default_still_default) |
244 | 261 |
|
245 | | - def test_currency_exchange_rate(self): |
246 | | - with patch( |
247 | | - 'plugins.consortial_billing.logic.latest_multiplier_for_indicator' |
248 | | - ) as latest_multiplier: |
249 | | - self.currency_other.exchange_rate() |
250 | | - self.assertIn( |
251 | | - plugin_settings.RATE_INDICATOR, |
252 | | - latest_multiplier.call_args.args, |
253 | | - ) |
254 | | - self.assertIn( |
255 | | - self.currency_other.region, |
256 | | - latest_multiplier.call_args.args, |
257 | | - ) |
258 | | - self.assertIn( |
259 | | - self.currency_other.region, |
260 | | - latest_multiplier.call_args.args, |
261 | | - ) |
| 262 | + @patch('plugins.consortial_billing.logic.latest_multiplier_for_indicator') |
| 263 | + def test_currency_exchange_rate_with_typical_args(self, latest_multiplier): |
| 264 | + self.currency_base.exchange_rate(base_band=self.band_base_country_other) |
| 265 | + expected_args = ( |
| 266 | + plugin_settings.RATE_INDICATOR, |
| 267 | + self.currency_base.region, # Target currency |
| 268 | + self.currency_other.region, # Specified base currency |
| 269 | + utils.setting('missing_data_exchange_rate') |
| 270 | + ) |
| 271 | + self.assertTupleEqual( |
| 272 | + expected_args, |
| 273 | + latest_multiplier.call_args.args, |
| 274 | + ) |
| 275 | + |
| 276 | + @patch('plugins.consortial_billing.logic.latest_multiplier_for_indicator') |
| 277 | + def test_currency_exchange_rate_with_no_args(self, latest_multiplier): |
| 278 | + self.currency_other.exchange_rate() |
| 279 | + expected_args = ( |
| 280 | + plugin_settings.RATE_INDICATOR, |
| 281 | + self.currency_other.region, # Target currency |
| 282 | + self.currency_base.region, # Default base currency |
| 283 | + utils.setting('missing_data_exchange_rate') |
| 284 | + ) |
| 285 | + self.assertTupleEqual( |
| 286 | + expected_args, |
| 287 | + latest_multiplier.call_args.args, |
| 288 | + ) |
262 | 289 |
|
263 | 290 | def test_band_economic_disparity(self): |
264 | 291 | with patch( |
|
0 commit comments