Exemplo n.º 1
0
def test_add_currency(currency_params):
    currency: CurrencyOutputFields = CurrenciesDAL.add_currency(
        *currency_params)
    assert currency.id == 1
    with create_session() as session:
        currency = session.query(Currency).filter(Currency.id == 1).first()
        assert currency.selling_price == currency_params[1]
        assert currency.purchasing_price == currency_params[2]
Exemplo n.º 2
0
 def get(self, currency_id: str) -> Any:
     request.get_json()
     try:
         currency_id_in_int: int = validate_path_parameter(currency_id)
         return (
             marshal(
                 CurrenciesDAL.get_currency_by_id(currency_id_in_int),
                 currency_output_fields,
             ),
             HTTPStatus.OK,
         )
     except (ValidationException, CurrenciesDALException) as e:
         return marshal({'message': e},
                        error_fields), HTTPStatus.BAD_REQUEST
Exemplo n.º 3
0
 def post(self) -> Any:
     try:
         validated_json = validate_request_json(request.data,
                                                currencies_input_fields)
         return (
             marshal(
                 CurrenciesDAL.add_currency(**validated_json),
                 currency_output_fields,
             ),
             HTTPStatus.CREATED,
         )
     except (ValidationException, CurrenciesDALException) as e:
         return marshal({'message': e},
                        error_fields), HTTPStatus.BAD_REQUEST
Exemplo n.º 4
0
 def get(self) -> Any:
     return CurrenciesDAL.get_currencies()
Exemplo n.º 5
0
 def get(self, currency_id: str):  # type: ignore
     try:
         currency_id_in_int: int = validate_path_parameter(currency_id)
         return CurrenciesDAL.get_currency_history(currency_id_in_int)
     except (ValidationException, CurrenciesDALException) as e:
         abort(HTTPStatus.BAD_REQUEST, e)
Exemplo n.º 6
0
def test_currency_history__with_not_exists_currency():
    with pytest.raises(CurrenciesDALException):
        CurrenciesDAL.get_currency_history(2)
Exemplo n.º 7
0
def test_currency_history_after_adding_currency(currency_params):
    actual: List[AbstractSerialize] = CurrenciesDAL.get_currency_history(1)
    assert len(actual) == 1
    assert actual[0].selling_price == currency_params[1]
    assert actual[0].purchasing_price == currency_params[2]
Exemplo n.º 8
0
def test_add_currency_with_invalid_price(currency_params):
    with pytest.raises(CurrenciesDALException):
        CurrenciesDAL.add_currency('test', Decimal(0), Decimal(0))
Exemplo n.º 9
0
def test_get_currency_with_invalid_id():
    with pytest.raises(CurrenciesDALException):
        CurrenciesDAL.get_currency_by_id(2)
Exemplo n.º 10
0
def test_get_currency_by_id():
    res = CurrenciesDAL.get_currency_by_id(1)
    assert res.id == 1
Exemplo n.º 11
0
def test_get_currencies():
    res = CurrenciesDAL.get_currencies()
    assert len(res) == 1
    assert res[0].id == 1
Exemplo n.º 12
0
def test_add_currency_that_already_exists(currency_params):
    with pytest.raises(CurrenciesDALException):
        CurrenciesDAL.add_currency(*currency_params)
Exemplo n.º 13
0
def _add_currency(currency_params):
    CurrenciesDAL.add_currency(*currency_params)