Exemplo n.º 1
0
 def test_get_currency_conversion_rates_successful(self, mock_requests):
     beforeRows = ExchangeRates.objects.count()
     self.assertEqual(beforeRows, 0)
     mock_requests.get.return_value = Mock(
         status_code=201, json=lambda: {"result": "success", "rates": {"AUD": 1.37, "CAD": 1.25, "CHF": 0.928}}
     )
     tasks.get_daily_currency_rates()
     afterRows = ExchangeRates.objects.count()
     self.assertEqual(afterRows, 3)
Exemplo n.º 2
0
def update_exchange_rates(request):
    """Return updated exchange rates."""
    exchange_result = get_daily_currency_rates()
    return Response({"updated_exchange_rates": exchange_result})
Exemplo n.º 3
0
 def test_error_get_currency_conversion_rates(self, mock_requests):
     mock_requests.get.side_effect = Exception("error")
     with self.assertRaises(Exception) as e:
         tasks.get_daily_currency_rates()
         self.assertIn("Couldn't pull latest conversion rates", str(e.exception))
Exemplo n.º 4
0
 def test_get_currency_conversion_rates(self):
     with self.assertLogs("masu.celery.tasks", "INFO") as captured_logs:
         tasks.get_daily_currency_rates()
         self.assertIn("Creating the exchange rate" or "Updating currency", str(captured_logs))