Exemple #1
0
    def exchange_rate(self, data):
        form = ExchangeForm.from_json(data)
        if not form.validate():
            return -1, str(form.errors), {}

        currency_from = form.data["currency_from"].upper()
        currency_to = form.data["currency_to"].upper()

        if currency_from not in all_currencies():
            return -1, "wrong currency", {}

        if currency_to not in all_currencies():
            return -1, "wrong currency", {}
        times = 0
        while True:
            times += 1
            ex = exchange.rate(currency_from, currency_to)
            if ex or times == 5:
                break
        if not ex:
            return -1, "timeout", {}
        result = {
            "currency_from": currency_from,
            "currency_to": currency_to,
            "rate": str(ex),
        }
        return 0, "success", result
Exemple #2
0
def test_rate_is_none():
    rate = exchange.rate('USD', 'INVID')
    assert rate is None
Exemple #3
0
def test_rate():
    rate = exchange.rate('USD', 'CNY')
    assert rate > 6
    assert rate < 7
Exemple #4
0
def test_rate_is_1():
    assert exchange.rate('USD', 'USD') == 1.00
Exemple #5
0
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 17 01:15:42 2018

@author: actionfocus
"""

import exchange
print exchange.rate('USD', 'CNY')