|
23 | 23 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24 | 24 | # THE SOFTWARE.
|
25 | 25 | import os
|
| 26 | + |
26 | 27 | from ..utils import AppriseConfigCache
|
27 | 28 | from ..utils import AppriseStoreMode
|
28 | 29 | from ..utils import SimpleFileExtension
|
@@ -112,6 +113,86 @@ def test_apprise_config_io_hash_mode(tmpdir):
|
112 | 113 | assert acc_obj.get(key) == (content, ConfigFormat.YAML)
|
113 | 114 |
|
114 | 115 |
|
| 116 | +def test_apprise_config_list_simple_mode(tmpdir): |
| 117 | + """ |
| 118 | + Test Apprise Config Keys List using SIMPLE mode |
| 119 | + """ |
| 120 | + # Create our object to work with |
| 121 | + acc_obj = AppriseConfigCache(str(tmpdir), mode=AppriseStoreMode.SIMPLE) |
| 122 | + |
| 123 | + # Add a hidden file to the config directory (which should be ignored) |
| 124 | + hidden_file = os.path.join(str(tmpdir), '.hidden') |
| 125 | + with open(hidden_file, 'w') as f: |
| 126 | + f.write('hidden file') |
| 127 | + |
| 128 | + # Write 5 text configs and 5 yaml configs |
| 129 | + content_text = 'mailto://test:pass@gmail.com' |
| 130 | + content_yaml = """ |
| 131 | + version: 1 |
| 132 | + urls: |
| 133 | + - windows:// |
| 134 | + """ |
| 135 | + text_key_tpl = 'test_apprise_config_list_simple_text_{}' |
| 136 | + yaml_key_tpl = 'test_apprise_config_list_simple_yaml_{}' |
| 137 | + text_keys = [text_key_tpl.format(i) for i in range(5)] |
| 138 | + yaml_keys = [yaml_key_tpl.format(i) for i in range(5)] |
| 139 | + key = None |
| 140 | + for key in text_keys: |
| 141 | + assert acc_obj.put(key, content_text, ConfigFormat.TEXT) |
| 142 | + for key in yaml_keys: |
| 143 | + assert acc_obj.put(key, content_yaml, ConfigFormat.YAML) |
| 144 | + |
| 145 | + # Ensure the 10 configuration files (plus the hidden file) are the only |
| 146 | + # contents of the directory |
| 147 | + conf_dir, _ = acc_obj.path(key) |
| 148 | + contents = os.listdir(conf_dir) |
| 149 | + assert len(contents) == 11 |
| 150 | + |
| 151 | + keys = acc_obj.keys() |
| 152 | + assert len(keys) == 10 |
| 153 | + assert sorted(keys) == sorted(text_keys + yaml_keys) |
| 154 | + |
| 155 | + |
| 156 | +def test_apprise_config_list_hash_mode(tmpdir): |
| 157 | + """ |
| 158 | + Test Apprise Config Keys List using HASH mode |
| 159 | + """ |
| 160 | + # Create our object to work with |
| 161 | + acc_obj = AppriseConfigCache(str(tmpdir), mode=AppriseStoreMode.HASH) |
| 162 | + |
| 163 | + # Add a hidden file to the config directory (which should be ignored) |
| 164 | + hidden_file = os.path.join(str(tmpdir), '.hidden') |
| 165 | + with open(hidden_file, 'w') as f: |
| 166 | + f.write('hidden file') |
| 167 | + |
| 168 | + # Write 5 text configs and 5 yaml configs |
| 169 | + content_text = 'mailto://test:pass@gmail.com' |
| 170 | + content_yaml = """ |
| 171 | + version: 1 |
| 172 | + urls: |
| 173 | + - windows:// |
| 174 | + """ |
| 175 | + text_key_tpl = 'test_apprise_config_list_simple_text_{}' |
| 176 | + yaml_key_tpl = 'test_apprise_config_list_simple_yaml_{}' |
| 177 | + text_keys = [text_key_tpl.format(i) for i in range(5)] |
| 178 | + yaml_keys = [yaml_key_tpl.format(i) for i in range(5)] |
| 179 | + key = None |
| 180 | + for key in text_keys: |
| 181 | + assert acc_obj.put(key, content_text, ConfigFormat.TEXT) |
| 182 | + for key in yaml_keys: |
| 183 | + assert acc_obj.put(key, content_yaml, ConfigFormat.YAML) |
| 184 | + |
| 185 | + # Ensure the 10 configuration files (plus the hidden file) are the only |
| 186 | + # contents of the directory |
| 187 | + conf_dir, _ = acc_obj.path(key) |
| 188 | + contents = os.listdir(conf_dir) |
| 189 | + assert len(contents) == 1 |
| 190 | + |
| 191 | + # does not search on hash mode |
| 192 | + keys = acc_obj.keys() |
| 193 | + assert len(keys) == 0 |
| 194 | + |
| 195 | + |
115 | 196 | def test_apprise_config_io_simple_mode(tmpdir):
|
116 | 197 | """
|
117 | 198 | Test Apprise Config Disk Put/Get using SIMPLE mode
|
|
0 commit comments