From 26c97db3648fd26ed1f502b874a153e41f03b37f Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 4 Feb 2023 11:17:37 +1100 Subject: [PATCH] Currency update fix (#4303) * Call function rather than just looking at it * Simple unit test POSTs to currency refresh endpoint * Check if rates have been updated --- InvenTree/common/api.py | 2 +- InvenTree/common/tests.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/InvenTree/common/api.py b/InvenTree/common/api.py index 82fae54cd2..4061e37b3b 100644 --- a/InvenTree/common/api.py +++ b/InvenTree/common/api.py @@ -154,7 +154,7 @@ class CurrencyRefreshView(APIView): from InvenTree.tasks import update_exchange_rates - update_exchange_rates + update_exchange_rates() return Response({ 'success': 'Exchange rates updated', diff --git a/InvenTree/common/tests.py b/InvenTree/common/tests.py index 3754fcf9c7..f77b32ca0e 100644 --- a/InvenTree/common/tests.py +++ b/InvenTree/common/tests.py @@ -912,3 +912,16 @@ class CurrencyAPITests(InvenTreeAPITestCase): self.assertIn('base_currency', response.data) self.assertIn('exchange_rates', response.data) + + def test_refresh_endpoint(self): + """Call the 'refresh currencies' endpoint""" + + from djmoney.contrib.exchange.models import Rate + + # Delete any existing exchange rate data + Rate.objects.all().delete() + + self.post(reverse('api-currency-refresh')) + + # There should be some new exchange rate objects now + self.assertTrue(Rate.objects.all().exists())