mirror of
https://github.com/beetbox/beets.git
synced 2026-02-22 15:22:42 +01:00
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 <g+beets@cobb.uk.net>
This commit is contained in:
parent
15be534e7c
commit
de58334ecb
1 changed files with 13 additions and 4 deletions
|
|
@ -25,9 +25,10 @@ class WebPluginTest(_common.LibTestCase):
|
|||
|
||||
# Add library elements. Note that self.lib.add overrides any "id=<n>" 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__)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue