|
19 | 19 |
|
20 | 20 |
|
21 | 21 | class TestValidateEuid: |
22 | | - """Tests for validate_euid function.""" |
23 | | - |
| 22 | + """Tests for validate_euid function. |
| 23 | +
|
| 24 | + BLOOM EUIDs follow the pattern: PREFIX + SEQUENCE_NUMBER |
| 25 | + - PREFIX: 2-3 uppercase letters identifying object type (e.g., CX, WX, MRX) |
| 26 | + - SEQUENCE_NUMBER: Integer with NO leading zeros |
| 27 | +
|
| 28 | + Valid examples: CX1, CX123, WX1000, MRX42, CWX5 |
| 29 | + """ |
| 30 | + |
24 | 31 | def test_valid_euid(self): |
25 | 32 | """Test validation of valid EUIDs.""" |
26 | | - assert validate_euid("WF_ABC123_X") is True |
27 | | - assert validate_euid("CT_SAMPLE01_Y") is True |
28 | | - assert validate_euid("EQ_DEVICE_Z") is True |
29 | | - |
| 33 | + # Format: 2-3 letter prefix + sequence number (no leading zeros) |
| 34 | + assert validate_euid("CX1") is True |
| 35 | + assert validate_euid("CX123") is True |
| 36 | + assert validate_euid("WX1000") is True |
| 37 | + assert validate_euid("MRX42") is True |
| 38 | + assert validate_euid("CWX5") is True |
| 39 | + |
30 | 40 | def test_none_euid(self): |
31 | 41 | """Test that None raises ValidationError.""" |
32 | 42 | with pytest.raises(ValidationError) as exc_info: |
33 | 43 | validate_euid(None) |
34 | 44 | assert "cannot be None" in str(exc_info.value) |
35 | | - |
| 45 | + |
36 | 46 | def test_empty_euid(self): |
37 | 47 | """Test that empty string raises ValidationError.""" |
38 | 48 | with pytest.raises(ValidationError) as exc_info: |
39 | 49 | validate_euid("") |
40 | 50 | assert "cannot be empty" in str(exc_info.value) |
41 | | - |
| 51 | + |
42 | 52 | def test_non_string_euid(self): |
43 | 53 | """Test that non-string raises ValidationError.""" |
44 | 54 | with pytest.raises(ValidationError) as exc_info: |
45 | 55 | validate_euid(12345) |
46 | 56 | assert "must be a string" in str(exc_info.value) |
47 | | - |
48 | | - def test_no_underscore(self): |
49 | | - """Test that EUID without underscore raises ValidationError.""" |
| 57 | + |
| 58 | + def test_invalid_format_with_separator(self): |
| 59 | + """Test that EUID with separators (underscore/hyphen) raises ValidationError.""" |
50 | 60 | with pytest.raises(ValidationError) as exc_info: |
51 | | - validate_euid("WFABC123X") |
52 | | - assert "underscore" in str(exc_info.value) |
53 | | - |
54 | | - def test_lowercase_prefix(self): |
55 | | - """Test that lowercase prefix raises ValidationError.""" |
| 61 | + validate_euid("WF-123") |
| 62 | + assert "PREFIX + sequence number" in str(exc_info.value) |
| 63 | + |
| 64 | + with pytest.raises(ValidationError) as exc_info: |
| 65 | + validate_euid("WF_123") |
| 66 | + assert "PREFIX + sequence number" in str(exc_info.value) |
| 67 | + |
| 68 | + def test_invalid_format_with_leading_zero(self): |
| 69 | + """Test that EUID with leading zero in sequence raises ValidationError.""" |
56 | 70 | with pytest.raises(ValidationError) as exc_info: |
57 | | - validate_euid("wf_ABC123_X") |
58 | | - assert "uppercase" in str(exc_info.value) |
| 71 | + validate_euid("CX01") |
| 72 | + assert "No leading zeros" in str(exc_info.value) |
59 | 73 |
|
60 | 74 |
|
61 | 75 | class TestValidateUuid: |
@@ -104,33 +118,33 @@ def test_non_dict(self): |
104 | 118 |
|
105 | 119 | class TestValidatedDecorator: |
106 | 120 | """Tests for @validated decorator.""" |
107 | | - |
| 121 | + |
108 | 122 | def test_valid_arguments(self): |
109 | 123 | """Test that valid arguments pass through.""" |
110 | 124 | @validated(euid=validate_euid) |
111 | 125 | def process(euid: str) -> str: |
112 | 126 | return f"processed: {euid}" |
113 | | - |
114 | | - result = process("WF_ABC123_X") |
115 | | - assert result == "processed: WF_ABC123_X" |
116 | | - |
| 127 | + |
| 128 | + result = process("WX123") |
| 129 | + assert result == "processed: WX123" |
| 130 | + |
117 | 131 | def test_invalid_argument_raises(self): |
118 | 132 | """Test that invalid arguments raise ValidationError.""" |
119 | 133 | @validated(euid=validate_euid) |
120 | 134 | def process(euid: str) -> str: |
121 | 135 | return f"processed: {euid}" |
122 | | - |
| 136 | + |
123 | 137 | with pytest.raises(ValidationError): |
124 | | - process("invalid") |
125 | | - |
| 138 | + process("invalid-format") |
| 139 | + |
126 | 140 | def test_multiple_validators(self): |
127 | 141 | """Test multiple validators on different arguments.""" |
128 | 142 | @validated(euid=validate_euid, data=validate_json_addl) |
129 | 143 | def process(euid: str, data: dict) -> dict: |
130 | 144 | return {"euid": euid, "data": data} |
131 | | - |
132 | | - result = process("WF_ABC123_X", {"key": "value"}) |
133 | | - assert result["euid"] == "WF_ABC123_X" |
| 145 | + |
| 146 | + result = process("MRX42", {"key": "value"}) |
| 147 | + assert result["euid"] == "MRX42" |
134 | 148 |
|
135 | 149 |
|
136 | 150 | class TestValidateSchema: |
|
0 commit comments