Skip to content

Commit eb8c7b4

Browse files
committed
tests skeleton
1 parent a2b2861 commit eb8c7b4

File tree

10 files changed

+202
-0
lines changed

10 files changed

+202
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pytest
2+
from functions.geos.libs.result import Result
3+
4+
def test_success():
5+
r = Result(status="success")
6+
assert r.success() == True
7+
assert r.failure() == False
8+
9+
def test_failure():
10+
r = Result(errors=["some error"])
11+
assert r.success() == False
12+
assert r.failure() == True
13+
14+
def test_default_status():
15+
r = Result()
16+
assert r.status == "ok"
17+
assert r.success() == True
18+
assert r.failure() == False
19+
20+
def test_custom_status():
21+
r = Result(status="custom")
22+
assert r.status == "custom"
23+
assert r.success() == True
24+
assert r.failure() == False
25+
26+
def test_result():
27+
r = Result(result="some result")
28+
assert r.result == "some result"
29+
30+
def test_errors():
31+
r = Result(errors=["some error"])
32+
assert r.errors == ["some error"]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from functions.geos.libs.utils import *
2+
from functions.geos.libs.result import Result
3+
import json
4+
5+
def test_output():
6+
# Create a mock result object with a successful status
7+
result_success = Result(status="success", result={"message": "Hello, world!"})
8+
9+
# Call the output function with the mock result object
10+
output_result_success = output(result_success)
11+
12+
# Verify that the output has the correct HTTP status code and payload
13+
assert output_result_success[1] == 200
14+
assert json.loads(output_result_success[0]) == {"message": "Hello, world!"}
15+
16+
# Create a mock result object with an error status
17+
result_error = Result(status="error", errors=[["param", "Invalid request"]])
18+
19+
# Call the output function with the mock result object
20+
output_result_error = output(result_error)
21+
22+
# Verify that the output has the correct HTTP status code and payload
23+
assert output_result_error[1] == 400
24+
assert json.loads(output_result_error[0]) == [{"param": "Invalid request"}]
25+
26+
def test_convert_to_hashes():
27+
input_arr = [["geo", "missing geo parameters"], ["app", "missing geo parameters"]]
28+
expected_output_arr = [{'geo': 'missing geo parameters'}, {'app': 'missing geo parameters'}]
29+
assert convert_to_hashes(input_arr) == expected_output_arr

tests/test_geos/test_geos_main.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import unittest
2+
import json
3+
from unittest.mock import Mock
4+
5+
from functions.geos.main import dispatcher
6+
from functions.geos.libs.utils import COUNTRIES
7+
8+
class TestCloudFunction(unittest.TestCase):
9+
10+
def test_success(self):
11+
request = Mock()
12+
response = dispatcher(request)
13+
expected_data = json.dumps(COUNTRIES)
14+
15+
self.assertEqual(response[1], 200)
16+
self.assertEqual(response[0], expected_data)
17+
18+
if __name__ == '__main__':
19+
unittest.main()
20+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from functions.ranks.libs.result import Result
2+
3+
def test_success():
4+
r = Result(status="success")
5+
assert r.success() == True
6+
assert r.failure() == False
7+
8+
def test_failure():
9+
r = Result(errors=["some error"])
10+
assert r.success() == False
11+
assert r.failure() == True
12+
13+
def test_default_status():
14+
r = Result()
15+
assert r.status == "ok"
16+
assert r.success() == True
17+
assert r.failure() == False
18+
19+
def test_custom_status():
20+
r = Result(status="custom")
21+
assert r.status == "custom"
22+
assert r.success() == True
23+
assert r.failure() == False
24+
25+
def test_result():
26+
r = Result(result="some result")
27+
assert r.result == "some result"
28+
29+
def test_errors():
30+
r = Result(errors=["some error"])
31+
assert r.errors == ["some error"]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from functions.ranks.libs.utils import *
2+
from functions.ranks.libs.result import Result
3+
import json
4+
5+
def test_output():
6+
# Create a mock result object with a successful status
7+
result_success = Result(status="success", result={"message": "Hello, world!"})
8+
9+
# Call the output function with the mock result object
10+
output_result_success = output(result_success)
11+
12+
# Verify that the output has the correct HTTP status code and payload
13+
assert output_result_success[1] == 200
14+
assert json.loads(output_result_success[0]) == {"message": "Hello, world!"}
15+
16+
# Create a mock result object with an error status
17+
result_error = Result(status="error", errors=[["param", "Invalid request"]])
18+
19+
# Call the output function with the mock result object
20+
output_result_error = output(result_error)
21+
22+
# Verify that the output has the correct HTTP status code and payload
23+
assert output_result_error[1] == 400
24+
assert json.loads(output_result_error[0]) == [{"param": "Invalid request"}]
25+
26+
def test_convert_to_hashes():
27+
input_arr = [["geo", "missing geo parameters"], ["app", "missing geo parameters"]]
28+
expected_output_arr = [{'geo': 'missing geo parameters'}, {'app': 'missing geo parameters'}]
29+
assert convert_to_hashes(input_arr) == expected_output_arr

tests/test_ranks/test_ranks_main.py

Whitespace-only changes.

tests/test_report/test_report_main.py

Whitespace-only changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pytest
2+
from functions.technologies.libs.result import Result
3+
4+
def test_success():
5+
r = Result(status="success")
6+
assert r.success() == True
7+
assert r.failure() == False
8+
9+
def test_failure():
10+
r = Result(errors=["some error"])
11+
assert r.success() == False
12+
assert r.failure() == True
13+
14+
def test_default_status():
15+
r = Result()
16+
assert r.status == "ok"
17+
assert r.success() == True
18+
assert r.failure() == False
19+
20+
def test_custom_status():
21+
r = Result(status="custom")
22+
assert r.status == "custom"
23+
assert r.success() == True
24+
assert r.failure() == False
25+
26+
def test_result():
27+
r = Result(result="some result")
28+
assert r.result == "some result"
29+
30+
def test_errors():
31+
r = Result(errors=["some error"])
32+
assert r.errors == ["some error"]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from functions.technologies.libs.utils import *
2+
from functions.technologies.libs.result import Result
3+
import json
4+
5+
def test_output():
6+
# Create a mock result object with a successful status
7+
result_success = Result(status="success", result={"message": "Hello, world!"})
8+
9+
# Call the output function with the mock result object
10+
output_result_success = output(result_success)
11+
12+
# Verify that the output has the correct HTTP status code and payload
13+
assert output_result_success[1] == 200
14+
assert json.loads(output_result_success[0]) == {"message": "Hello, world!"}
15+
16+
# Create a mock result object with an error status
17+
result_error = Result(status="error", errors=[["param", "Invalid request"]])
18+
19+
# Call the output function with the mock result object
20+
output_result_error = output(result_error)
21+
22+
# Verify that the output has the correct HTTP status code and payload
23+
assert output_result_error[1] == 400
24+
assert json.loads(output_result_error[0]) == [{"param": "Invalid request"}]
25+
26+
def test_convert_to_hashes():
27+
input_arr = [["geo", "missing geo parameters"], ["app", "missing geo parameters"]]
28+
expected_output_arr = [{'geo': 'missing geo parameters'}, {'app': 'missing geo parameters'}]
29+
assert convert_to_hashes(input_arr) == expected_output_arr

tests/test_technologies/test_technologies_main.py

Whitespace-only changes.

0 commit comments

Comments
 (0)