[tracker-miners/sam/writeback-album-title-test] functional-tests: Add a test for updating an album title using writeback
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/sam/writeback-album-title-test] functional-tests: Add a test for updating an album title using writeback
- Date: Mon, 26 Aug 2019 11:26:36 +0000 (UTC)
commit 1fb3efec87c0cd9b6a759c4c0a5b62226aaa5a1e
Author: Sam Thursfield <sam afuera me uk>
Date: Mon Aug 26 14:21:26 2019 +0300
functional-tests: Add a test for updating an album title using writeback
tests/functional-tests/502-writeback-audio.py | 81 ++++++++++++++++++++++-----
1 file changed, 66 insertions(+), 15 deletions(-)
---
diff --git a/tests/functional-tests/502-writeback-audio.py b/tests/functional-tests/502-writeback-audio.py
index f74ca4913..8aad98aaa 100755
--- a/tests/functional-tests/502-writeback-audio.py
+++ b/tests/functional-tests/502-writeback-audio.py
@@ -26,36 +26,87 @@ from common.utils.writebacktest import CommonTrackerWritebackTest
class WritebackAudioTest(CommonTrackerWritebackTest):
- def _writeback_test(self, path):
- prop = 'nie:title'
+ def _writeback_test_title(self, path):
+ """Test updating the 'title' tag of a music file."""
path = self.prepare_test_audio(path)
initial_mtime = path.stat().st_mtime
- TEST_VALUE = prop.replace(":", "") + "test"
+ TEST_VALUE = "test_title"
SPARQL_TMPL = """
- DELETE { ?u %s ?v } WHERE { ?u nie:url '%s' ; %s ?v }
- INSERT { ?u %s '%s' }
+ DELETE { ?u nie:title ?v } WHERE { ?u nie:url '%s' ; nie:title ?v }
+ INSERT { ?u nie:title '%s' }
WHERE { ?u nie:url '%s' }
"""
- self.tracker.update(SPARQL_TMPL % (prop, path.as_uri(), prop, prop, TEST_VALUE, path.as_uri()))
+ self.tracker.update(SPARQL_TMPL % (path.as_uri(), TEST_VALUE, path.as_uri()))
self.wait_for_file_change(path, initial_mtime)
results = get_tracker_extract_jsonld_output(path)
- self.assertIn(TEST_VALUE, results[prop])
+ self.assertIn(TEST_VALUE, results['nie:title'])
- def test_writeback_mp3(self):
- self._writeback_test(self.datadir_path('writeback-test-5.mp3'))
+ def _writeback_test_album_title(self, path):
+ """Test updating the 'album title' tag of a music file."""
- def test_writeback_ogg(self):
- self._writeback_test(self.datadir_path('writeback-test-6.ogg'))
+ path = self.prepare_test_audio(path)
+ url = path.as_uri()
+ initial_mtime = path.stat().st_mtime
+
+ TEST_VALUE = "test_album_title"
+
+ # First we delete link between the musicpiece and the old album.
+ update = 'DELETE { ?musicpiece nmm:musicAlbum ?album } WHERE { ?musicpiece nie:url "%s" }' % url
+ self.tracker.update(update)
+
+ # Then we check if a matching album resource already exists. (In the
+ # case of this test, this is unnecessary, but real applications will
+ # need to do so).
+ query = 'SELECT ?album { ?album a nmm:MusicAlbum ; nie:title "New Title" }'
+ results = self.tracker.query(query)
+ assert len(results) == 0
+
+ # Create a new music album and music album disk.
+ new_album_title = TEST_VALUE
+ new_album_urn = "urn:album:test_album_title"
+ new_album_disc_urn = "urn:album-disc:test_album_title:Disc1"
+
+ update = """
+ INSERT DATA {
+ <%s> a nmm:MusicAlbum ;
+ nie:title "%s" .
+ <%s> a nmm:MusicAlbumDisc ;
+ nmm:setNumber 1 ;
+ nmm:albumDiscAlbum <%s> .
+ }
+ """ % (new_album_urn, new_album_title, new_album_disc_urn, new_album_urn)
+ self.tracker.update(update)
+
+ # Finally, update the existing musicpiece to refer to the new album.
+ update = 'INSERT { ?musicpiece nmm:musicAlbum <%s> } WHERE { ?musicpiece nie:url "%s" . }' %
(new_album_urn, url)
+ self.tracker.update(update)
+
+ self.wait_for_file_change(path, initial_mtime)
+
+ results = get_tracker_extract_jsonld_output(path)
+ self.assertIn(TEST_VALUE, results['nmm:musicAlbum']['nie:title'])
+
+ def test_writeback_mp3_title(self):
+ self._writeback_test_title(self.datadir_path('writeback-test-5.mp3'))
+ def test_writeback_mp3_album_title(self):
+ self._writeback_test_album_title(self.datadir_path('writeback-test-5.mp3'))
+
+ def test_writeback_ogg_title(self):
+ self._writeback_test_title(self.datadir_path('writeback-test-6.ogg'))
+ def test_writeback_ogg_album_title(self):
+ self._writeback_test_album_title(self.datadir_path('writeback-test-6.ogg'))
- def test_writeback_flac(self):
- self._writeback_test(self.datadir_path('writeback-test-7.flac'))
+ def test_writeback_flac_title(self):
+ self._writeback_test_title(self.datadir_path('writeback-test-7.flac'))
+ def test_writeback_flac_album_title(self):
+ self._writeback_test_album_title(self.datadir_path('writeback-test-7.flac'))
- def test_writeback_aac(self):
- self._writeback_test(self.datadir_path('writeback-test-8.mp4'))
+ def test_writeback_aac_title(self):
+ self._writeback_test_title(self.datadir_path('writeback-test-8.mp4'))
if __name__ == "__main__":
unittest.main(failfast=True)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]