feat: add cdr validation and normalization domain
This commit is contained in:
71
tests/unit/test_validation.py
Normal file
71
tests/unit/test_validation.py
Normal file
@@ -0,0 +1,71 @@
|
||||
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"
|
||||
Reference in New Issue
Block a user