aboutsummaryrefslogtreecommitdiffstats
path: root/python_moonutilities/tests/unit_python/test_validated_input.py
blob: c8e681e99d9dca67ba138932e0d9e62e733809f3 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import pytest


def test_valid_string():
    from python_moonutilities.security_functions import validate_data
    validate_data("CorrectString")

def test_unvalid_string():
    from python_moonutilities.security_functions import validate_data
    with pytest.raises(Exception) as exception_info:
        validate_data("Notcorrect String")

    assert str(exception_info.value) == 'String contains space'

def test_empty_string():
    from python_moonutilities.security_functions import validate_data
    with pytest.raises(Exception) as exception_info:
        validate_data("")

    assert str(exception_info.value) == 'Empty String'


def test_none_value():
    from python_moonutilities.security_functions import validate_data
    with pytest.raises(Exception) as exception_info:
        validate_data(None)

    assert str(exception_info.value) == 'Value is Not String or Container or Dictionary'


def test_int_value():
    from python_moonutilities.security_functions import validate_data
    with pytest.raises(Exception) as exception_info:
        validate_data(1)

    assert str(exception_info.value) == 'Value is Not String or Container or Dictionary'


def test_float_value():
    from python_moonutilities.security_functions import validate_data
    with pytest.raises(Exception) as exception_info:
        validate_data(1.23)

    assert str(exception_info.value) == 'Value is Not String or Container or Dictionary'


def test_correct_list():
    from python_moonutilities.security_functions import validate_data
    validate_data(["skjdnfa","dao","daosdjpw"])


def test_correct_list():
    from python_moonutilities.security_functions import validate_data
    validate_data(["skjdnfa"])


def test_correct_instead_list():
    from python_moonutilities.security_functions import validate_data
    validate_data([["skjdnfa","daswi"],[["daskdlw"],["daklwo"]],["dawl","afioa"],["dawno"]])


def test_empty_list():
    from python_moonutilities.security_functions import validate_data
    with pytest.raises(Exception) as exception_info:
        validate_data([])

    assert str(exception_info.value) == 'Empty Container'


def test_empty_list_inside_other_list():
    from python_moonutilities.security_functions import validate_data
    with pytest.raises(Exception) as exception_info:
        validate_data(["dajiwdj",[]])

    assert str(exception_info.value) == 'Empty Container'


def test_incorrect_string_inside_list():
    from python_moonutilities.security_functions import validate_data
    with pytest.raises(Exception) as exception_info:
        validate_data(["dajiwdj",["dakwe","daow awoepa"]])

    assert str(exception_info.value) == 'String contains space'


def test_empty_string_inside_list():
    from python_moonutilities.security_functions import validate_data
    with pytest.raises(Exception) as exception_info:
        validate_data(["dajiwdj", ["dakwe", ""]])

    assert str(exception_info.value) == 'Empty String'


def test_correct_tuples():
    from python_moonutilities.security_functions import validate_data
    validate_data(("dasdw","dawdwa"))


def test_empty_tuples():
    from python_moonutilities.security_functions import validate_data
    with pytest.raises(Exception) as exception_info:
        validate_data(())

    assert str(exception_info.value) == 'Empty Container'

def test_correct_tuple_of_tuple():
    from python_moonutilities.security_functions import validate_data
    validate_data(("gjosjefa",("diwajdi","oejfoea"),(("jwdi","fjia"),("nfioa","ifao"))))


def test_incorrect_tuple():
    from python_moonutilities.security_functions import validate_data
    with pytest.raises(Exception) as exception_info:
        validate_data(("djawo","dowa afw"))

    assert str(exception_info.value) == 'String contains space'


def test_correct_dictionary():
    from python_moonutilities.security_functions import validate_data
    validate_data({"daiwdw":"dwioajd"})


def test_incorrect_dictionary():
    from python_moonutilities.security_functions import validate_data
    with pytest.raises(Exception) as exception_info:
        validate_data({"daiwdw":"dwioa jd"})

    assert str(exception_info.value) == 'String contains space'

def test_empty_dictionary():
    from python_moonutilities.security_functions import validate_data
    with pytest.raises(Exception) as exception_info:
        validate_data({})

    assert str(exception_info.value) == 'Empty Dictionary'


def test_correct_function_pass():
    from python_moonutilities.security_functions import validate_input

    @validate_input()
    def temp_function(string,list,tuple):
        if string!="teststring" :
            raise ValueError("values which passed incorrect")

    temp_function("teststring",["teststring",["teststring"]],("teststring",("teststring")))

def test_incorrect_function_pass1():
    from python_moonutilities.security_functions import validate_input

    @validate_input()
    def temp_function(string, list, tuple):
        if string != "teststring":
            raise ValueError("values which passed incorrect")

    with pytest.raises(Exception) as exception_info:
        temp_function("teststring",list=["teststring", ["testst ring"]],tuple=("teststring", ("teststri ng")))

    assert str(exception_info.value) == 'String contains space'


def test_incorrect_function_pass2():
    from python_moonutilities.security_functions import validate_input

    @validate_input()
    def temp_function(string, list, dictionary):
        if string != "teststring":
            raise ValueError("values which passed incorrect")

    with pytest.raises(Exception) as exception_info:
        temp_function("teststring", ["teststring", ["teststri ng"]], {"teststring": ("teststring")})

    assert str(exception_info.value) == 'String contains space'


def test_incorrect_function_pass3():
    from python_moonutilities.security_functions import validate_input

    class x:
        @validate_input()
        def temp_function(string, list, dictionary):
            if string != "teststring":
                raise ValueError("values which passed incorrect")

    e=x;

    with pytest.raises(Exception) as exception_info:
        e.temp_function("teststring", ["teststring", ["teststri ng"]], {"teststring": ("teststring")})

    assert str(exception_info.value) == 'String contains space'