askrobots / dbbasic-object-server
Public
Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
danq9
signup: the person chooses the password and name on the confirm page
83c7aa6
2 weeks, 5 days ago
History
test_object_correlation.py · 1.2 KB · 36 lines
| 1 | from uuid import UUID |
| 2 | |
| 3 | import object_correlation |
| 4 | |
| 5 | |
| 6 | def test_new_correlation_id_returns_uuid4_string(): |
| 7 | correlation_id = object_correlation.new_correlation_id() |
| 8 | |
| 9 | parsed = UUID(correlation_id) |
| 10 | assert parsed.version == 4 |
| 11 | assert str(parsed) == correlation_id |
| 12 | |
| 13 | |
| 14 | def test_normalize_correlation_id_accepts_only_uuid4_values(): |
| 15 | valid = "123e4567-e89b-42d3-a456-426614174000" |
| 16 | |
| 17 | assert object_correlation.normalize_correlation_id(valid.upper()) == valid |
| 18 | assert object_correlation.normalize_correlation_id("") is None |
| 19 | assert object_correlation.normalize_correlation_id("not-a-uuid") is None |
| 20 | assert ( |
| 21 | object_correlation.normalize_correlation_id("123e4567-e89b-12d3-a456-426614174000") |
| 22 | is None |
| 23 | ) |
| 24 | |
| 25 | |
| 26 | def test_correlation_context_can_be_set_and_reset(): |
| 27 | correlation_id = "123e4567-e89b-42d3-a456-426614174000" |
| 28 | |
| 29 | assert object_correlation.current_correlation_id() is None |
| 30 | token = object_correlation.set_current_correlation_id(correlation_id) |
| 31 | try: |
| 32 | assert object_correlation.current_correlation_id() == correlation_id |
| 33 | finally: |
| 34 | object_correlation.reset_current_correlation_id(token) |
| 35 | |
| 36 | assert object_correlation.current_correlation_id() is None |