|
5 | 5 | from uuid import uuid4 |
6 | 6 | import pytest |
7 | 7 | from common.block import Block |
8 | | -from common.exceptions import InvalidBlockUUIDError |
| 8 | +from common.exceptions import InvalidBlockUUIDError, InvalidEncodedFragment |
9 | 9 | from common.fragment import APIFragment, Fragment |
10 | 10 | from common.pool import Pool |
11 | 11 | from common.utils import bytes_to_str |
@@ -196,6 +196,26 @@ def test_from_enc_str_success(): |
196 | 196 | assert block._data == bytes.fromhex("00000000000506070809") |
197 | 197 |
|
198 | 198 |
|
| 199 | +def test_from_enc_str_bad_str(): |
| 200 | + """ |
| 201 | + Attempt to create a Fragment from a bad encoded string (invalid encoded string format). |
| 202 | + """ |
| 203 | + # pylint: disable=protected-access |
| 204 | + (pool, block) = _create_test_pool_and_block(10) |
| 205 | + # No colons |
| 206 | + with pytest.raises(InvalidEncodedFragment): |
| 207 | + _fragment = Fragment.from_enc_str("not-an-encoded-str", pool) |
| 208 | + # Only one colon |
| 209 | + with pytest.raises(InvalidEncodedFragment): |
| 210 | + _fragment = Fragment.from_enc_str(f"{block.uuid}:only-one-colon", pool) |
| 211 | + # Start is not a number |
| 212 | + with pytest.raises(InvalidEncodedFragment): |
| 213 | + _fragment = Fragment.from_enc_str(f"{block.uuid}:not-a-number:5", pool) |
| 214 | + # Size is not a number |
| 215 | + with pytest.raises(InvalidEncodedFragment): |
| 216 | + _fragment = Fragment.from_enc_str(f"{block.uuid}:0:not-a-number", pool) |
| 217 | + |
| 218 | + |
199 | 219 | def test_from_enc_str_bad_block_uuid(): |
200 | 220 | """ |
201 | 221 | Attempt to create a Fragment from a bad encoded string (invalid block UUID). |
|
0 commit comments