Tests

test_calculator

Tests for math functions.

test_division_1()

Test 1 division()

Source code in tests/test_calculator.py
135
136
137
138
139
140
141
def test_division_1():
    """
    Test 1 division()
    """
    with pytest.raises(ZeroDivisionError) as excinfo:
        Calculator.division(1, 0)
    assert str(excinfo.value) == "Division by 0 not allowed!"

test_division_2()

Test 2 division()

Source code in tests/test_calculator.py
144
145
146
147
148
def test_division_2():
    """
    Test 2 division()
    """
    assert Calculator.division(10, 2) == 5

test_division_3()

Test 3 division()

Source code in tests/test_calculator.py
151
152
153
154
155
def test_division_3():
    """
    Test 3 division()
    """
    assert Calculator.division(-4, 2) == -2

test_division_4()

Test 4 division()

Source code in tests/test_calculator.py
158
159
160
161
162
def test_division_4():
    """
    Test 4 division()
    """
    assert Calculator.division(-20, -5) == 4

test_division_5()

Test 5 for division()

Source code in tests/test_calculator.py
165
166
167
168
169
170
171
172
173
174
def test_division_5():
    """
    Test 5 for division()
    """
    with pytest.raises(DivisionError):
        Calculator.division("1", 2)
    with pytest.raises(DivisionError):
        Calculator.division(2, "1")
    with pytest.raises(DivisionError):
        Calculator.division("1", "2")

test_multiplicacion_1()

Test 1 for multiplicacion()

Source code in tests/test_calculator.py
95
96
97
98
99
def test_multiplicacion_1():
    """
    Test 1 for multiplicacion()
    """
    assert Calculator.multiplicacion(0, 0) == 0

test_multiplicacion_2()

Test 2 for multiplicacion()

Source code in tests/test_calculator.py
102
103
104
105
106
def test_multiplicacion_2():
    """
    Test 2 for multiplicacion()
    """
    assert Calculator.multiplicacion(2, 1) == 2

test_multiplicacion_3()

Test 3 for multiplicacion()

Source code in tests/test_calculator.py
109
110
111
112
113
def test_multiplicacion_3():
    """
    Test 3 for multiplicacion()
    """
    assert Calculator.multiplicacion(2, -2) == -4

test_multiplicacion_4()

Test 4 for multiplicacion()

Source code in tests/test_calculator.py
116
117
118
119
120
def test_multiplicacion_4():
    """
    Test 4 for multiplicacion()
    """
    assert Calculator.multiplicacion(-3, -3) == 9

test_multiplicacion_5()

Test 5 for multiplicacion()

Source code in tests/test_calculator.py
123
124
125
126
127
128
129
130
131
132
def test_multiplicacion_5():
    """
    Test 5 for multiplicacion()
    """
    with pytest.raises(MultiplicationError):
        Calculator.multiplicacion("1", 2)
    with pytest.raises(MultiplicationError):
        Calculator.multiplicacion(2, "1")
    with pytest.raises(MultiplicationError):
        Calculator.multiplicacion("1", "2")

test_resta_1()

Test 1 for resta()

Source code in tests/test_calculator.py
55
56
57
58
59
def test_resta_1():
    """
    Test 1 for resta()
    """
    assert Calculator.resta(1, 1) == 0

test_resta_2()

Test 2 for resta()

Source code in tests/test_calculator.py
62
63
64
65
66
def test_resta_2():
    """
    Test 2 for resta()
    """
    assert Calculator.resta(-1, -1) == 0

test_resta_3()

Test 3 for resta()

Source code in tests/test_calculator.py
69
70
71
72
73
def test_resta_3():
    """
    Test 3 for resta()
    """
    assert Calculator.resta(-1, 1) == -2

test_resta_4()

Test 4 for resta()

Source code in tests/test_calculator.py
76
77
78
79
80
def test_resta_4():
    """
    Test 4 for resta()
    """
    assert Calculator.resta(0, 0) == 0

test_resta_5()

Test 5 for resta()

Source code in tests/test_calculator.py
83
84
85
86
87
88
89
90
91
92
def test_resta_5():
    """
    Test 5 for resta()
    """
    with pytest.raises(SubstractionError):
        Calculator.resta("1", 2)
    with pytest.raises(SubstractionError):
        Calculator.resta(2, "1")
    with pytest.raises(SubstractionError):
        Calculator.resta("1", "2")

test_suma_1()

Test 1 for suma()

Source code in tests/test_calculator.py
15
16
17
18
19
def test_suma_1():
    """
    Test 1 for suma()
    """
    assert Calculator.suma(1, 1) == 2

test_suma_2()

Test 2 for suma()

Source code in tests/test_calculator.py
22
23
24
25
26
def test_suma_2():
    """
    Test 2 for suma()
    """
    assert Calculator.suma(-1, -1) == -2

test_suma_3()

Test 3 for suma()

Source code in tests/test_calculator.py
29
30
31
32
33
def test_suma_3():
    """
    Test 3 for suma()
    """
    assert Calculator.suma(-1, 1) == 0

test_suma_4()

Test 4 for suma()

Source code in tests/test_calculator.py
36
37
38
39
40
def test_suma_4():
    """
    Test 4 for suma()
    """
    assert Calculator.suma(0, 0) == 0

test_suma_5()

Test 5 for suma()

