"""Tests for Persister.""" import datetime import decimal from ows_product_physical.constant import field from ows_product_physical.models import persister def test_convert_dates_to_string( monkeypatch, db_fixture, valid_post_product_data): """Assert conversion successful.""" mock_product = { field.RELEASE_DATE: datetime.date(2007, 12, 5), field.SALE_START_DATE: datetime.date(2007, 12, 5), 'any_other_date_field': datetime.date(2016, 11, 1)} response = persister._convert_dates_to_string(mock_product) assert response[field.RELEASE_DATE] == '2007-12-05' assert response[field.SALE_START_DATE] == '2007-12-05' def test_convert_decimal_to_string( monkeypatch, db_fixture, valid_post_product_data): """Assert conversion successful.""" mock_product = { field.WHOLESALE_PRICE: decimal.Decimal('3.14'), 'any_other_decimal_field': decimal.Decimal('1.718')} response = persister._convert_decimal_to_string(mock_product) assert response[field.WHOLESALE_PRICE] == '3.14' assert response['any_other_decimal_field'] == '1.718'