Skip to content

Commit a0d6816

Browse files
author
John Major
committed
fixed tests
1 parent 5b0f733 commit a0d6816

File tree

2 files changed

+61
-37
lines changed

2 files changed

+61
-37
lines changed

tests/test_core_validation.py

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,57 @@
1919

2020

2121
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+
2431
def test_valid_euid(self):
2532
"""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+
3040
def test_none_euid(self):
3141
"""Test that None raises ValidationError."""
3242
with pytest.raises(ValidationError) as exc_info:
3343
validate_euid(None)
3444
assert "cannot be None" in str(exc_info.value)
35-
45+
3646
def test_empty_euid(self):
3747
"""Test that empty string raises ValidationError."""
3848
with pytest.raises(ValidationError) as exc_info:
3949
validate_euid("")
4050
assert "cannot be empty" in str(exc_info.value)
41-
51+
4252
def test_non_string_euid(self):
4353
"""Test that non-string raises ValidationError."""
4454
with pytest.raises(ValidationError) as exc_info:
4555
validate_euid(12345)
4656
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."""
5060
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."""
5670
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)
5973

6074

6175
class TestValidateUuid:
@@ -104,33 +118,33 @@ def test_non_dict(self):
104118

105119
class TestValidatedDecorator:
106120
"""Tests for @validated decorator."""
107-
121+
108122
def test_valid_arguments(self):
109123
"""Test that valid arguments pass through."""
110124
@validated(euid=validate_euid)
111125
def process(euid: str) -> str:
112126
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+
117131
def test_invalid_argument_raises(self):
118132
"""Test that invalid arguments raise ValidationError."""
119133
@validated(euid=validate_euid)
120134
def process(euid: str) -> str:
121135
return f"processed: {euid}"
122-
136+
123137
with pytest.raises(ValidationError):
124-
process("invalid")
125-
138+
process("invalid-format")
139+
126140
def test_multiple_validators(self):
127141
"""Test multiple validators on different arguments."""
128142
@validated(euid=validate_euid, data=validate_json_addl)
129143
def process(euid: str, data: dict) -> dict:
130144
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"
134148

135149

136150
class TestValidateSchema:

tests/test_schemas.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,31 @@ def test_pagination_params(self):
2727
assert params_default.page_size == 50
2828

2929
def test_euid_validation(self):
30-
"""Test EUID validation function."""
30+
"""Test EUID validation function.
31+
32+
BLOOM EUIDs follow the pattern: PREFIX + SEQUENCE_NUMBER
33+
- PREFIX: 2-3 uppercase letters (e.g., CX, WX, MRX)
34+
- SEQUENCE_NUMBER: Integer with NO leading zeros
35+
36+
Valid examples: CX1, CX123, WX1000, MRX42
37+
"""
3138
from bloom_lims.schemas import validate_euid
3239

33-
# Valid EUIDs (format: PREFIX-IDENTIFIER or PREFIX-IDENTIFIER-SUFFIX)
34-
assert validate_euid("BLM-123456") == "BLM-123456"
35-
assert validate_euid(" BLM-123456 ") == "BLM-123456"
36-
assert validate_euid("CONT-12345-A1") == "CONT-12345-A1"
40+
# Valid EUIDs (format: PREFIX + sequence number)
41+
assert validate_euid("CX1") == "CX1"
42+
assert validate_euid("CX123") == "CX123"
43+
assert validate_euid(" wx1000 ") == "WX1000" # Should uppercase and strip
44+
assert validate_euid("MRX42") == "MRX42"
3745

3846
# Invalid EUIDs
3947
with pytest.raises(ValueError):
4048
validate_euid("")
4149
with pytest.raises(ValueError):
4250
validate_euid(" ")
4351
with pytest.raises(ValueError):
44-
validate_euid("INVALID") # No hyphen
52+
validate_euid("BLM-123456") # Hyphens not allowed
53+
with pytest.raises(ValueError):
54+
validate_euid("CX01") # Leading zeros not allowed
4555

4656

4757
class TestObjectSchemas:
@@ -83,7 +93,7 @@ def test_container_create_schema(self):
8393
name="Test Plate",
8494
container_type="plate",
8595
b_sub_type="96-well",
86-
template_euid="CONT-123456",
96+
template_euid="CT123456", # Valid EUID format: PREFIX + sequence number
8797
)
8898
assert data.name == "Test Plate"
8999
assert data.container_type == "plate"
@@ -139,7 +149,7 @@ def test_workflow_create_schema(self):
139149
data = WorkflowCreateSchema(
140150
name="Test Workflow",
141151
workflow_type="sequencing",
142-
template_euid="WF-123456",
152+
template_euid="WF123456", # Valid EUID format: PREFIX + sequence number
143153
)
144154
assert data.name == "Test Workflow"
145155

0 commit comments

Comments
 (0)