Esempio n. 1
0
def test_encode_randomness_raises_on_bytes_length_mismatch(invalid_bytes_80):
    """
    Assert that :func:`~ulid.base32.encode_randomness` raises a :class:`~ValueError` when given a :class:`~bytes`
    instance that is not exactly 80 bit.
    """
    with pytest.raises(ValueError) as ex:
        base32.encode_randomness(invalid_bytes_80)
    assert ex.match(ENCODE_RANDOMNESS_BYTE_SIZE_EXC_REGEX)
Esempio n. 2
0
def test_encode_randomness_returns_16_char_string(valid_bytes_80):
    """
    Assert that :func:`~ulid.base32.encode_randomness` encodes a valid 80 bit bytes object into a :class:`~str`
    that is 16 characters long.
    """
    encoded = base32.encode_randomness(valid_bytes_80)
    assert isinstance(encoded, str)
    assert len(encoded) == 16
Esempio n. 3
0
def test_decode_randomness_str_returns_randomness_instance(valid_bytes_80):
    """
    Assert that :func:`~ulid.codec.decode_randomness` returns a new :class:`~ulid.ulid.Randomness` instance
    from the given random values as an :class:`~str`.
    """
    value = base32.encode_randomness(valid_bytes_80)
    instance = codec.decode_randomness(value)
    assert isinstance(instance, ulid.Randomness)
    assert instance.str == value
Esempio n. 4
0
def test_from_randomness_str_returns_ulid_instance(valid_bytes_80):
    """
    Assert that :func:`~ulid.api.from_randomness` returns a new :class:`~ulid.ulid.ULID` instance
    from the given random values as an :class:`~str`.
    """
    value = base32.encode_randomness(valid_bytes_80)
    instance = api.from_randomness(value)
    assert isinstance(instance, ulid.ULID)
    assert instance.randomness().str == value
Esempio n. 5
0
def test_parse_returns_ulid_instance_from_randomness_str(valid_bytes_80):
    """
    Assert that :func:`~ulid.api.parse` returns a new :class:`~ulid.ulid.ULID` instance
    from the given :class:`~str` instance that represents randomness data.
    """
    value = base32.encode_randomness(valid_bytes_80)
    instance = api.parse(value)
    assert isinstance(instance, ulid.ULID)
    assert instance.randomness().str == value