mirror of
https://github.com/spl0k/supysonic.git
synced 2024-11-09 19:52:16 +00:00
WIP: Adding unit tests for API User
This commit is contained in:
parent
9fcd4e8c52
commit
d4b3074662
@ -6,13 +6,15 @@
|
||||
#
|
||||
# Distributed under terms of the GNU GPLv3 license.
|
||||
|
||||
from .test_folder_manager import FolderManagerTestCase
|
||||
from .test_user_manager import UserManagerTestCase
|
||||
from .test_api_user import ApiUserTestCase
|
||||
#from .test_folder_manager import FolderManagerTestCase
|
||||
#from .test_user_manager import UserManagerTestCase
|
||||
|
||||
import unittest
|
||||
#import unittest
|
||||
|
||||
def suite():
|
||||
suite = unittest.TestSuite()
|
||||
suite.addTest(FolderManagerTestCase())
|
||||
suite.addTest(UserManagerTestCase())
|
||||
return suite
|
||||
#def suite():
|
||||
# suite = unittest.TestSuite()
|
||||
# suite.addTest(ApiUserTestCase())
|
||||
#suite.addTest(FolderManagerTestCase())
|
||||
#suite.addTest(UserManagerTestCase())
|
||||
# return suite
|
||||
|
49
tests/test_api_user.py
Normal file
49
tests/test_api_user.py
Normal file
@ -0,0 +1,49 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
#
|
||||
# Copyright © 2017 Óscar García Amor <ogarcia@connectical.com>
|
||||
#
|
||||
# Distributed under terms of the GNU GPLv3 license.
|
||||
|
||||
from supysonic import db
|
||||
from supysonic.managers.user import UserManager
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
import uuid
|
||||
|
||||
class ApiUserTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# Create an empty sqlite database in memory
|
||||
self.store = db.get_store("sqlite:")
|
||||
# Read schema from file
|
||||
with open('schema/sqlite.sql') as sql:
|
||||
schema = sql.read()
|
||||
# Create tables on memory database
|
||||
for command in schema.split(';'):
|
||||
self.store.execute(command)
|
||||
# Create some users
|
||||
self.assertEqual(UserManager.add(self.store, 'alice', 'alice', 'test@example.com', True), UserManager.SUCCESS)
|
||||
self.assertEqual(UserManager.add(self.store, 'bob', 'bob', 'bob@example.com', False), UserManager.SUCCESS)
|
||||
self.assertEqual(UserManager.add(self.store, 'charlie', 'charlie', 'charlie@example.com', False), UserManager.SUCCESS)
|
||||
# Create a mockup of web
|
||||
from flask import Flask
|
||||
self.app = Flask(__name__)
|
||||
class web():
|
||||
app = self.app
|
||||
store = self.store
|
||||
sys.modules['supysonic.web'] = web()
|
||||
# Import module and set app in test mode
|
||||
from supysonic.api.user import user_info
|
||||
self.app.testing = True
|
||||
self.app = self.app.test_client()
|
||||
|
||||
def test_user_info(self):
|
||||
rv = self.app.get('/rest/getUser.view?u=alice&p=alice&c=test')
|
||||
assert 'message="Missing username"' in rv.data
|
||||
rv = self.app.get('/rest/getUser.view?u=alice&p=alice&c=test&username=alice')
|
||||
assert 'adminRole="true"' in rv.data
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
Reference in New Issue
Block a user