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
|
###############################################################################
# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
# and others #
# #
# All rights reserved. This program and the accompanying materials #
# are made available under the terms of the Apache License, Version 2.0 #
# which accompanies this distribution, and is available at #
# http://www.apache.org/licenses/LICENSE-2.0 #
###############################################################################
from test.api.test_base import TestBase
from test.api.responders_test.test_data import base
from test.api.responders_test.test_data import aggregates
from unittest.mock import patch
class TestAggregates(TestBase):
def test_get_aggregate_without_type(self):
self.validate_get_request(aggregates.URL,
params={},
expected_code=base.BAD_REQUEST_CODE)
def test_get_aggregate_with_wrong_filter(self):
self.validate_get_request(aggregates.URL,
params={
"unknown": "unknown"
},
expected_code=base.BAD_REQUEST_CODE)
def test_get_environment_aggregates_without_env_name(self):
self.validate_get_request(aggregates.URL,
params={
"type": aggregates.ENV_TYPE
},
expected_code=base.BAD_REQUEST_CODE)
@patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
def test_get_environment_aggregates_with_unknown_env_name(self,
check_env_name):
self.validate_get_request(aggregates.URL,
params={
"type": aggregates.ENV_TYPE,
"env_name": base.UNKNOWN_ENV
},
mocks={
check_env_name: False
},
expected_code=base.BAD_REQUEST_CODE)
@patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
@patch(base.RESPONDER_BASE_AGGREGATE)
def test_get_environment_aggregates_with_env_name(self, aggregates_method,
check_env_name):
self.validate_get_request(aggregates.URL,
params={
"type": aggregates.ENV_TYPE,
"env_name": base.ENV_NAME
},
mocks={
check_env_name: True,
aggregates_method:
aggregates.ENVIRONMENT_AGGREGATES
},
expected_code=base.SUCCESSFUL_CODE,
expected_response=
aggregates.ENVIRONMENT_AGGREGATES_RESPONSE
)
@patch(base.RESPONDER_BASE_AGGREGATE)
def test_get_message_aggregates(self, aggregate):
self.validate_get_request(aggregates.URL,
params={
"type": aggregates.MESSAGE_TYPE
},
side_effects={aggregate: [
aggregates.MESSAGE_ENV_AGGREGATES,
aggregates.MESSAGE_LEVEL_AGGREGATES]
},
expected_code=base.SUCCESSFUL_CODE,
expected_response=
aggregates.MESSAGE_AGGREGATES_RESPONSE
)
@patch(base.RESPONDER_BASE_AGGREGATE)
def test_get_constant_aggregates(self, aggregate):
self.validate_get_request(aggregates.URL,
params={
"type": aggregates.CONSTANT_TYPE
},
mocks={
aggregate: aggregates.CONSTANT_AGGREGATES
},
expected_code=base.SUCCESSFUL_CODE,
expected_response=
aggregates.CONSTANT_AGGREGATES_RESPONSE
)
def test_get_unknown_aggregates(self):
self.validate_get_request(aggregates.URL,
params={
"type": aggregates.UNKNOWN_TYPE
},
expected_code=base.BAD_REQUEST_CODE)
|