- Implement tests for the internet connections module, covering routes, IP range creation, and connection validation. - Add tests for the Invoice2DataService to validate extraction from GlobalConnect invoices. - Create tests for subscription network provisioning, ensuring proper handling of network items and IP allocations. - Include validation checks for subtotal mismatches and ensure error handling for missing IP selections.
117 lines
3.7 KiB
Python
117 lines
3.7 KiB
Python
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
from app.services.invoice2data_service import Invoice2DataService
|
|
|
|
|
|
def test_globalconnect_parser_extracts_contextual_lines():
|
|
service = Invoice2DataService()
|
|
sample_text = """
|
|
GlobalConnect A/S
|
|
Kundenr. D30190
|
|
Fakturanr. 3016392
|
|
Bilagsdato 1. januar 2026
|
|
Forfaldsdato 1. april 2026
|
|
Kontrakt: 20292
|
|
Vedr: DSL-EB722388
|
|
Metalbuen 26 2750 Ballerup
|
|
Slutkunde: MALERFIRMAET GERT JENSEN ApS VOIP
|
|
Periode: 01-01-2026 - 31-03-2026
|
|
20480/2048 Kbps ADSL forbindelse 3 Stk. 140,00 420,00
|
|
Kontrakt: 20140005-00
|
|
Vedr: IP adresser
|
|
152.115.84.232/29 (NKA-008214)
|
|
Industrivej 7 2605 Brondby
|
|
IPv4 IP-adresser 3 Stk. 64,00 192,00
|
|
I alt DKK ekskl. moms 612,00
|
|
25% moms 153,00
|
|
I alt DKK inkl. moms 765,00
|
|
SE/CVR-nr. 26759722
|
|
29522790
|
|
""".strip()
|
|
|
|
extracted = service.extract_with_template(sample_text, "dk.globalconnect")
|
|
|
|
assert extracted["invoice_number"] == 3016392
|
|
assert extracted["invoice_date"] == "2026-01-01"
|
|
assert extracted["due_date"] == "2026-04-01"
|
|
assert extracted["customer_reference"] == "D30190"
|
|
assert extracted["vendor_vat"] == "26759722"
|
|
assert extracted["amount_total"] == 765.0
|
|
assert len(extracted["lines"]) == 2
|
|
|
|
first_line = extracted["lines"][0]
|
|
assert first_line["provider_reference"] == "DSL-EB722388"
|
|
assert first_line["contract_number"] == "20292"
|
|
assert first_line["end_customer_name"] == "MALERFIRMAET GERT JENSEN ApS VOIP"
|
|
assert first_line["period_start"] == "2026-01-01"
|
|
assert first_line["period_end"] == "2026-03-31"
|
|
|
|
second_line = extracted["lines"][1]
|
|
assert second_line["ip_address"] == "152.115.84.232/29"
|
|
assert second_line["provider_reference"] == "NKA-008214"
|
|
assert second_line["service_address"] == "Industrivej 7, 2605 Brondby"
|
|
|
|
|
|
def test_validation_details_are_added_on_subtotal_mismatch():
|
|
service = Invoice2DataService()
|
|
extracted = {
|
|
"total_amount": 1000.0,
|
|
"vat_amount": 200.0,
|
|
"lines": [
|
|
{"line_total": 500.0},
|
|
{"line_total": 100.0},
|
|
],
|
|
}
|
|
|
|
service._validate_amounts(extracted)
|
|
|
|
assert "_validation_warning" in extracted
|
|
assert extracted["_validation_details"]["line_sum"] == 600.0
|
|
assert extracted["_validation_details"]["subtotal"] == 800.0
|
|
assert extracted["_validation_details"]["difference"] == 200.0
|
|
assert extracted["_validation_details"]["subtotal_matches"] is False
|
|
|
|
|
|
def test_globalconnect_parser_handles_split_address_and_mpls_multiline_context():
|
|
service = Invoice2DataService()
|
|
sample_text = """
|
|
GlobalConnect A/S
|
|
Kundenr. D30190
|
|
Fakturanr. 3018657
|
|
Bilagsdato 1. januar 2026
|
|
Forfaldsdato 1. april 2026
|
|
NKA020900
|
|
Rydagervej 27
|
|
2620 Albertslund
|
|
1 Gbps fiberforbindelse 3 Måneder 1.650,00 4.950,00
|
|
MPLS VPN (layer 3) Serviceaftale Døgn 3 Måneder
|
|
1 Gbps Flatrate internet
|
|
IPv4 IP-adresser 3 Stk. 64,00 192,00
|
|
87.116.1.200/29 (NKA-020900)
|
|
Rydagervej 27
|
|
2620 Albertslund
|
|
I alt DKK ekskl. moms 5.142,00
|
|
25% moms 1.285,50
|
|
I alt DKK inkl. moms 6.427,50
|
|
SE/CVR-nr. 26759722
|
|
29522790
|
|
""".strip()
|
|
|
|
extracted = service.extract_with_template(sample_text, "dk.globalconnect")
|
|
|
|
assert len(extracted["lines"]) == 2
|
|
|
|
connection_line = extracted["lines"][0]
|
|
assert connection_line["provider_reference"] == "NKA020900"
|
|
assert connection_line["service_address"] == "Rydagervej 27, 2620 Albertslund"
|
|
assert "MPLS VPN" in connection_line["description"]
|
|
assert "1 Gbps Flatrate internet" in connection_line["description"]
|
|
|
|
ip_line = extracted["lines"][1]
|
|
assert ip_line["provider_reference"] == "NKA-020900"
|
|
assert ip_line["ip_address"] == "87.116.1.200/29"
|
|
assert ip_line["service_address"] == "Rydagervej 27, 2620 Albertslund"
|