From dc55480f51bf93d11042acc03ce797d3f05b8c97 Mon Sep 17 00:00:00 2001 From: "Graham R. Cobb" Date: Fri, 5 Mar 2021 15:27:00 +0000 Subject: [PATCH 1/7] Document "id" handling in test setup and add test to confirm self.lib.add ignores the "id" field from the entry being added and overwrites it with the next free number. So remove the misleading id fields. Add a test to confirm that the album query response contains the expected album id number. Signed-off-by: Graham R. Cobb --- test/test_web.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/test/test_web.py b/test/test_web.py index e7d1f334f..e0022e60f 100644 --- a/test/test_web.py +++ b/test/test_web.py @@ -22,10 +22,15 @@ class WebPluginTest(_common.LibTestCase): # Add fixtures for track in self.lib.items(): track.remove() - self.lib.add(Item(title=u'title', path='/path_1', id=1)) - self.lib.add(Item(title=u'another title', path='/path_2', id=2)) - self.lib.add(Album(album=u'album', id=3)) - self.lib.add(Album(album=u'another album', id=4)) + + # Add library elements. Note that self.lib.add overrides any "id=" and assigns + # the next free id number. + # The following adds will create items #1 and #2 + self.lib.add(Item(title=u'title', path='/path_1')) + self.lib.add(Item(title=u'another title', path='/path_2', album_id=2)) + # The following adds will create albums #1 and #2 + self.lib.add(Album(album=u'album')) + self.lib.add(Album(album=u'another album')) web.app.config['TESTING'] = True web.app.config['lib'] = self.lib @@ -140,6 +145,15 @@ class WebPluginTest(_common.LibTestCase): self.assertEqual(response.status_code, 200) self.assertEqual(len(res_json['albums']), 2) + def test_get_simple_album_query(self): + response = self.client.get('/album/query/another') + res_json = json.loads(response.data.decode('utf-8')) + + self.assertEqual(response.status_code, 200) + self.assertEqual(len(res_json['results']), 1) + self.assertEqual(res_json['results'][0]['album'], + u'another album') + self.assertEqual(res_json['results'][0]['id'], 2) def suite(): return unittest.TestLoader().loadTestsFromName(__name__) From 79b41f6f3852ec498794b199fefec5f4a627f18a Mon Sep 17 00:00:00 2001 From: "Graham R. Cobb" Date: Fri, 5 Mar 2021 15:56:46 +0000 Subject: [PATCH 2/7] Add test for getting album track listing using ?expand=1 Added test_get_album_details to test fetching /album/2?expand=1. Also changed second album name to make tests more robust. Signed-off-by: Graham R. Cobb --- test/test_web.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/test/test_web.py b/test/test_web.py index e0022e60f..6cf0d2dbb 100644 --- a/test/test_web.py +++ b/test/test_web.py @@ -26,11 +26,11 @@ class WebPluginTest(_common.LibTestCase): # Add library elements. Note that self.lib.add overrides any "id=" and assigns # the next free id number. # The following adds will create items #1 and #2 - self.lib.add(Item(title=u'title', path='/path_1')) - self.lib.add(Item(title=u'another title', path='/path_2', album_id=2)) + self.lib.add(Item(title=u'title', path='/path_1', album_id=2)) + self.lib.add(Item(title=u'another title', path='/path_2')) # The following adds will create albums #1 and #2 self.lib.add(Album(album=u'album')) - self.lib.add(Album(album=u'another album')) + self.lib.add(Album(album=u'other album')) web.app.config['TESTING'] = True web.app.config['lib'] = self.lib @@ -120,7 +120,7 @@ class WebPluginTest(_common.LibTestCase): self.assertEqual(response.status_code, 200) response_albums = [album['album'] for album in res_json['albums']] - assertCountEqual(self, response_albums, [u'album', u'another album']) + assertCountEqual(self, response_albums, [u'album', u'other album']) def test_get_single_album_by_id(self): response = self.client.get('/album/2') @@ -128,7 +128,7 @@ class WebPluginTest(_common.LibTestCase): self.assertEqual(response.status_code, 200) self.assertEqual(res_json['id'], 2) - self.assertEqual(res_json['album'], u'another album') + self.assertEqual(res_json['album'], u'other album') def test_get_multiple_albums_by_id(self): response = self.client.get('/album/1,2') @@ -136,7 +136,7 @@ class WebPluginTest(_common.LibTestCase): self.assertEqual(response.status_code, 200) response_albums = [album['album'] for album in res_json['albums']] - assertCountEqual(self, response_albums, [u'album', u'another album']) + assertCountEqual(self, response_albums, [u'album', u'other album']) def test_get_album_empty_query(self): response = self.client.get('/album/query/') @@ -146,15 +146,25 @@ class WebPluginTest(_common.LibTestCase): self.assertEqual(len(res_json['albums']), 2) def test_get_simple_album_query(self): - response = self.client.get('/album/query/another') + response = self.client.get('/album/query/other') res_json = json.loads(response.data.decode('utf-8')) self.assertEqual(response.status_code, 200) self.assertEqual(len(res_json['results']), 1) self.assertEqual(res_json['results'][0]['album'], - u'another album') + u'other album') self.assertEqual(res_json['results'][0]['id'], 2) + def test_get_album_details(self): + response = self.client.get('/album/2?expand=1') + res_json = json.loads(response.data.decode('utf-8')) + + self.assertEqual(response.status_code, 200) + self.assertEqual(len(res_json['items']), 1) + self.assertEqual(res_json['items'][0]['album'], + u'other album') + self.assertEqual(res_json['items'][0]['id'], 1) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__) From 15be534e7cc80f6056c0e421ccb51ab3487b5a5a Mon Sep 17 00:00:00 2001 From: "Graham R. Cobb" Date: Fri, 5 Mar 2021 16:17:14 +0000 Subject: [PATCH 3/7] Test ?expand using documented syntax Documentation says that ?expand does not need a value (i.e. ?expand=1 is wrong), so the test is changed to reflect that syntax. Signed-off-by: Graham R. Cobb --- test/test_web.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_web.py b/test/test_web.py index 6cf0d2dbb..34a22f8d1 100644 --- a/test/test_web.py +++ b/test/test_web.py @@ -156,7 +156,7 @@ class WebPluginTest(_common.LibTestCase): self.assertEqual(res_json['results'][0]['id'], 2) def test_get_album_details(self): - response = self.client.get('/album/2?expand=1') + response = self.client.get('/album/2?expand') res_json = json.loads(response.data.decode('utf-8')) self.assertEqual(response.status_code, 200) From de58334ecb45a5c3dc10f23336530073c2ac54c6 Mon Sep 17 00:00:00 2001 From: "Graham R. Cobb" Date: Fri, 5 Mar 2021 16:29:26 +0000 Subject: [PATCH 4/7] Test web API /stats Added a test (test_get_stats) for the /stats web API. This involved adding another item so that we can check both items and albums are being counted correctly, which required a few small changes to some item tests. Signed-off-by: Graham R. Cobb --- test/test_web.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/test/test_web.py b/test/test_web.py index 34a22f8d1..d4f365c73 100644 --- a/test/test_web.py +++ b/test/test_web.py @@ -25,9 +25,10 @@ class WebPluginTest(_common.LibTestCase): # Add library elements. Note that self.lib.add overrides any "id=" and assigns # the next free id number. - # The following adds will create items #1 and #2 + # The following adds will create items #1, #2 and #3 self.lib.add(Item(title=u'title', path='/path_1', album_id=2)) self.lib.add(Item(title=u'another title', path='/path_2')) + self.lib.add(Item(title=u'and a third')) # The following adds will create albums #1 and #2 self.lib.add(Album(album=u'album')) self.lib.add(Album(album=u'other album')) @@ -58,7 +59,7 @@ class WebPluginTest(_common.LibTestCase): res_json = json.loads(response.data.decode('utf-8')) self.assertEqual(response.status_code, 200) - self.assertEqual(len(res_json['items']), 2) + self.assertEqual(len(res_json['items']), 3) def test_get_single_item_by_id(self): response = self.client.get('/item/1') @@ -78,7 +79,7 @@ class WebPluginTest(_common.LibTestCase): assertCountEqual(self, response_titles, [u'title', u'another title']) def test_get_single_item_not_found(self): - response = self.client.get('/item/3') + response = self.client.get('/item/4') self.assertEqual(response.status_code, 404) def test_get_single_item_by_path(self): @@ -103,7 +104,7 @@ class WebPluginTest(_common.LibTestCase): res_json = json.loads(response.data.decode('utf-8')) self.assertEqual(response.status_code, 200) - self.assertEqual(len(res_json['items']), 2) + self.assertEqual(len(res_json['items']), 3) def test_get_simple_item_query(self): response = self.client.get('/item/query/another') @@ -165,6 +166,14 @@ class WebPluginTest(_common.LibTestCase): u'other album') self.assertEqual(res_json['items'][0]['id'], 1) + def test_get_stats(self): + response = self.client.get('/stats') + res_json = json.loads(response.data.decode('utf-8')) + + self.assertEqual(response.status_code, 200) + self.assertEqual(res_json['items'], 3) + self.assertEqual(res_json['albums'], 2) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__) From 3846e3519d1ea38f876b3e05a51e074574fee4f3 Mon Sep 17 00:00:00 2001 From: "Graham R. Cobb" Date: Fri, 5 Mar 2021 16:38:03 +0000 Subject: [PATCH 5/7] Update changelog to mention small test coverage improvement for web plugin. Signed-off-by: Graham R. Cobb --- docs/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 2f31ecfe3..ecc926a33 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -186,6 +186,7 @@ New features: Fixes: +* Small improvement to ``web`` plugin test coverage (for `expand` and `stats` features) * :bug:`/plugins/discogs`: Fixed a bug with ``index_tracks`` options that sometimes caused the index to be discarded. Also remove the extra semicolon that was added when there is no index track. From 7d3fb0d7ecf42b531b2d4edeb355defba84c3bc0 Mon Sep 17 00:00:00 2001 From: "Graham R. Cobb" Date: Fri, 5 Mar 2021 16:52:21 +0000 Subject: [PATCH 6/7] Fix lint errors Signed-off-by: Graham R. Cobb --- test/test_web.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/test_web.py b/test/test_web.py index d4f365c73..e9ca028d9 100644 --- a/test/test_web.py +++ b/test/test_web.py @@ -23,8 +23,8 @@ class WebPluginTest(_common.LibTestCase): for track in self.lib.items(): track.remove() - # Add library elements. Note that self.lib.add overrides any "id=" and assigns - # the next free id number. + # Add library elements. Note that self.lib.add overrides any "id=" + # and assigns the next free id number. # The following adds will create items #1, #2 and #3 self.lib.add(Item(title=u'title', path='/path_1', album_id=2)) self.lib.add(Item(title=u'another title', path='/path_2')) @@ -174,6 +174,7 @@ class WebPluginTest(_common.LibTestCase): self.assertEqual(res_json['items'], 3) self.assertEqual(res_json['albums'], 2) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__) From d2a125175654fb6390ff68dcf9217a0fd85feed2 Mon Sep 17 00:00:00 2001 From: "Graham R. Cobb" Date: Fri, 5 Mar 2021 22:42:27 +0000 Subject: [PATCH 7/7] Drop changelog as requested by @sampsyo. Signed-off-by: Graham R. Cobb --- docs/changelog.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index ecc926a33..2f31ecfe3 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -186,7 +186,6 @@ New features: Fixes: -* Small improvement to ``web`` plugin test coverage (for `expand` and `stats` features) * :bug:`/plugins/discogs`: Fixed a bug with ``index_tracks`` options that sometimes caused the index to be discarded. Also remove the extra semicolon that was added when there is no index track.