def test_convert_to_all(self): self.assertEqual( convert_to_all(-1, 'CZK'), error_msg('Error', "Amount has to be a number greater than zero!")) self.assertEqual( convert_to_all(1, 5), error_msg( 'Error', "Entered currency code or symbol not found! " "Mind the upper casing!")) self.assertEqual( convert_to_all(1, 'usd'), error_msg( 'Error', "Entered currency code or symbol not found! " "Mind the upper casing!")) self.assertEqual(convert_to_all(1, '¥'), (convert_to_all(1, 'JPY')))
def get(): amount = request.args.get('amount', type=float) input_currency = request.args.get('input_currency') output_currency = request.args.get('output_currency', default=None) if output_currency is None: return convert_to_all(amount, input_currency) else: return convert_between(amount, input_currency, output_currency)
def test_convert_between(self): self.assertEqual( convert_to_all(-1, 'CZK'), error_msg('Error', "Amount has to be a number greater than zero!")) self.assertEqual( convert_between(1, 5, 'JPY'), error_msg( 'Error', "Entered currency code or symbol not found! " "Mind the upper casing!")) self.assertEqual( convert_between(1, 'CZK', ':'), error_msg( 'Error', "Entered currency code or symbol not found! " "Mind the upper casing!")) self.assertEqual( convert_between(1, 'usd', 'nok'), error_msg( 'Error', "Entered currency code or symbol not found! " "Mind the upper casing!")) self.assertEqual(convert_between(1, 'Kč', 'Nkr'), convert_between(1, 'CZK', 'NOK'))
def get(amount, input_currency, output_currency=None): if output_currency is None: return print(convert_to_all(amount, input_currency)) else: return print(convert_between(amount, input_currency, output_currency))