72 lines
1.8 KiB
Python
72 lines
1.8 KiB
Python
import pytest
|
|
|
|
from core.domain.errors import CDRProcessingError, FailureReason
|
|
from core.domain.validation import parse_raw_cdr
|
|
|
|
|
|
def valid_payload() -> dict:
|
|
return {
|
|
"raw_id": "raw-001",
|
|
"src_ip": "10.240.12.1",
|
|
"device_id": "310410998877665",
|
|
"caller_num": "0019875551234",
|
|
"svc": "4G_DATA",
|
|
"up_bytes": 1048576,
|
|
"down_bytes": 4194304,
|
|
"rat": 6,
|
|
"lac": "4021",
|
|
"ci": "8812",
|
|
"epoch_start": 1726070000,
|
|
"epoch_end": 1726070300,
|
|
}
|
|
|
|
def test_missing_required_field() -> None:
|
|
payload = valid_payload()
|
|
del payload["caller_num"]
|
|
|
|
with pytest.raises(CDRProcessingError) as exc_info:
|
|
parse_raw_cdr(payload)
|
|
|
|
error = exc_info.value
|
|
|
|
assert error.reason == FailureReason.MISSING_REQUIRED_FIELD
|
|
assert error.failed_field == "caller_num"
|
|
|
|
def test_invalid_rat() -> None:
|
|
payload = valid_payload()
|
|
payload["rat"] = 99
|
|
|
|
with pytest.raises(CDRProcessingError) as exc_info:
|
|
parse_raw_cdr(payload)
|
|
|
|
error = exc_info.value
|
|
|
|
assert error.reason == FailureReason.INVALID_RAT_VALUE
|
|
assert error.failed_field == "rat"
|
|
|
|
def test_epoch_start_after_end_is_invalid() -> None:
|
|
payload = valid_payload()
|
|
|
|
payload["epoch_start"] = 200
|
|
payload["epoch_end"] = 100
|
|
|
|
with pytest.raises(CDRProcessingError) as exc_info:
|
|
parse_raw_cdr(payload)
|
|
|
|
error = exc_info.value
|
|
|
|
assert error.reason == FailureReason.INVALID_EPOCH
|
|
|
|
def test_negative_uploaded_bytes_is_invalid() -> None:
|
|
payload = valid_payload()
|
|
|
|
payload["up_bytes"] = -1
|
|
|
|
with pytest.raises(CDRProcessingError) as exc_info:
|
|
parse_raw_cdr(payload)
|
|
|
|
error = exc_info.value
|
|
|
|
assert error.reason == FailureReason.NORMALIZATION_ERROR
|
|
assert error.failed_field == "up_bytes"
|