Adding support for DB access from unit tests
authorStas Shtin <antisvin@gmail.com>
Tue, 20 Apr 2010 14:22:43 +0000 (18:22 +0400)
committerStas Shtin <antisvin@gmail.com>
Tue, 20 Apr 2010 14:22:43 +0000 (18:22 +0400)
src/ipypbx/tests/support.py [new file with mode: 0644]
src/ipypbx/tests/test_http.py

diff --git a/src/ipypbx/tests/support.py b/src/ipypbx/tests/support.py
new file mode 100644 (file)
index 0000000..8cde219
--- /dev/null
@@ -0,0 +1,32 @@
+# Copyright (c) Stas Shtin, 2010
+
+# This file is part of IPyPBX.
+
+# IPyPBX is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# IPyPBX is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with IPyPBX.  If not, see <http://www.gnu.org/licenses/>.
+
+from ipypbx import main
+
+class InitDatabase(object):
+    _tables = (
+        'connection', 'sipprofile', 'domain', 'gateway', 'endpoint',
+        'extension')
+    
+    @classmethod
+    def setUpClass(cls):
+        cls.db, _created = main.setupDb(dbname=':memory:')
+
+    def setUp(self):
+        for table in self._tables:
+            self.db.exec_('delete from ipypbxweb_%s' % table)
+            
index 47251c2..180b124 100644 (file)
@@ -17,6 +17,7 @@
 
 import unittest
 from ipypbx import http
+from ipypbx.tests import support
 
 
 class TestHttpRequestParser(unittest.TestCase):
@@ -124,3 +125,6 @@ class TestHttpRequestParser(unittest.TestCase):
             'Only post requests work')
 
         
+class TestFreeswitchConfigGenerator(support.InitDatabase, unittest.TestCase):
+    def test_foo(self):
+        print self.db