Source code in tests/test_calculator.py
43
44
45
46
47
48
49
50
51
52
def test_suma_5():
    """
    Test 5 for suma()
    """
    with pytest.raises(AdditionError):
        Calculator.suma("1", 2)
    with pytest.raises(AdditionError):
        Calculator.suma(2, "1")
    with pytest.raises(AdditionError):
        Calculator.suma("1", "2")

test_endpoints_calculator

Tests for calculator api endpoints.

test_calculator_addition_1()

Test /calculator/addition/ endpoint

Source code in tests/test_endpoints_calculator.py
11
12
13
14
15
16
17
def test_calculator_addition_1():
    """
    Test /calculator/addition/ endpoint
    """
    response: TestClient = client.get("/calculator/addition/?a=5&b=4")
    assert response.status_code == 200
    assert response.json() == {"result": 9.0}

test_calculator_addition_2()

Test /calculator/addition/ endpoint

Source code in tests/test_endpoints_calculator.py
20
21
22
23
24
25
26
def test_calculator_addition_2():
    """
    Test /calculator/addition/ endpoint
    """
    response: TestClient = client.get("/calculator/addition/?a=5&b=-5")
    assert response.status_code == 200
    assert response.json() == {"result": 0.0}

test_calculator_addition_3()

Test /calculator/addition/ endpoint

Source code in tests/test_endpoints_calculator.py
29
30
31
32
33
34
35
def test_calculator_addition_3():
    """
    Test /calculator/addition/ endpoint
    """
    response: TestClient = client.get("/calculator/addition/?a=-5&b=4")
    assert response.status_code == 200
    assert response.json() == {"result": -1.0}

test_calculator_divide_1()

Test /calculator/divide/ endpoint

Source code in tests/test_endpoints_calculator.py
38
39
40
41
42
43
44
def test_calculator_divide_1():
    """
    Test /calculator/divide/ endpoint
    """
    response: TestClient = client.get("/calculator/divide/?a=4&b=2")
    assert response.status_code == 200
    assert response.json() == {"result": 2.0}

test_calculator_divide_2()

Test /calculator/divide/ endpoint

Source code in tests/test_endpoints_calculator.py
47
48
49
50
51
52
53
def test_calculator_divide_2():
    """
    Test /calculator/divide/ endpoint
    """
    response: TestClient = client.get("/calculator/divide/?a=4&b=4")
    assert response.status_code == 200
    assert response.json() == {"result": 1.0}

test_calculator_divide_3()

Test /calculator/divide/ endpoint

Source code in tests/test_endpoints_calculator.py
56
57
58
59
60
61
62
def test_calculator_divide_3():
    """
    Test /calculator/divide/ endpoint
    """
    response: TestClient = client.get("/calculator/divide/?a=-4&b=2")
    assert response.status_code == 200
    assert response.json() == {"result": -2.0}

test_calculator_multiply_1()

Test /calculator/multiply/ endpoint

Source code in tests/test_endpoints_calculator.py
65
66
67
68
69
70
71
def test_calculator_multiply_1():
    """
    Test /calculator/multiply/ endpoint
    """
    response: TestClient = client.get("/calculator/multiply/?a=2&b=2")
    assert response.status_code == 200
    assert response.json() == {"result": 4.0}

test_calculator_multiply_2()

Test /calculator/multiply/ endpoint

Source code in tests/test_endpoints_calculator.py
74
75
76
77
78
79
80
def test_calculator_multiply_2():
    """
    Test /calculator/multiply/ endpoint
    """
    response: TestClient = client.get("/calculator/multiply/?a=2&b=-2")
    assert response.status_code == 200
    assert response.json() == {"result": -4.0}

test_calculator_multiply_3()

Test /calculator/multiply/ endpoint

Source code in tests/test_endpoints_calculator.py
83
84
85
86
87
88
89
def test_calculator_multiply_3():
    """
    Test /calculator/multiply/ endpoint
    """
    response: TestClient = client.get("/calculator/multiply/?a=1&b=2")
    assert response.status_code == 200
    assert response.json() == {"result": 2.0}

test_calculator_substract_1()

Test /calculator/substract/ endpoint

Source code in tests/test_endpoints_calculator.py
92
93
94
95
96
97
98
def test_calculator_substract_1():
    """
    Test /calculator/substract/ endpoint
    """
    response: TestClient = client.get("/calculator/substract/?a=4&b=2")
    assert response.status_code == 200
    assert response.json() == {"result": 2.0}

test_calculator_substract_2()

Test /calculator/substract/ endpoint

Source code in tests/test_endpoints_calculator.py
101
102
103
104
105
106
107
def test_calculator_substract_2():
    """
    Test /calculator/substract/ endpoint
    """
    response: TestClient = client.get("/calculator/substract/?a=2&b=4")
    assert response.status_code == 200
    assert response.json() == {"result": -2.0}

test_calculator_substract_3()

Test /calculator/substract/ endpoint

Source code in tests/test_endpoints_calculator.py
110
111
112
113
114
115
116
def test_calculator_substract_3():
    """
    Test /calculator/substract/ endpoint
    """
    response: TestClient = client.get("/calculator/substract/?a=2&b=2")
    assert response.status_code == 200
    assert response.json() == {"result": 0.0}

test_endpoints_health

Tests for health api endpoints.

test_read_main()

Test /health/status/ endpoint

Source code in tests/test_endpoints_health.py
11
12
13
14
15
16
17
def test_read_main():
    """
    Test /health/status/ endpoint
    """
    response: TestClient = client.get("/health/status/")
    assert response.status_code == 200
    assert response.json() == {"status": "OK"}