[glom] Added a new LDTP test which tests creating a centrally hosted database
- From: Armin Burgmeier <arminb src gnome org>
- To: svn-commits-list gnome org
- Subject: [glom] Added a new LDTP test which tests creating a centrally hosted database
- Date: Wed, 24 Jun 2009 17:01:29 +0000 (UTC)
commit 5b024258507cf1bd8ffdfad64ba8c50af2fea12a
Author: Armin Burgmeier <armin arbur net>
Date: Sat Jun 20 17:49:02 2009 +0200
Added a new LDTP test which tests creating a centrally hosted database
* glom/glom.glade: Added a title to the connection dialog window, and
added accessible names for the entries, to be able to use them via
LDTP.
* ldtp/README: Describe how to set the login credentials required
to test creating a centrally hosted database.
* ldtp/common.py: Moved useful code from
ldtp/database-creation/create-db.py into functions in this file, so
other tests can use them, too.
* ldtp/database-creation/create-db.py: Adapt accordingly.
* ldtp/database-creation/create-central-db.py:
* ldtp/database-creation/postgres-central.xml: Added a new test script
and data XML which tests creating a centrally hosted database.
* ldtp/test.xml: Added the new script file.
ChangeLog | 21 ++++++
glom/glom.glade | 22 ++++++
ldtp/README | 17 ++++-
ldtp/common.py | 76 +++++++++++++++++++++-
ldtp/database-creation/create-central-db.py | 95 +++++++++++++++++++++++++++
ldtp/database-creation/create-db.py | 65 ++----------------
ldtp/database-creation/postgres-central.xml | 8 ++
ldtp/test.xml | 4 +
8 files changed, 247 insertions(+), 61 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f7ad89a..85b5b57 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,26 @@
2009-06-24 Armin Burgmeier <armin openismus com>
+ * glom/glom.glade: Added a title to the connection dialog window, and
+ added accessible names for the entries, to be able to use them via
+ LDTP.
+
+ * ldtp/README: Describe how to set the login credentials required
+ to test creating a centrally hosted database.
+
+ * ldtp/common.py: Moved useful code from
+ ldtp/database-creation/create-db.py into functions in this file, so
+ other tests can use them, too.
+
+ * ldtp/database-creation/create-db.py: Adapt accordingly.
+
+ * ldtp/database-creation/create-central-db.py:
+ * ldtp/database-creation/postgres-central.xml: Added a new test script
+ and data XML which tests creating a centrally hosted database.
+
+ * ldtp/test.xml: Added the new script file.
+
+2009-06-24 Armin Burgmeier <armin openismus com>
+
* glom/application.cc (on_document_load): Only provide a known user
name and password for self-hosted databases, and ask the user for the
database password for centrally-hosted ones.
diff --git a/glom/glom.glade b/glom/glom.glade
index 1a58411..4f15383 100644
--- a/glom/glom.glade
+++ b/glom/glom.glade
@@ -414,6 +414,7 @@
</action-widgets>
</object>
<object class="GtkDialog" id="dialog_connection">
+ <property name="title" translatable="yes">Connection Details</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkVBox" id="vbox27">
@@ -487,6 +488,11 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">•</property>
+ <child internal-child="accessible">
+ <object class="AtkObject" id="entry_host-atkobject">
+ <property name="AtkObject::accessible-name" translatable="yes">Host</property>
+ </object>
+ </child>
</object>
<packing>
<property name="left_attach">1</property>
@@ -502,6 +508,11 @@
<property name="visibility">False</property>
<property name="invisible_char">•</property>
<property name="activates_default">True</property>
+ <child internal-child="accessible">
+ <object class="AtkObject" id="entry_password-atkobject">
+ <property name="AtkObject::accessible-name" translatable="yes">Password</property>
+ </object>
+ </child>
</object>
<packing>
<property name="left_attach">1</property>
@@ -516,6 +527,11 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">•</property>
+ <child internal-child="accessible">
+ <object class="AtkObject" id="entry_user-atkobject">
+ <property name="AtkObject::accessible-name" translatable="yes">User</property>
+ </object>
+ </child>
</object>
<packing>
<property name="left_attach">1</property>
@@ -594,6 +610,12 @@
<object class="GtkLabel" id="label_database">
<property name="visible">True</property>
<property name="xalign">0</property>
+ <property name="selectable">True</property>
+ <child internal-child="accessible">
+ <object class="AtkObject" id="label_database-atkobject">
+ <property name="AtkObject::accessible-name" translatable="yes">Database</property>
+ </object>
+ </child>
</object>
<packing>
<property name="left_attach">1</property>
diff --git a/ldtp/README b/ldtp/README
index 91d89ed..d595510 100644
--- a/ldtp/README
+++ b/ldtp/README
@@ -7,5 +7,18 @@ single test, simply launch the corresponding python script, such as
database-creation/self-hosted.py
-To add a new test, create a corresponding python script file and it to the
-list in test.xml.
+Make sure to execute all scripts from the glom/ldtp directory, they might not
+find required files otherwise. For the tests which test central hosting,
+create a file called central-info.xml in the same directory as this README
+file, with the following content:
+
+ <data>
+ <hostname>localhost</hostname>
+ <username>username</username>
+ <password>password</password>
+ </data>
+
+This provides the required information for the database to connect to.
+
+To add a new test, create a corresponding python script file, and add it to
+the list in test.xml.
diff --git a/ldtp/common.py b/ldtp/common.py
index e352e68..88d0ef4 100644
--- a/ldtp/common.py
+++ b/ldtp/common.py
@@ -1,10 +1,23 @@
#!/usr/bin/python
+import threading
import ldtp
+import ldtputils
main_window = '*Glom*'
initial_dialog = 'WelcometoGlom'
+error_message = ''
+error_happened = threading.Event()
+error_happened.clear()
+
+def error_cb():
+ global error_message
+ if not error_happened.isSet():
+ # TODO: Read the actual error message from the dialog window
+ error_message = 'Failed to create new database'
+ error_happened.set()
+
def launch_glom():
# Start glom:
ldtp.launchapp('glom')
@@ -15,6 +28,67 @@ def launch_glom():
# 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')
+
+def exit_glom():
+ ldtp.selectmenuitem(main_window, 'mnuFile;mnuClose')
+
+ if ldtp.waittillguinotexist('Glom-SmallBusinessExample') == 0:
+ raise ldtp.LdtpExecutionError('The Glom Window does not disappear after closing the application')
+
+# Reads hostname, username and password to use for access to a
+# centrally hosted database server
+def read_central_info():
+ info = ldtputils.LdtpDataFileParser('central-info.xml')
+ ret = [info.gettagvalue('hostname'), info.gettagvalue('username'), info.gettagvalue('password')]
+ if len(ret[0]) == 0 or len(ret[1]) == 0 or len(ret[2]) == 0:
+ raise ldtp.LdtpExecutionError('Connection details for centrally hosted database not provided. See the README file for how to provide the details.')
+ return [ret[0], ret[1], ret[2]]
+
+# Selects one of the backends in button_texts in the database creation dialog
+def select_backend(backend_name, button_texts):
+ for text in button_texts:
+ if ldtp.objectexist('Creating From Example File', 'rbtn' + text):
+ ldtp.click('Creating From Example File', 'rbtn' + text)
+ break
+ else:
+ raise ldtp.LdtpExecutionError('Backend ' + backend + ' not supported')
+
+def wait_for_database_open():
+ # Be notified when an error dialog pops up
+ ldtp.onwindowcreate('Warning', error_cb)
+ ldtp.onwindowcreate('Error', error_cb)
+
+ # Maybe one exists already:
+ if ldtp.guiexist('Warning') or ldtp.guiexist('Error'):
+ error_cb()
+
+ # 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 ldtp.guiexist('Glom-SmallBusinessExample') or not ldtp.objectexist('Glom-SmallBusinessExample', 'ptlListOrDetailsView'):
+ if error_happened.isSet():
+ raise ldtp.LdtpExecutionError(error_message)
+ # Wait a bit and then try again:
+ ldtp.wait()
+
+ # TODO: This doesn't seem to work currently, maybe has something to
+ # do with bug #586291.
+# ldtp.removecallback('Warning')
+# ldtp.removecallback('Error')
+
+def check_small_business_integrity():
+ if(ldtp.getrowcount(main_window, 'tblTableContent') != 9):
+ raise ldtp.LdtpExecutionError("Newly created database does not contain all 8 rows"); # Note there is one placeholder row
+
+ ldtp.selecttab(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.
diff --git a/ldtp/database-creation/create-central-db.py b/ldtp/database-creation/create-central-db.py
new file mode 100755
index 0000000..089fed8
--- /dev/null
+++ b/ldtp/database-creation/create-central-db.py
@@ -0,0 +1,95 @@
+#!/usr/bin/python
+from ldtp import *
+from ldtputils import *
+
+sys.path = ['..'] + sys.path
+import common
+
+import os
+import shutil
+
+try:
+ xml = LdtpDataFileParser(datafilename)
+ backend = xml.gettagvalue('backend')[0]
+ button_texts = xml.gettagvalue('button_text')
+
+ common.launch_glom()
+
+ # Read info for database connection
+ (hostname, username, password) = common.read_central_info()
+
+ # 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')
+
+ # Wait for the file chooser dialog to appear:
+ if waittillguiexist('Creating From Example File') == 0:
+ raise LdtpExecutionError('File chooser does not show up')
+
+ # Call the new document 'Test':
+ settextvalue('Creating From Example File', 'txtName', 'Test');
+
+ # Select the correct backend
+ common.select_backend(backend, button_texts)
+
+ # Acknowledge the dialog:
+ click('Creating From Example File', 'btnSave')
+
+ # Wait until it asks to enter the credentials
+ if waittillguiexist('Connection Details') == 0:
+ raise LdtpExecutionError('Connection details dialog does not show up')
+
+ # Set connection details
+ settextvalue('Connection Details', 'txtHost', hostname)
+ settextvalue('Connection Details', 'txtUser', username)
+ settextvalue('Connection Details', 'txtPassword', password)
+
+ # Remember the database glom is going to create on the central server,
+ # so we can delete it again later.
+ database = getlabel('Connection Details', 'lblDatabase')
+
+ # Acknowledge the dialog
+ click('Connection Details', 'btnConnect')
+
+ # Wait until the database has been created:
+ common.wait_for_database_open()
+
+ # Everything finished, so check the created database for consistency.
+ common.check_small_business_integrity()
+
+ # Exit the application.
+ common.exit_glom()
+
+ # Wait until Glom has cleaned up everything, so that removing the
+ # test database is going to work.
+ wait(2)
+
+ # Remove the test Glom file
+ os.unlink('Test.glom')
+
+except LdtpExecutionError, msg:
+ log(msg, 'fail')
+
+ # Remove the test glom file also on error, so that the test
+ # does not fail because of the file already existing next time
+ try:
+ os.unlink('Test.glom')
+ # Ignore if this fails, for example if the file does not exist
+ except OSError, err:
+ pass
+
+ raise LdtpExecutionError (msg)
+ # TODO: Terminate the Glom application
+ # os.kill(whatpid?, signal.SIGTERM)
diff --git a/ldtp/database-creation/create-db.py b/ldtp/database-creation/create-db.py
index 0a7dcc6..6f6b9fc 100755
--- a/ldtp/database-creation/create-db.py
+++ b/ldtp/database-creation/create-db.py
@@ -7,25 +7,6 @@ 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()
try:
xml = LdtpDataFileParser(datafilename)
@@ -64,56 +45,24 @@ try:
# 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 ' + backend + ' not supported')
+ # Make sure we use the correct backend:
+ common.select_backend(backend, button_texts)
# 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()
+ # Wait until the database has been created:
+ common.wait_for_database_open()
# 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')
+ common.check_small_business_integrity()
- if waittillguinotexist('Glom-SmallBusinessExample') == 0:
- raise LdtpExecutionError('The Glom Window does not disappear after closing the application')
+ # Exit the application.
+ common.exit_glom()
# Wait until Glom has cleaned up everything, so that removing the
# test database is going to work.
diff --git a/ldtp/database-creation/postgres-central.xml b/ldtp/database-creation/postgres-central.xml
new file mode 100644
index 0000000..d2ecf42
--- /dev/null
+++ b/ldtp/database-creation/postgres-central.xml
@@ -0,0 +1,8 @@
+<data>
+ <backend>Postgres Central-Hosted</backend>
+ <button_text>CreatedatabaseonanexternalPostgreSQLdatabaseserver,tobespecifiedinthenextstep.</button_text>
+ <button_text>Createdatabaseonanexternaldatabaseserver,tobespecifiedinthenextstep.</button_text>
+ <hostname>localhost</hostname>
+ <username>ck</username>
+ <password>078175511</password>
+</data>
diff --git a/ldtp/test.xml b/ldtp/test.xml
index 44d12b0..40b4eec 100644
--- a/ldtp/test.xml
+++ b/ldtp/test.xml
@@ -6,6 +6,10 @@
<testcaseid>database-creation</testcaseid>
<comment>Test whether creation of a new database work for all available backends</comment>
<script>
+ <name>database-creation/create-central-db.py</name>
+ <data>database-creation/postgres-central.xml</data>
+ </script>
+ <script>
<name>database-creation/create-db.py</name>
<data>database-creation/postgres-self.xml</data>
</script>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]