Skip to content

Instantly share code, notes, and snippets.

@apast
Last active April 9, 2018 11:44
Show Gist options
  • Save apast/84a4a4a98e2a223b836225ae225b5568 to your computer and use it in GitHub Desktop.
Save apast/84a4a4a98e2a223b836225ae225b5568 to your computer and use it in GitHub Desktop.
rates_api = {
"USDBRL": 3.37
}
def get_rate(f, t):
return rates_api[f+t]
class Converter():
def __init__(self, rates):
self.rates = rates
def convert(self, from_currency, from_amount, to_currency):
if from_currency == to_currency:
return from_amount
return get_rate(from_currency, to_currency) * from_amount
import pytest
@pytest.fixture
def ratesdb():
return rates_api
@pytest.fixture
def convert(ratesdb):
return Converter(ratesdb).convert
def test_one_brl_should_return_one_brl(convert):
assert convert(from_currency="BRL", from_amount=0, to_currency="BRL") == 0
assert convert(from_currency="BRL", from_amount=1, to_currency="BRL") == 1
assert convert(from_currency="BRL", from_amount=2, to_currency="BRL") == 2
def test_convert_one_usd_should_return_312_brl(convert, mocker):
mocker.patch("test_converter.get_rate", return_value=3.12)
assert convert(from_currency="USD", from_amount=1, to_currency="BRL") == 3.12
def test_broken_assert():
assert True
def test_coffeebreak():
assert True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment