-
Notifications
You must be signed in to change notification settings - Fork 120
/
test_micro_service.py
64 lines (46 loc) · 1.69 KB
/
test_micro_service.py
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
import pytest
from satosa.context import Context
from satosa.exception import SATOSAAuthenticationError
from satosa.microservices.service_base import MicroService, build_micro_service_queue
from satosa.state import State
def create_process_func(data_str):
def process(context, data):
return "{}{}".format(data, data_str)
return process
def create_process_fail_func(data_str):
def process(context, data):
raise Exception("error")
return process
def test_micro_service(context):
"""
Test the micro service flow
"""
data_list = ["1", "2", "3"]
service_list = []
for d in data_list:
service = MicroService()
service.process = create_process_func(d)
service_list.append(service)
service_queue = build_micro_service_queue(service_list)
test_data = "test_data"
data = service_queue.process_service_queue(context, test_data)
for d in data_list:
test_data = "{}{}".format(test_data, d)
assert data == test_data
def test_mirco_service_error(context):
"""
Test that the process_service_queue raises a SATOSAAuthenticationError if anything goes wrong with a micro service
"""
data_list = ["1", "2", "3"]
service_list = []
fail_service = MicroService()
fail_service.process = create_process_fail_func("4")
service_list.append(fail_service)
for d in data_list:
service = MicroService()
service.process = create_process_func(d)
service_list.append(service)
service_queue = build_micro_service_queue(service_list)
test_data = "test_data"
with pytest.raises(SATOSAAuthenticationError):
service_queue.process_service_queue(context, test_data)