fix: transactions and stricter tests

This commit is contained in:
Bert Besser 2021-05-13 15:07:54 +02:00
parent a25a2a6cbb
commit e98f78e29b
2 changed files with 24 additions and 28 deletions

View file

@ -576,17 +576,17 @@ class ImportTask(BaseImportTask):
"""Sets the fields given at CLI or configuration to the specified """Sets the fields given at CLI or configuration to the specified
values, for both the album and all its items. values, for both the album and all its items.
""" """
items = self.imported_items()
for field, view in config['import']['set_fields'].items():
value = view.get()
log.debug(u'Set field {1}={2} for {0}',
displayable_path(self.paths),
field,
value)
self.album[field] = value
for item in items:
item[field] = value
with lib.transaction(): with lib.transaction():
items = self.imported_items()
for field, view in config['import']['set_fields'].items():
value = view.get()
log.debug(u'Set field {1}={2} for {0}',
displayable_path(self.paths),
field,
value)
self.album[field] = value
for item in items:
item[field] = value
for item in items: for item in items:
item.store() item.store()
self.album.store() self.album.store()
@ -956,15 +956,14 @@ class SingletonImportTask(ImportTask):
"""Sets the fields given at CLI or configuration to the specified """Sets the fields given at CLI or configuration to the specified
values, for the singleton item. values, for the singleton item.
""" """
with lib.transaction(): for field, view in config['import']['set_fields'].items():
for field, view in config['import']['set_fields'].items(): value = view.get()
value = view.get() log.debug(u'Set field {1}={2} for {0}',
log.debug(u'Set field {1}={2} for {0}', displayable_path(self.paths),
displayable_path(self.paths), field,
field, value)
value) self.item[field] = value
self.item[field] = value self.item.store()
self.item.store()
# FIXME The inheritance relationships are inverted. This is why there # FIXME The inheritance relationships are inverted. This is why there

View file

@ -743,7 +743,6 @@ class ImportTest(_common.TestCase, ImportHelper):
comments = u"managed by beets" comments = u"managed by beets"
config['import']['set_fields'] = { config['import']['set_fields'] = {
u'collection': collection,
u'genre': genre, u'genre': genre,
u'comments': comments u'comments': comments
} }
@ -756,11 +755,10 @@ class ImportTest(_common.TestCase, ImportHelper):
for album in self.lib.albums(): for album in self.lib.albums():
album.load() # TODO: Not sure this is necessary. album.load() # TODO: Not sure this is necessary.
self.assertEqual(album.genre, genre) self.assertEqual(album.genre, genre)
self.assertEqual(album.collection, collection) self.assertEqual(album.comments, comments)
for item in album.items(): for item in album.items():
self.assertEqual(item.genre, genre) self.assertEqual(item.get("genre", with_album=False), genre)
self.assertEqual(item.collection, collection) self.assertEqual(item.get("comments", with_album=False), comments)
self.assertEqual(item.comments, comments)
# Remove album from library to test again with APPLY choice. # Remove album from library to test again with APPLY choice.
album.remove() album.remove()
@ -773,11 +771,10 @@ class ImportTest(_common.TestCase, ImportHelper):
for album in self.lib.albums(): for album in self.lib.albums():
album.load() album.load()
self.assertEqual(album.genre, genre) self.assertEqual(album.genre, genre)
self.assertEqual(album.collection, collection) self.assertEqual(album.comments, comments)
for item in album.items(): for item in album.items():
self.assertEqual(item.genre, genre) self.assertEqual(item.get("genre", with_album=False), genre)
self.assertEqual(item.collection, collection) self.assertEqual(item.get("comments", with_album=False), comments)
self.assertEqual(item.comments, comments)
class ImportTracksTest(_common.TestCase, ImportHelper): class ImportTracksTest(_common.TestCase, ImportHelper):