This repository has been archived by the owner on Jun 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 276
/
email_factory_test.py
98 lines (89 loc) · 3.65 KB
/
email_factory_test.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
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
# Copyright 2017 The Forseti Security Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for Email Factory"""
from google.cloud.forseti.common.util.email import email_factory
from google.cloud.forseti.common.util.email import mailjet_connector
from google.cloud.forseti.common.util.email import sendgrid_connector
from google.cloud.forseti.common.util.errors import InvalidInputError
from tests.unittest_utils import ForsetiTestCase
class EmailFactoryTest(ForsetiTestCase):
"""Tests for Email Factory"""
def test_get_connector_correctness_default(self):
"""Test get_connector() correctness."""
sample_notifier_config = {
'sender': 'abc',
'recipient': 'xyz',
'api_key': 'a0b0c0'
}
connector = email_factory.EmailFactory(
sample_notifier_config).get_connector()
self.assertTrue(isinstance(connector,
sendgrid_connector.SendgridConnector))
def test_get_connector_correctness_sendgrid(self):
"""Test get_connector() correctness."""
sample_notifier_config = {
'email_connector': {
'name': 'sendgrid',
'sender': 'abc',
'recipient': 'xyz',
'data_format': 'csv',
'auth': {
'api_key': 'a0b0c0'
}
}
}
connector = email_factory.EmailFactory(
sample_notifier_config).get_connector()
self.assertTrue(isinstance(connector,
sendgrid_connector.SendgridConnector))
def test_get_connector_correctness_mailjet(self):
"""Test get_connector() correctness."""
sample_notifier_config = {
'email_connector': {
'name': 'mailjet',
'sender': 'abc',
'recipient': 'xyz',
'data_format': 'csv',
'auth': {
'api_key': 'a0b0c0',
'api_secret': 'z9y9x9'
},
'custom': {
'campaign': 'forseti'
}
}
}
connector = email_factory.EmailFactory(sample_notifier_config).get_connector()
self.assertIsInstance(connector, mailjet_connector.MailjetConnector)
def test_get_connector_invalid_input(self):
"""Test get_connector() with invalid input."""
incomplete_notifier_config = {
'email_connector': {
'sender': 'abc',
'recipient': 'xyz',
'data_format': 'csv',
'auth': {
'api_key': 'a0b0c0'
}
}
}
self.assertRaises(InvalidInputError,
email_factory.EmailFactory(
incomplete_notifier_config).get_connector)
def test_get_connector_empty(self):
"""Test get_connector() when input is not passed."""
empty_notifier_config = {}
self.assertRaises(InvalidInputError,
email_factory.EmailFactory(
empty_notifier_config).get_connector)