[glom] Added SQLite database creation test
- From: Armin Burgmeier <arminb src gnome org>
- To: svn-commits-list gnome org
- Subject: [glom] Added SQLite database creation test
- Date: Wed, 17 Jun 2009 15:38:21 -0400 (EDT)
commit c4cda903442b374ed20fd806367065f436543d06
Author: Armin Burgmeier <armin arbur net>
Date: Wed Jun 17 21:32:04 2009 +0200
Added SQLite database creation test
* ldtp/common.py: Added a common function to launch glom and wait for
its windows to appear into a new separate python script file.
* ldtp/database-creation/create_db.py: Added a function to create a
new database, with the backend to use as an argument. This allows to
reuse the existing code to test other backends.
* ldtp/database-creation/self-hosted.py: Adapted accordingly.
* ldtp/database-creation/sqlite.py: Added a test file to check whether
SQLite database creation works.
* ldty/test.xml: Added the test to create an SQLite database.
ChangeLog | 16 ++++
ldtp/common.py | 20 +++++
ldtp/database-creation/create_db.py | 128 +++++++++++++++++++++++++++++++++
ldtp/database-creation/self-hosted.py | 127 ++------------------------------
ldtp/database-creation/sqlite.py | 13 ++++
ldtp/test.xml | 1 +
6 files changed, 185 insertions(+), 120 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 043a9e0..765ea9d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2009-06-17 Armin Burgmeier <armin openismus com>
+
+ * ldtp/common.py: Added a common function to launch glom and wait for
+ its windows to appear into a new separate python script file.
+
+ * ldtp/database-creation/create_db.py: Added a function to create a
+ new database, with the backend to use as an argument. This allows to
+ reuse the existing code to test other backends.
+
+ * ldtp/database-creation/self-hosted.py: Adapted accordingly.
+
+ * ldtp/database-creation/sqlite.py: Added a test file to check whether
+ SQLite database creation works.
+
+ * ldty/test.xml: Added the test to create an SQLite database.
+
2009-06-08 Armin Burgmeier <armin openismus com>
* ldtp/database-creation/self-hosted.py: Added a LDTP test script
diff --git a/ldtp/common.py b/ldtp/common.py
new file mode 100644
index 0000000..e352e68
--- /dev/null
+++ b/ldtp/common.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+
+import ldtp
+
+main_window = '*Glom*'
+initial_dialog = 'WelcometoGlom'
+
+def launch_glom():
+ # Start glom:
+ ldtp.launchapp('glom')
+
+ # Wait for the initial dialog to appear. The argument matches on the
+ # Window title, so make sure to set a window title in Glade or in the
+ # code for each window.
+ # Wildcard (* and ?) can be used.
+ if ldtp.waittillguiexist(main_window) == 0:
+ raise ldtp.LdtpExecutionError('Glom main window does not show up')
+ print initial_dialog
+ if ldtp.waittillguiexist(initial_dialog) == 0:
+ raise ldtp.LdtpExecutionError('Glom initial dialog does not show up')
diff --git a/ldtp/database-creation/create_db.py b/ldtp/database-creation/create_db.py
new file mode 100755
index 0000000..681bb32
--- /dev/null
+++ b/ldtp/database-creation/create_db.py
@@ -0,0 +1,128 @@
+#!/usr/bin/python
+from ldtp import *
+from ldtputils import *
+
+sys.path = ['..'] + sys.path
+import common
+
+import os
+import shutil
+import threading
+
+class BackendUnavailableError (Exception):
+ def __str__ (self):
+ return 'Backend not available'
+
+# TODO: Avoid these being global variables:
+errorMessage = ''
+errorHappened = threading.Event()
+errorHappened.clear()
+
+def error_cb():
+ global errorMessage
+ # We already stop at the first error that occurs
+ if not errorHappened.isSet():
+ # TODO: Read the actual error message from the error
+ # dialog window:
+ errorMessage = 'Failed to create new database'
+ errorHappened.set()
+
+def test_create_db(button_texts):
+ try:
+ common.launch_glom()
+
+ # Create a new document from the Small Business Example:
+ # The notebook and treeview widgets are accessed via their
+ # "accessible name". It can be set in Glade on the Accessibility tab,
+ # or in code via widget->get_accessible()->set_name("").
+ # It is meant to be a human-readable, translatable string describing
+ # the widget. To access the widget in LDTP, all spaces are removed
+ # from that string, so "Create New Document" becomes
+ # "CreateNewDocument". Each widget type also has an (optional, I
+ # believe) prefix, for example notebooks are prefixed by 'ptl' and
+ # treeviews are prefixed by 'ttbl'.
+ selecttab(common.initial_dialog, 'ptlOpenorcreateDocument', 'Create New Document')
+ selectrow(common.initial_dialog, 'ttblCreateNewDocument', 'Small Business Example')
+
+ # Buttons (prefix: 'btn') are addressed via their label text:
+ click(common.initial_dialog, 'btnSelect')
+
+ # Create a directory into which to create the new Glom document:
+ if not os.path.exists('TestDatabase'):
+ os.mkdir('TestDatabase')
+
+ # Wait for the file chooser dialog to appear:
+ if waittillguiexist('Creating From Example File') == 0:
+ raise LdtpExecutionError('File chooser does not show up')
+
+ # Navigate into the newly created folder:
+ doubleclickrow('Creating From Example File', 'tblFiles', 'TestDatabase')
+
+ # Call the new document 'Test':
+ settextvalue('Creating From Example File', 'txtName', 'Test');
+
+ # Make sure we use the self-hosted postgresql backend:
+ for text in button_texts:
+ if objectexist('Creating From Example File', 'rbtn' + text):
+ click('Creating From Example File', 'rbtn' + text)
+ break
+ else:
+ raise LdtpExecutionError('Backend not supported')
+ #raise NoBackendError; TODO
+
+ # Make sure the Glom main window still exists
+ if not guiexist(common.main_window):
+ raise LdtpExecutionError('The Glom main window does not exist anymore')
+
+ # Be notified when error dialogs pop up during database creation
+ onwindowcreate('Warning', error_cb)
+ onwindowcreate('Error', error_cb)
+
+ # Acknowledge the dialog:
+ click('Creating From Example File', 'btnSave')
+
+ # Wait for the list view to pop up in the main Glom window:
+ # Note that the Window title of the Glom Window changes when the file
+ # has loaded. If we use wildcards for the Window title (*Glom*) here,
+ # then objectexist does not find the notebook_data
+ # (ptlListOrDetailsView) widget, even when it has actually appeared.
+ # TODO: Maybe we can use setcontext(), to avoid this.
+ # TODO: Or maybe this has been fixed in LDTP in the meanwhile,
+ # see bug #583021.
+ while not guiexist('Glom-SmallBusinessExample') or not objectexist('Glom-SmallBusinessExample', 'ptlListOrDetailsView'):
+ if errorHappened.isSet():
+ raise LdtpExecutionError(errorMessage)
+ # Wait a bit and then try again:
+ wait()
+
+ # Everything finished, so check the created database for consistency.
+ if(getrowcount(common.main_window, 'tblTableContent') != 9):
+ raise LdtpExecutionError("Newly created database does not contain all 8 rows"); # Note there is one placeholder row
+
+ selecttab(common.main_window, 'ptlListOrDetailsView', 'Details')
+
+ # TODO: Check that there is an image present.
+ # Accerciser shows the Image Size for the widget which we may use to
+ # check this. However, LDTP does not implement this yet.
+
+ # Exit the application. Here, the wildcard *Glom* works again. I
+ # suppose this is because the menu already existed when we used the
+ # Wildcard for the first time, in contrast to the notebook_data.
+ selectmenuitem(common.main_window, 'mnuFile;mnuClose')
+
+ if waittillguinotexist('Glom-SmallBusinessExample') == 0:
+ raise LdtpExecutionError('The Glom Window does not disappear after closing the application')
+
+ # Remove the test database again
+ shutil.rmtree('TestDatabase')
+
+ except LdtpExecutionError, msg:
+ log(msg, 'fail')
+
+ # Remove the created directory also on error, so that the test
+ # does not fail because of the database already existing next time
+ shutil.rmtree('TestDatabase')
+
+ raise LdtpExecutionError (msg)
+ # TODO: Terminate the Glom application
+ # os.kill(whatpid?, signal.SIGTERM)
diff --git a/ldtp/database-creation/self-hosted.py b/ldtp/database-creation/self-hosted.py
index b5e7f68..94860fa 100755
--- a/ldtp/database-creation/self-hosted.py
+++ b/ldtp/database-creation/self-hosted.py
@@ -1,123 +1,10 @@
#!/usr/bin/python
-from ldtp import *
-from ldtputils import *
-
-import os
-import shutil
-import threading
-
-errorMessage = ''
-errorHappened = threading.Event()
-errorHappened.clear()
-
-def error_cb():
- global errorMessage
- # We already stop at the first error that occurs
- if not errorHappened.isSet():
- # TODO: Read the actual error message from the error
- # dialog window:
- errorMessage = 'Failed to create new database'
- errorHappened.set()
+import create_db
try:
- # Start glom:
- launchapp('glom')
-
- # Wait for the initial dialog to appear. The argument matches on the
- # Window title, so make sure to set a window title in Glade or in the
- # code for each window.
- # Wildcard (* and ?) can be used.
- if waittillguiexist('*Glom*') == 0:
- raise LdtpExecutionError('Glom main window does not show up')
- if waittillguiexist('Welcome to Glom') == 0:
- raise LdtpExecutionError('Glom initial dialog does not show up')
-
- # Create a new document from the Small Business Example:
- # The notebook and treeview widgets are accessed via their
- # "accessible name". It can be set in Glade on the Accessibility tab,
- # or in code via widget->get_accessible()->set_name("").
- # It is meant to be a human-readable, translatable string describing
- # the widget. To access the widget in LDTP, all spaces are removed
- # from that string, so "Create New Document" becomes
- # "CreateNewDocument". Each widget type also has an (optional, I
- # believe) prefix, for example notebooks are prefixed by 'ptl' and
- # treeviews are prefixed by 'ttbl'.
- selecttab('Welcome to Glom', 'ptlOpenorcreateDocument', 'Create New Document')
- selectrow('Welcome to Glom', 'ttblCreateNewDocument', 'Small Business Example')
-
- # Buttons (prefix: 'btn') are addressed via their label text:
- click('Welcome to Glom', 'btnSelect')
-
- # Create a directory into which to create the new Glom documents:
- if not os.path.exists('TestDatabase'):
- os.mkdir('TestDatabase')
-
- # Wait for the file chooser dialog to appear:
- if waittillguiexist('Creating From Example File') == 0:
- raise LdtpExecutionError('File chooser does not show up')
-
- # Navigate into the newly created folder:
- doubleclickrow('Creating From Example File', 'tblFiles', 'TestDatabase')
-
- # Call the new document 'Test':
- settextvalue('Creating From Example File', 'txtName', 'Test');
-
- # Make sure we use the self-hosted postgresql backend:
- click('Creating From Example File', 'rbtnCreatePostgreSQLdatabaseinitsownfolder,tobehostedbythiscomputer.')
-
- # Make sure the Glom main window still exists
- if not guiexist('*Glom*'):
- raise LdtpExecutionError('The Glom main window does not exist anymore')
-
- # Be notified when error dialogs pop up during database creation
- onwindowcreate('Warning', error_cb)
- onwindowcreate('Error', error_cb)
-
- # Acknowledge the dialog:
- click('Creating From Example File', 'btnSave')
-
- # Wait for the list view to pop up in the main Glom window:
- # Note that the Window title of the Glom Window changes when the file
- # has loaded. If we use wildcards for the Window title (*Glom*) here,
- # then objectexist does not find the notebook_data
- # (ptlListOrDetailsView) widget, even when it has actually appeared.
- # TODO: Maybe we can use setcontext(), to avoid this.
- # TODO: Or maybe this has been fixed in LDTP in the meanwhile,
- # see bug #583021.
- while not guiexist('Glom-SmallBusinessExample') or not objectexist('Glom-SmallBusinessExample', 'ptlListOrDetailsView'):
- if errorHappened.isSet():
- raise LdtpExecutionError(errorMessage)
- # Wait a bit and then try again:
- wait()
-
- # Everything finished, so check the created database for consistency.
- if(getrowcount('*Glom*', 'tblTableContent') != 9):
- raise LdtpExecutionError("Newly created database does not contain all 8 rows"); # Note there is one placeholder row
-
- selecttab('*Glom*', 'ptlListOrDetailsView', 'Details')
-
- # TODO: Check that there is an image present.
- # Accerciser shows the Image Size for the widget which we may use to
- # check this. However, LDTP does not implement this yet.
-
- # Exit the application. Here, the wildcard *Glom* works again. I
- # suppose this is because the menu already existed when we used the
- # Wildcard for the first time, in contrast to the notebook_data.
- selectmenuitem('*Glom*', 'mnuFile;mnuClose')
-
- if waittillguinotexist('Glom-SmallBusinessExample') == 0:
- raise LdtpExecutionError('The Glom Window does not disappear after closing the application')
-
- # Remove the test database again
- shutil.rmtree('TestDatabase')
-
-except LdtpExecutionError, msg:
- print msg
-
- # Remove the created directory also on error, so that the test
- # does not fail because of the database already existing next time
- shutil.rmtree('TestDatabase')
-
- raise LdtpExecutionError (msg)
-# TODO: Terminate the Glom application
-# os.kill(whatpid?, signal.SIGTERM)
+ create_db.test_create_db([
+ 'CreatePostgreSQLdatabaseinitsownfolder,tobehostedbythiscomputer.',
+ 'Createdatabaseinitsownfolder,tobehostedbythiscomputer.'
+ ])
+except create_db.BackendUnavailableError:
+ raise LdtpExecutionError('Self-hosted postgresql backend not available')
diff --git a/ldtp/database-creation/sqlite.py b/ldtp/database-creation/sqlite.py
new file mode 100755
index 0000000..9275025
--- /dev/null
+++ b/ldtp/database-creation/sqlite.py
@@ -0,0 +1,13 @@
+#!/usr/bin/python
+import create_db
+
+try:
+ create_db.test_create_db([
+ 'CreateSQLitedatabaseinitsownfolder,tobehostedbythiscomputer.',
+ 'Createdatabaseinitsownfolder,tobehostedbythiscomputer,usingSQLite.'
+ ])
+except create_db.BackendUnavailableError:
+ raise LdtpExecutionError('Self-hosted postgresql backend not available')
+
+
+
diff --git a/ldtp/test.xml b/ldtp/test.xml
index ce4c295..9edfa18 100644
--- a/ldtp/test.xml
+++ b/ldtp/test.xml
@@ -7,6 +7,7 @@
<comment>Test whether creation of a new database work for all available backends</comment>
<script>
<name>database-creation/self-hosted.py</name>
+ <name>database-creation/sqlite.py</name>
</script>
</group>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]