86 lines
2.2 KiB
Python
86 lines
2.2 KiB
Python
"""Unit tests for memberdata utility functions.
|
|
|
|
Replaces test/memberdata_datum.js, test/memberdata_datum_parsed.js,
|
|
test/memberdata_patenarray.js, test/memberdata_realstatus.js.
|
|
"""
|
|
|
|
import pytest
|
|
from cteward_ng.memberdata import (
|
|
realstatus,
|
|
datum,
|
|
datum_parsed,
|
|
patenarray,
|
|
cleanpaten,
|
|
)
|
|
|
|
|
|
class TestDatum:
|
|
def test_valid_yyyy_mmdd(self):
|
|
assert datum('20230115') == '15.1.2023'
|
|
|
|
def test_invalid_length(self):
|
|
assert datum('2023011') == '1.1.1970'
|
|
|
|
def test_not_a_string(self):
|
|
assert datum(12345) == '1.1.1970'
|
|
|
|
def test_invalid_format(self):
|
|
assert datum('notadate') == '1.1.1970'
|
|
|
|
def test_empty_string(self):
|
|
assert datum('') == '1.1.1970'
|
|
|
|
|
|
class TestDatumParsed:
|
|
def test_iso_format(self):
|
|
result = datum_parsed('2023-01-15T00:00:00.000Z')
|
|
assert '2023' in result
|
|
|
|
def test_invalid(self):
|
|
assert datum_parsed('not-a-date') == '1.1.1970'
|
|
|
|
|
|
class TestPatenarray:
|
|
def test_single_name(self):
|
|
assert patenarray('Alice') == ['Alice']
|
|
|
|
def test_multiple_names(self):
|
|
assert patenarray('Alice, Bob, Charlie') == ['Alice', 'Bob', 'Charlie']
|
|
|
|
def test_empty_string(self):
|
|
assert patenarray('') == []
|
|
|
|
def test_none(self):
|
|
assert patenarray(None) == []
|
|
|
|
def test_whitespace_handling(self):
|
|
assert patenarray(' Alice , Bob ') == ['Alice', 'Bob']
|
|
|
|
def test_empty_entries(self):
|
|
assert patenarray('Alice,,Bob') == ['Alice', 'Bob']
|
|
|
|
|
|
class TestCleanpaten:
|
|
def test_clean_and_rejoin(self):
|
|
assert cleanpaten(' Alice , Bob , Charlie ') == 'Alice,Bob,Charlie'
|
|
|
|
|
|
class TestRealstatus:
|
|
def test_none_raises(self):
|
|
with pytest.raises(TypeError):
|
|
realstatus(None)
|
|
|
|
def test_default_to_crew(self):
|
|
assert realstatus({}) == 'crew'
|
|
|
|
def test_explicit_crew(self):
|
|
assert realstatus({'Kennung3': 'crew'}) == 'crew'
|
|
|
|
def test_raumfahrer(self):
|
|
assert realstatus({'Kennung3': 'raumfahrer'}) == 'raumfahrer'
|
|
|
|
def test_passiv(self):
|
|
assert realstatus({'Kennung3': 'passiv'}) == 'passiv'
|
|
|
|
def test_disabled_prefix(self):
|
|
assert realstatus({'Kurzname': 'disabled-someone'}) == 'ex-crew'
|