import pytest @pytest.fixture def example_budget_data(): from superx_budget.budget import BudgetData example = BudgetData( 3, "1.", "Safegurard I", "01.08.2019-31.07.2020", "1100000102", "3210", 5000, 0, 0, ) yield example def test_project_overview_init(example_budget_data): from superx_budget.overview import ProjectOverview over = ProjectOverview(example_budget_data) assert over.budget_data == example_budget_data assert over.entries == [] def test_project_overview_project_property(example_budget_data): from superx_budget.overview import ProjectOverview over = ProjectOverview(example_budget_data) assert over.project == example_budget_data.project def test_project_overview_row_property(example_budget_data): from superx_budget.overview import ProjectOverview over = ProjectOverview(example_budget_data) assert over.row == example_budget_data.row def test_project_overview_add(example_budget_data): from superx_budget.overview import ProjectOverview, OverviewBudgetEntry over = ProjectOverview(example_budget_data) over.add("Sachmittel", "Obligo", -100) over.add("Kleinzeugs", "Ausgaben", 200) assert len(over.entries) == 2 assert isinstance(over.entries[0], OverviewBudgetEntry) assert over.entries[0].description == "Sachmittel" assert over.entries[0].kind == "Obligo" assert over.entries[0].amount == -100 def test_project_overview_expenses_property(example_budget_data): from superx_budget.overview import ProjectOverview over = ProjectOverview(example_budget_data) over.add("Sachmittel", "Obligo", -100) over.add("Kleinzeugs", "Ausgaben", 200) assert over.expenses == 300 def test_project_overview_available_property(example_budget_data): from superx_budget.overview import ProjectOverview over = ProjectOverview(example_budget_data) over.add("Sachmittel", "Obligo", -100) over.add("Kleinzeugs", "Ausgaben", 200) assert over.available == 5000 - 300 def test_create_overview_map(budget_example_file): from superx_budget.budget import parse_budget_file from superx_budget.overview import _create_overview_map budget_data = parse_budget_file(budget_example_file) result = _create_overview_map(budget_data) assert len(result) == 20 assert "1083013701" in result for key, value in result.items(): assert key == str(value.project) def test_create_entries_from_export(budget_example_file, superx_example_file): from superx_budget.budget import parse_budget_file from superx_budget.superx import parse_exported_file from superx_budget.overview import ( _create_overview_map, _create_entries_from_superx, ) superx_data = parse_exported_file(superx_example_file) budget_data = parse_budget_file(budget_example_file) budget_map = _create_overview_map(budget_data) _create_entries_from_superx(budget_map, superx_data.data) expenses = 0.01 + 1000 + 1 + 1001 assert budget_map["1100068704"].available == 2000 - expenses def test_filter_superx_material_expenses(superx_example_file): from superx_budget.superx import parse_exported_file from superx_budget.overview import ( VALID_MATERIAL_IDS, _filter_superx_material_expenses, ) superx_data = parse_exported_file(superx_example_file) result = list(_filter_superx_material_expenses(superx_data)) assert {item.kind for item in result} == VALID_MATERIAL_IDS assert result[0].obligo == 1 assert result[0].expenses == 1001 def test_create_overview(budget_example_file, superx_example_file): from superx_budget.budget import parse_budget_file from superx_budget.superx import parse_exported_file from superx_budget.overview import create_overview superx_data = parse_exported_file(superx_example_file) budget_data = parse_budget_file(budget_example_file) budget_map = create_overview(budget_data, superx_data) assert budget_map["1100068704"].available == 2000 - 1 - 1001