-
Notifications
You must be signed in to change notification settings - Fork 85
/
test_init.py
182 lines (153 loc) · 4.76 KB
/
test_init.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
"""Tests for init."""
from unittest.mock import patch
import pytest
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from pytest_homeassistant_custom_component.common import MockConfigEntry
from custom_components.mail_and_packages.const import DOMAIN
from tests.const import (
FAKE_CONFIG_DATA,
FAKE_CONFIG_DATA_AMAZON_FWD_STRING,
FAKE_CONFIG_DATA_CUSTOM_IMG,
FAKE_CONFIG_DATA_MISSING_TIMEOUT,
FAKE_CONFIG_DATA_NO_PATH,
)
async def test_unload_entry(hass, mock_update, mock_copy_overlays):
"""Test unloading entities."""
entry = MockConfigEntry(
domain=DOMAIN,
title="imap.test.email",
data=FAKE_CONFIG_DATA,
)
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 43
entries = hass.config_entries.async_entries(DOMAIN)
assert len(entries) == 1
assert await hass.config_entries.async_unload(entries[0].entry_id)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 43
assert len(hass.states.async_entity_ids(DOMAIN)) == 0
assert await hass.config_entries.async_remove(entries[0].entry_id)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 0
async def test_setup_entry(
hass,
mock_imap_no_email,
mock_osremove,
mock_osmakedir,
mock_listdir,
mock_update_time,
mock_copy_overlays,
mock_hash_file,
mock_getctime_today,
mock_update,
):
"""Test settting up entities."""
entry = MockConfigEntry(
domain=DOMAIN,
title="imap.test.email",
data=FAKE_CONFIG_DATA,
)
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 43
entries = hass.config_entries.async_entries(DOMAIN)
assert len(entries) == 1
async def test_no_path_no_sec(
hass,
mock_imap_no_email,
mock_osremove,
mock_osmakedir,
mock_listdir,
mock_update_time,
mock_copy_overlays,
mock_hash_file,
mock_getctime_today,
mock_update,
):
"""Test settting up entities."""
entry = MockConfigEntry(
domain=DOMAIN, title="imap.test.email", data=FAKE_CONFIG_DATA_NO_PATH, version=3
)
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 43
entries = hass.config_entries.async_entries(DOMAIN)
assert len(entries) == 1
async def test_missing_imap_timeout(
hass,
mock_imap_no_email,
mock_osremove,
mock_osmakedir,
mock_listdir,
mock_update_time,
mock_copy_overlays,
mock_hash_file,
mock_getctime_today,
mock_update,
):
"""Test settting up entities."""
entry = MockConfigEntry(
domain=DOMAIN,
title="imap.test.email",
data=FAKE_CONFIG_DATA_MISSING_TIMEOUT,
version=3,
)
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 42
entries = hass.config_entries.async_entries(DOMAIN)
assert len(entries) == 1
async def test_amazon_fwds_string(
hass,
mock_imap_no_email,
mock_osremove,
mock_osmakedir,
mock_listdir,
mock_update_time,
mock_copy_overlays,
mock_hash_file,
mock_getctime_today,
mock_update,
):
"""Test settting up entities."""
entry = MockConfigEntry(
domain=DOMAIN,
title="imap.test.email",
data=FAKE_CONFIG_DATA_AMAZON_FWD_STRING,
version=3,
)
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 42
entries = hass.config_entries.async_entries(DOMAIN)
assert len(entries) == 1
async def test_custom_img(
hass,
mock_imap_no_email,
mock_osremove,
mock_osmakedir,
mock_listdir,
mock_update_time,
mock_copy_overlays,
mock_hash_file,
mock_getctime_today,
mock_update,
):
"""Test settting up entities."""
entry = MockConfigEntry(
domain=DOMAIN,
title="imap.test.email",
data=FAKE_CONFIG_DATA_CUSTOM_IMG,
)
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 43
entries = hass.config_entries.async_entries(DOMAIN)
assert len(entries) == 1