|
6 | 6 | from datalad.api import Dataset |
7 | 7 | import pygit2 |
8 | 8 |
|
9 | | -from datalad_service.tasks.snapshots import write_new_changes |
| 9 | +from datalad_service.tasks.snapshots import edit_changes, write_new_changes |
10 | 10 | from datalad_service.common.git import git_show, git_show_content |
11 | 11 |
|
12 | 12 |
|
@@ -167,6 +167,60 @@ async def test_write_new_changes(datalad_store, new_dataset): |
167 | 167 | ) |
168 | 168 |
|
169 | 169 |
|
| 170 | +def test_edit_changes_with_preamble(): |
| 171 | + """New version should be inserted after preamble text, not before it.""" |
| 172 | + changes = """Preamble text that should be preserved |
| 173 | +
|
| 174 | +1.0.0 2025-09-24 |
| 175 | + - Initial upload |
| 176 | +""" |
| 177 | + result = edit_changes(changes, ['Added data'], '2.0.0', '2026-03-24') |
| 178 | + assert ( |
| 179 | + result |
| 180 | + == """Preamble text that should be preserved |
| 181 | +
|
| 182 | +2.0.0 2026-03-24 |
| 183 | + - Added data |
| 184 | +1.0.0 2025-09-24 |
| 185 | + - Initial upload |
| 186 | +""" |
| 187 | + ) |
| 188 | + |
| 189 | + |
| 190 | +def test_edit_changes_update_existing_with_preamble(): |
| 191 | + """Updating an existing version should preserve preamble.""" |
| 192 | + changes = """Preamble text that should be preserved |
| 193 | +
|
| 194 | +1.0.0 2025-09-24 |
| 195 | + - Initial upload |
| 196 | +""" |
| 197 | + result = edit_changes(changes, ['Updated data'], '1.0.0', '2025-09-24') |
| 198 | + assert ( |
| 199 | + result |
| 200 | + == """Preamble text that should be preserved |
| 201 | +
|
| 202 | +1.0.0 2025-09-24 |
| 203 | + - Updated data |
| 204 | +""" |
| 205 | + ) |
| 206 | + |
| 207 | + |
| 208 | +def test_edit_changes_no_preamble(): |
| 209 | + """Without preamble, new version is prepended.""" |
| 210 | + changes = """1.0.0 2025-09-24 |
| 211 | + - Initial upload |
| 212 | +""" |
| 213 | + result = edit_changes(changes, ['Added data'], '2.0.0', '2026-03-24') |
| 214 | + assert ( |
| 215 | + result |
| 216 | + == """2.0.0 2026-03-24 |
| 217 | + - Added data |
| 218 | +1.0.0 2025-09-24 |
| 219 | + - Initial upload |
| 220 | +""" |
| 221 | + ) |
| 222 | + |
| 223 | + |
170 | 224 | async def test_write_with_empty_changes(datalad_store, new_dataset): |
171 | 225 | ds_id = os.path.basename(new_dataset.path) |
172 | 226 | new_dataset.remove('CHANGES') |
|
0 commit comments