def test_converter(): with raises(CurrencyNotFoundError): convert_currency(5.0, 'test', None) results = convert_currency(5.0, 'GBP', None) assert results['input']['amount'] == 5.0 and results['input']['currency'] == 'GBP' assert isinstance(results['output']['RUB'], float) and isinstance(results['output']['USD'], float) results = convert_currency(10.0, 'GBP', 'RUB') assert results['input']['amount'] == 10.0 and results['input']['currency'] == 'GBP' assert isinstance(results['output']['RUB'], float)
def converter_cli(amount, input_currency, output_currency): try: print(json.dumps(convert_currency(amount, input_currency, output_currency))) except IncorrectInputError as e: print('Please check your input:', str(e)) except Exception as e: print('Unexpected error occurred:', str(e))
def currency_converter(): try: amount = float(request.args.get('amount')) input_currency = request.args.get('input_currency') output_currency = request.args.get('output_currency') results = convert_currency(amount, input_currency, output_currency) return jsonify(results) except IncorrectInputError as e: abort(make_response(jsonify(status="error", error=str(e)), 400)) except Exception as e: abort(make_response(jsonify(status="unexpected_error", error=str(e)), 500))
def api_converter(): amount = request.args.get('amount', '') input_currency = request.args.get('input_currency', '') output_currency = request.args.get('output_currency', None) if len(input_currency) <= 2: input_currency = get_code(input_currency) if output_currency != None: if len(output_currency) <= 2: output_currency = get_code(output_currency) data = { "input": { "amount": amount, "currency": input_currency }, "output": convert_currency(amount, input_currency, output_currency) } return jsonify(data)
def test_convertcurrency(): assert convert_currency(1,"USD","USD") == '1 in USD = 1 in USD' assert convert_currency(1,"INR","INR") == '1 in INR = 1 in INR' assert convert_currency(1,"TTT","USD") == "FROM currency code not found" assert convert_currency(1,"USD","TTT") == "TO currency code not found"
def currency_coefficient(self, new_currency): return convert_currency(self.currency, new_currency, 1)
def currency_converter(self, new_currency): return convert_currency(self.currency, new_currency, self.price)