mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-23 01:16:18 +00:00
Added folder management UI tests
This commit is contained in:
parent
2cf6d01489
commit
be47a259a8
@ -11,11 +11,13 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from .test_login import LoginTestCase
|
from .test_login import LoginTestCase
|
||||||
|
from .test_folder import FolderTestCase
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
|
|
||||||
suite.addTest(unittest.makeSuite(LoginTestCase))
|
suite.addTest(unittest.makeSuite(LoginTestCase))
|
||||||
|
suite.addTest(unittest.makeSuite(FolderTestCase))
|
||||||
|
|
||||||
return suite
|
return suite
|
||||||
|
|
||||||
|
19
tests/frontend/frontendtestbase.py
Normal file
19
tests/frontend/frontendtestbase.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vim:fenc=utf-8
|
||||||
|
#
|
||||||
|
# This file is part of Supysonic.
|
||||||
|
# Supysonic is a Python implementation of the Subsonic server API.
|
||||||
|
#
|
||||||
|
# Copyright (C) 2017 Alban 'spl0k' Féron
|
||||||
|
#
|
||||||
|
# Distributed under terms of the GNU AGPLv3 license.
|
||||||
|
|
||||||
|
from ..testbase import TestBase
|
||||||
|
|
||||||
|
class FrontendTestBase(TestBase):
|
||||||
|
def _login(self, username, password):
|
||||||
|
return self.client.post('/user/login', data = { 'user': username, 'password': password }, follow_redirects = True)
|
||||||
|
|
||||||
|
def _logout(self):
|
||||||
|
return self.client.get('/user/logout', follow_redirects = True)
|
||||||
|
|
102
tests/frontend/test_folder.py
Normal file
102
tests/frontend/test_folder.py
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vim:fenc=utf-8
|
||||||
|
#
|
||||||
|
# This file is part of Supysonic.
|
||||||
|
# Supysonic is a Python implementation of the Subsonic server API.
|
||||||
|
#
|
||||||
|
# Copyright (C) 2013-2017 Alban 'spl0k' Féron
|
||||||
|
#
|
||||||
|
# Distributed under terms of the GNU AGPLv3 license.
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from supysonic.db import Folder
|
||||||
|
|
||||||
|
from .frontendtestbase import FrontendTestBase
|
||||||
|
|
||||||
|
class FolderTestCase(FrontendTestBase):
|
||||||
|
__module_to_test__ = 'supysonic.frontend'
|
||||||
|
|
||||||
|
def test_index(self):
|
||||||
|
self._login('bob', 'B0b')
|
||||||
|
rv = self.client.get('/folder', follow_redirects = True)
|
||||||
|
self.assertIn('There\'s nothing much to see', rv.data)
|
||||||
|
self.assertNotIn('Music folders', rv.data)
|
||||||
|
self._logout()
|
||||||
|
|
||||||
|
self._login('alice', 'Alic3')
|
||||||
|
rv = self.client.get('/folder')
|
||||||
|
self.assertIn('Music folders', rv.data)
|
||||||
|
|
||||||
|
def test_add_get(self):
|
||||||
|
self._login('bob', 'B0b')
|
||||||
|
rv = self.client.get('/folder/add', follow_redirects = True)
|
||||||
|
self.assertIn('There\'s nothing much to see', rv.data)
|
||||||
|
self.assertNotIn('Add folder', rv.data)
|
||||||
|
self._logout()
|
||||||
|
|
||||||
|
self._login('alice', 'Alic3')
|
||||||
|
rv = self.client.get('/folder/add')
|
||||||
|
self.assertIn('Add Folder', rv.data)
|
||||||
|
|
||||||
|
def test_add_post(self):
|
||||||
|
self._login('alice', 'Alic3')
|
||||||
|
rv = self.client.post('/folder/add')
|
||||||
|
self.assertIn('required', rv.data)
|
||||||
|
rv = self.client.post('/folder/add', data = { 'name': 'name' })
|
||||||
|
self.assertIn('required', rv.data)
|
||||||
|
rv = self.client.post('/folder/add', data = { 'path': 'path' })
|
||||||
|
self.assertIn('required', rv.data)
|
||||||
|
rv = self.client.post('/folder/add', data = { 'name': 'name', 'path': 'path' })
|
||||||
|
self.assertIn('Add Folder', rv.data)
|
||||||
|
rv = self.client.post('/folder/add', data = { 'name': 'name', 'path': 'tests/assets' }, follow_redirects = True)
|
||||||
|
self.assertIn('created', rv.data)
|
||||||
|
self.assertEqual(self.store.find(Folder).count(), 1)
|
||||||
|
|
||||||
|
def test_delete(self):
|
||||||
|
folder = Folder()
|
||||||
|
folder.name = 'folder'
|
||||||
|
folder.path = 'tests/assets'
|
||||||
|
folder.root = True
|
||||||
|
self.store.add(folder)
|
||||||
|
self.store.commit()
|
||||||
|
|
||||||
|
self._login('bob', 'B0b')
|
||||||
|
rv = self.client.get('/folder/del/' + str(folder.id), follow_redirects = True)
|
||||||
|
self.assertIn('There\'s nothing much to see', rv.data)
|
||||||
|
self.assertEqual(self.store.find(Folder).count(), 1)
|
||||||
|
self._logout()
|
||||||
|
|
||||||
|
self._login('alice', 'Alic3')
|
||||||
|
rv = self.client.get('/folder/del/string', follow_redirects = True)
|
||||||
|
self.assertIn('Invalid', rv.data)
|
||||||
|
rv = self.client.get('/folder/del/' + str(uuid.uuid4()), follow_redirects = True)
|
||||||
|
self.assertIn('No such folder', rv.data)
|
||||||
|
rv = self.client.get('/folder/del/' + str(folder.id), follow_redirects = True)
|
||||||
|
self.assertIn('Music folders', rv.data)
|
||||||
|
self.assertEqual(self.store.find(Folder).count(), 0)
|
||||||
|
|
||||||
|
def test_scan(self):
|
||||||
|
folder = Folder()
|
||||||
|
folder.name = 'folder'
|
||||||
|
folder.path = 'tests/assets'
|
||||||
|
folder.root = True
|
||||||
|
self.store.add(folder)
|
||||||
|
self.store.commit()
|
||||||
|
self._login('alice', 'Alic3')
|
||||||
|
|
||||||
|
rv = self.client.get('/folder/scan/string', follow_redirects = True)
|
||||||
|
self.assertIn('Invalid', rv.data)
|
||||||
|
rv = self.client.get('/folder/scan/' + str(uuid.uuid4()), follow_redirects = True)
|
||||||
|
self.assertIn('No such folder', rv.data)
|
||||||
|
rv = self.client.get('/folder/scan/' + str(folder.id), follow_redirects = True)
|
||||||
|
self.assertIn('Added', rv.data)
|
||||||
|
self.assertIn('Deleted', rv.data)
|
||||||
|
rv = self.client.get('/folder/scan', follow_redirects = True)
|
||||||
|
self.assertIn('Added', rv.data)
|
||||||
|
self.assertIn('Deleted', rv.data)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
@ -14,9 +14,9 @@ import uuid
|
|||||||
|
|
||||||
from supysonic.db import User
|
from supysonic.db import User
|
||||||
|
|
||||||
from ..testbase import TestBase
|
from .frontendtestbase import FrontendTestBase
|
||||||
|
|
||||||
class LoginTestCase(TestBase):
|
class LoginTestCase(FrontendTestBase):
|
||||||
__module_to_test__ = 'supysonic.frontend'
|
__module_to_test__ = 'supysonic.frontend'
|
||||||
|
|
||||||
def test_unauthorized_request(self):
|
def test_unauthorized_request(self):
|
||||||
@ -26,25 +26,25 @@ class LoginTestCase(TestBase):
|
|||||||
|
|
||||||
def test_login_with_bad_data(self):
|
def test_login_with_bad_data(self):
|
||||||
# Login with not blank user or password
|
# Login with not blank user or password
|
||||||
rv = self.client.post('/user/login', data=dict(name='', password=''), follow_redirects=True)
|
rv = self._login('', '')
|
||||||
self.assertIn('Missing user name', rv.data)
|
self.assertIn('Missing user name', rv.data)
|
||||||
self.assertIn('Missing password', rv.data)
|
self.assertIn('Missing password', rv.data)
|
||||||
# Login with not valid user or password
|
# Login with not valid user or password
|
||||||
rv = self.client.post('/user/login', data=dict(user='nonexistent', password='nonexistent'), follow_redirects=True)
|
rv = self._login('nonexistent', 'nonexistent')
|
||||||
self.assertIn('No such user', rv.data)
|
self.assertIn('No such user', rv.data)
|
||||||
rv = self.client.post('/user/login', data=dict(user='alice', password='badpassword'), follow_redirects=True)
|
rv = self._login('alice', 'badpassword')
|
||||||
self.assertIn('Wrong password', rv.data)
|
self.assertIn('Wrong password', rv.data)
|
||||||
|
|
||||||
def test_login_admin(self):
|
def test_login_admin(self):
|
||||||
# Login with a valid admin user
|
# Login with a valid admin user
|
||||||
rv = self.client.post('/user/login', data=dict(user='alice', password='Alic3'), follow_redirects=True)
|
rv = self._login('alice', 'Alic3')
|
||||||
self.assertIn('Logged in', rv.data)
|
self.assertIn('Logged in', rv.data)
|
||||||
self.assertIn('Users', rv.data)
|
self.assertIn('Users', rv.data)
|
||||||
self.assertIn('Folders', rv.data)
|
self.assertIn('Folders', rv.data)
|
||||||
|
|
||||||
def test_login_non_admin(self):
|
def test_login_non_admin(self):
|
||||||
# Login with a valid non-admin user
|
# Login with a valid non-admin user
|
||||||
rv = self.client.post('/user/login', data=dict(user='bob', password='B0b'), follow_redirects=True)
|
rv = self._login('bob', 'B0b')
|
||||||
self.assertIn('Logged in', rv.data)
|
self.assertIn('Logged in', rv.data)
|
||||||
# Non-admin user cannot acces to users and folders
|
# Non-admin user cannot acces to users and folders
|
||||||
self.assertNotIn('Users', rv.data)
|
self.assertNotIn('Users', rv.data)
|
||||||
@ -74,5 +74,12 @@ class LoginTestCase(TestBase):
|
|||||||
rv = self.client.get('/', follow_redirects=True)
|
rv = self.client.get('/', follow_redirects=True)
|
||||||
self.assertIn('Please login', rv.data)
|
self.assertIn('Please login', rv.data)
|
||||||
|
|
||||||
|
def test_multiple_login(self):
|
||||||
|
self._login('alice', 'Alic3')
|
||||||
|
rv = self._login('bob', 'B0b')
|
||||||
|
self.assertIn('Already logged in', rv.data)
|
||||||
|
self.assertIn('alice', rv.data)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user