Adding support for DB access from unit tests
[ipypbx] / src / ipypbx / tests / support.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)
+