File size: 1,366 Bytes
819c9a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import sys
import pytest

sys.path.insert(0, ".")
from validators import _validate_target, _validate_selection, _validate_sources


class TestValidateTarget:
    def test_empty_string_raises(self):
        with pytest.raises(Exception):
            _validate_target("")

    def test_null_string_raises(self):
        with pytest.raises(Exception):
            _validate_target("null")

    def test_whitespace_only_raises(self):
        with pytest.raises(Exception):
            _validate_target("   ")

    def test_valid_string_does_not_raise(self):
        _validate_target("data:image/jpeg;base64,abc")


class TestValidateSelection:
    def test_empty_list_raises(self):
        with pytest.raises(Exception):
            _validate_selection([])

    def test_non_empty_does_not_raise(self):
        _validate_selection([0])
        _validate_selection([0, 2, 5])


class TestValidateSources:
    def test_missing_source_raises(self):
        with pytest.raises(Exception):
            _validate_sources([0, 1], {"0": "data:..."})

    def test_empty_source_raises(self):
        with pytest.raises(Exception):
            _validate_sources([0], {"0": ""})

    def test_all_present_does_not_raise(self):
        _validate_sources([0, 1], {"0": "data:...", "1": "data:..."})

    def test_none_selected_does_not_raise(self):
        _validate_sources([], {})