|
| 1 | +import json |
1 | 2 | import os |
2 | 3 | import pytest |
3 | 4 | import secrets |
@@ -131,3 +132,34 @@ def get_installs(self): |
131 | 132 | assert_log( |
132 | 133 | assert_log.skip_until(".*Global shortcuts directory is not on PATH") |
133 | 134 | ) |
| 135 | + |
| 136 | + |
| 137 | +def test_merge_existing_index(tmp_path): |
| 138 | + # This function is for multiple downloaded index.jsons, so it merges based |
| 139 | + # on the url property, which should usually be a local file. |
| 140 | + existing = tmp_path / "index.json" |
| 141 | + with open(existing, "w", encoding="utf-8") as f: |
| 142 | + json.dump({"versions": [ |
| 143 | + {"id": "test-1", "url": "test-file-1.zip"}, |
| 144 | + {"id": "test-2", "url": "test-file-2.zip"}, |
| 145 | + {"id": "test-3", "url": "test-file-3.zip"}, |
| 146 | + ]}, f) |
| 147 | + |
| 148 | + new = [ |
| 149 | + # Ensure new versions appear first |
| 150 | + {"id": "test-4", "url": "test-file-4.zip"}, |
| 151 | + # Ensure matching ID doesn't result in overwrite |
| 152 | + {"id": "test-1", "url": "test-file-1b.zip"}, |
| 153 | + # Ensure matching URL excludes original entry |
| 154 | + {"id": "test-2b", "url": "test-file-2.zip"}, |
| 155 | + ] |
| 156 | + |
| 157 | + IC._merge_existing_index(new, existing) |
| 158 | + |
| 159 | + assert new == [ |
| 160 | + {"id": "test-4", "url": "test-file-4.zip"}, |
| 161 | + {"id": "test-1", "url": "test-file-1b.zip"}, |
| 162 | + {"id": "test-2b", "url": "test-file-2.zip"}, |
| 163 | + {"id": "test-1", "url": "test-file-1.zip"}, |
| 164 | + {"id": "test-3", "url": "test-file-3.zip"}, |
| 165 | + ] |
0 commit comments