-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
test_api_generator.py
52 lines (47 loc) · 1.77 KB
/
test_api_generator.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
from unittest import TestCase
from unittest.mock import Mock, patch
from parameterized import parameterized
from samtranslator.model import InvalidResourceException
from samtranslator.model.api.api_generator import ApiGenerator
class TestApiGenerator(TestCase):
@parameterized.expand([("this should be a dict",), ("123",), ([{}],)])
@patch("samtranslator.model.api.api_generator.AuthProperties")
def test_construct_usage_plan_with_invalid_usage_plan_type(self, invalid_usage_plan, AuthProperties_mock):
AuthProperties_mock.return_value = Mock(UsagePlan=invalid_usage_plan)
api_generator = ApiGenerator(
Mock(),
Mock(),
Mock(),
Mock(),
Mock(),
Mock(),
Mock(),
Mock(),
Mock(),
Mock(),
Mock(),
auth={"some": "value"},
)
with self.assertRaises(InvalidResourceException) as cm:
api_generator._construct_usage_plan()
self.assertIn("Invalid type", str(cm.exception))
@patch("samtranslator.model.api.api_generator.AuthProperties")
def test_construct_usage_plan_with_invalid_usage_plan_fields(self, AuthProperties_mock):
AuthProperties_mock.return_value = Mock(UsagePlan={"Unknown_field": "123"})
api_generator = ApiGenerator(
Mock(),
Mock(),
Mock(),
Mock(),
Mock(),
Mock(),
Mock(),
Mock(),
Mock(),
Mock(),
Mock(),
auth={"some": "value"},
)
with self.assertRaises(InvalidResourceException) as cm:
api_generator._construct_usage_plan()
self.assertIn("Invalid property for", str(cm.exception))