[glom] test_selfhosting_new_empty_then_users: Slight improvement.



commit 7d6715efa0f9ccefe137d98b95a7997297faaec7
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Feb 3 08:59:01 2012 +0100

    test_selfhosting_new_empty_then_users: Slight improvement.
    
    	* tests/test_selfhosting_new_from_example_operator.cc: Check
    	that the group exists before adding a user to it.

 ChangeLog                                          |    7 +++++++
 .../test_selfhosting_new_from_example_operator.cc  |   19 ++++++++++++++++++-
 2 files changed, 25 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 208ba57..4a6d2db 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2012-02-03  Murray Cumming  <murrayc murrayc com>
 
+	test_selfhosting_new_empty_then_users: Slight improvement.
+
+	* tests/test_selfhosting_new_from_example_operator.cc: Check
+	that the group exists before adding a user to it.
+
+2012-02-03  Murray Cumming  <murrayc murrayc com>
+
 	Add some runtime warnings.
 
 	* glom/libglom/db_utils.cc: get_table_names_from_database():
diff --git a/tests/test_selfhosting_new_from_example_operator.cc b/tests/test_selfhosting_new_from_example_operator.cc
index f9637e1..8178756 100644
--- a/tests/test_selfhosting_new_from_example_operator.cc
+++ b/tests/test_selfhosting_new_from_example_operator.cc
@@ -28,6 +28,14 @@
 #include <iostream>
 #include <cstdlib> //For EXIT_SUCCESS and EXIT_FAILURE
 
+template<typename T_Container, typename T_Value>
+bool contains(const T_Container& container, const T_Value& name)
+{
+  typename T_Container::const_iterator iter =
+    std::find(container.begin(), container.end(), name);
+  return iter != container.end();
+}
+
 static bool test(Glom::Document::HostingMode hosting_mode)
 {
   Glib::ustring temp_file_uri;
@@ -53,7 +61,16 @@ static bool test(Glom::Document::HostingMode hosting_mode)
     }
 
     //Add an operator user:
-    if(!Glom::DbUtils::add_user(&document, operator_user, operator_password, "personnel_department"))
+    const Glib::ustring operator_group_name = "personnel_department";
+    const Glom::DbUtils::type_vec_strings group_list = 
+      Glom::Privs::get_database_groups();
+    if(!contains(group_list, operator_group_name))
+    {
+      std::cerr << "The expected group was not found." << std::endl;
+      return false;
+    }
+
+    if(!Glom::DbUtils::add_user(&document, operator_user, operator_password, operator_group_name))
     {
       std::cerr << "DbUtils::add_user() failed." << std::endl;
       test_selfhosting_cleanup();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]