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
This commit is contained in:
Oliver 2023-02-04 11:17:37 +11:00 committed by GitHub
parent ce3dabedb6
commit 26c97db364
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -154,7 +154,7 @@ class CurrencyRefreshView(APIView):
from InvenTree.tasks import update_exchange_rates from InvenTree.tasks import update_exchange_rates
update_exchange_rates update_exchange_rates()
return Response({ return Response({
'success': 'Exchange rates updated', 'success': 'Exchange rates updated',

View File

@ -912,3 +912,16 @@ class CurrencyAPITests(InvenTreeAPITestCase):
self.assertIn('base_currency', response.data) self.assertIn('base_currency', response.data)
self.assertIn('exchange_rates', 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())