# HG changeset patch # User Denis Laxalde # Date 1472214685 -7200 # Node ID 628dd583249514d87b840b78f6773c506b5311d2 # Parent ae58ba20418cb1069239e38ab0d29d3f46af2a9b [test] Add a test for toolsutils.read_config diff -r ae58ba20418c -r 628dd5832495 cubicweb/test/unittest_toolsutils.py --- a/cubicweb/test/unittest_toolsutils.py Fri Aug 26 13:56:59 2016 +0200 +++ b/cubicweb/test/unittest_toolsutils.py Fri Aug 26 14:31:25 2016 +0200 @@ -17,9 +17,10 @@ # with CubicWeb. If not, see . +import tempfile import unittest -from cubicweb.toolsutils import RQLExecuteMatcher +from cubicweb.toolsutils import RQLExecuteMatcher, read_config class RQLExecuteMatcherTests(unittest.TestCase): @@ -53,5 +54,48 @@ self.assertEqual(query, 'Any X WHERE X is ') +SOURCES_CONTENT = b""" +[admin] + +# cubicweb manager account's login (this user will be created) +login=admin + +# cubicweb manager account's password +password=admin + +[system] + +# database driver (postgres, sqlite, sqlserver2005) +db-driver=postgres + +# database host +db-host= + +# database port +db-port= +""" + + +class ToolsUtilsTC(unittest.TestCase): + + def test_read_config(self): + with tempfile.NamedTemporaryFile() as f: + f.write(SOURCES_CONTENT) + f.seek(0) + config = read_config(f.name) + expected = { + 'admin': { + 'password': 'admin', + 'login': 'admin', + }, + 'system': { + 'db-port': None, + 'db-driver': 'postgres', + 'db-host': None, + }, + } + self.assertEqual(config, expected) + + if __name__ == '__main__': unittest.main()