This commit is contained in:
Mateusz Gruszczyński
2026-08-02 00:19:34 +02:00
parent 5299a7fc66
commit 84ceb23316
7 changed files with 299 additions and 38 deletions
+143
View File
@@ -362,3 +362,146 @@ def test_last_price_zero_and_full_vat_deduction():
from app.domain.costs import calculate_net_price_costs
assert round(float(calculate_net_price_costs(10, 23, 0)["effective_cost"]), 2) == 12.30
assert round(float(calculate_net_price_costs(10, 23, 100)["effective_cost"]), 2) == 10.00
def test_fuel_entry_edit_modal_uses_scrollable_bootstrap_structure(tmp_path):
app = make_app(tmp_path, "fuel-entry-modal.db")
client = app.test_client()
client.post('/login', data={'email': 'admin@example.com', 'password': 'admin123!'})
html = client.get('/admin/fuel-entries').get_data(as_text=True)
assert (
'modal-dialog modal-lg modal-dialog-scrollable">'
'<form id="fuel-entry-edit-form" class="modal-content ajax-form"'
in html
)
assert '<div class="modal-content"><form id="fuel-entry-edit-form"' not in html
def test_orlen_incremental_sync_starts_at_latest_saved_record(tmp_path, monkeypatch):
from datetime import date
from decimal import Decimal
from app.extensions import db
from app.models import OrlenPrice
from app.orlen_sync import sync_orlen_prices
import app.orlen_sync as orlen_sync_module
app = make_app(tmp_path, "orlen-incremental.db")
calls = []
def fake_fetch(fuel, date_from, date_to, region):
calls.append((fuel, date_from, date_to, region))
return []
monkeypatch.setattr(orlen_sync_module, 'fetch_orlen_range', fake_fetch)
with app.app_context():
db.session.add_all([
OrlenPrice(fuel_type='PB95', effective_date=date(2026, 1, 2), price_per_liter=Decimal('4.1000'), raw_value=Decimal('4100'), region='', product_name='PB95', source='test'),
OrlenPrice(fuel_type='PB95', effective_date=date(2026, 7, 15), price_per_liter=Decimal('4.5000'), raw_value=Decimal('4500'), region='', product_name='PB95', source='test'),
])
db.session.commit()
result, total = sync_orlen_prices(
fuels=['PB95'],
year=2026,
regions=[],
default_region='mazowieckie',
full_refresh=False,
today=date(2026, 8, 2),
)
assert calls == [('PB95', date(2026, 7, 15), date(2026, 8, 2), 'mazowieckie')]
assert result['PB95']['from'] == '2026-07-15'
assert result['PB95']['full_refresh'] is False
assert total == 0
def test_orlen_full_refresh_starts_at_beginning_of_selected_year(tmp_path, monkeypatch):
from datetime import date
from decimal import Decimal
from app.extensions import db
from app.models import OrlenPrice
from app.orlen_sync import sync_orlen_prices
import app.orlen_sync as orlen_sync_module
app = make_app(tmp_path, "orlen-full-refresh.db")
calls = []
def fake_fetch(fuel, date_from, date_to, region):
calls.append((fuel, date_from, date_to, region))
return []
monkeypatch.setattr(orlen_sync_module, 'fetch_orlen_range', fake_fetch)
with app.app_context():
db.session.add(OrlenPrice(fuel_type='DIESEL', effective_date=date(2026, 7, 20), price_per_liter=Decimal('4.9000'), raw_value=Decimal('4900'), region='', product_name='DIESEL', source='test'))
db.session.commit()
result, _ = sync_orlen_prices(
fuels=['DIESEL'],
year=2026,
regions=[],
default_region='mazowieckie',
full_refresh=True,
today=date(2026, 8, 2),
)
assert calls == [('DIESEL', date(2026, 1, 1), date(2026, 8, 2), 'mazowieckie')]
assert result['DIESEL']['from'] == '2026-01-01'
assert result['DIESEL']['full_refresh'] is True
def test_orlen_lpg_incremental_sync_uses_oldest_latest_region_date(tmp_path, monkeypatch):
from datetime import date
from decimal import Decimal
from app.extensions import db
from app.models import OrlenPrice
from app.orlen_sync import sync_orlen_prices
import app.orlen_sync as orlen_sync_module
app = make_app(tmp_path, "orlen-lpg-incremental.db")
calls = []
def fake_fetch(fuel, date_from, date_to, region):
calls.append((fuel, date_from, date_to, region))
return [
{'fuel_type': 'LPG', 'effective_date': date(2026, 8, 1), 'price_per_liter': Decimal('2.1000'), 'raw_value': Decimal('2.1000'), 'region': 'mazowieckie', 'product_name': 'LPG', 'source': 'test'},
{'fuel_type': 'LPG', 'effective_date': date(2026, 8, 1), 'price_per_liter': Decimal('2.2000'), 'raw_value': Decimal('2.2000'), 'region': 'pomorskie', 'product_name': 'LPG', 'source': 'test'},
]
monkeypatch.setattr(orlen_sync_module, 'fetch_orlen_range', fake_fetch)
with app.app_context():
db.session.add_all([
OrlenPrice(fuel_type='LPG', effective_date=date(2026, 7, 20), price_per_liter=Decimal('2.0000'), raw_value=Decimal('2.0000'), region='mazowieckie', product_name='LPG', source='test'),
OrlenPrice(fuel_type='LPG', effective_date=date(2026, 7, 25), price_per_liter=Decimal('2.0000'), raw_value=Decimal('2.0000'), region='śląskie', product_name='LPG', source='test'),
])
db.session.commit()
result, total = sync_orlen_prices(
fuels=['LPG'],
year=2026,
regions=['mazowieckie', 'śląskie'],
default_region='mazowieckie',
full_refresh=False,
today=date(2026, 8, 2),
)
db.session.commit()
assert OrlenPrice.query.filter_by(fuel_type='LPG', region='pomorskie').count() == 0
assert calls == [('LPG', date(2026, 7, 20), date(2026, 8, 2), 'all')]
assert result['LPG']['from'] == '2026-07-20'
assert total == 1
def test_orlen_page_has_incremental_and_full_refresh_controls(tmp_path):
app = make_app(tmp_path, "orlen-sync-ui.db")
client = app.test_client()
client.post('/login', data={'email': 'admin@example.com', 'password': 'admin123!'})
html = client.get('/orlen?mode=history').get_data(as_text=True)
assert 'id="orlen-sync-btn"' in html
assert 'Pobierz nowe dane' in html
assert 'id="orlen-full-sync-btn"' in html
assert 'Pobierz cały wybrany rok ponownie' in html