Adding some unit tests
[gc-dialer] / tests / test_startup.py
diff --git a/tests/test_startup.py b/tests/test_startup.py
new file mode 100644 (file)
index 0000000..88d8807
--- /dev/null
@@ -0,0 +1,90 @@
+from __future__ import with_statement
+
+import os
+import time
+
+import test_utils
+
+import sys
+sys.path.append("../src")
+
+import dc_glade
+
+
+def test_startup_with_no_data_dir():
+       dc_glade.Dialcentral._data_path = os.path.join(os.path.dirname(__file__), "notexistent_data")
+       dc_glade.Dialcentral._user_settings = "%s/settings.ini" % dc_glade.Dialcentral._data_path
+
+       try:
+               handle = dc_glade.Dialcentral()
+               with test_utils.expected(AssertionError("Attempting login before app is fully loaded")):
+                       handle.refresh_session()
+
+               for i in xrange(10):
+                       if handle._initDone:
+                               print "Completed init on iteration %d" % i
+                               break
+                       time.sleep(1)
+               assert handle._initDone
+
+               with test_utils.expected(RuntimeError("Login Failed")):
+                       handle.refresh_session()
+
+               handle._save_settings()
+
+               del handle
+       finally:
+               os.remove(dc_glade.Dialcentral._user_settings)
+               os.removedirs(dc_glade.Dialcentral._data_path)
+
+
+def test_startup_with_empty_data_dir():
+       dc_glade.Dialcentral._data_path = os.path.join(os.path.dirname(__file__), "empty_data")
+       dc_glade.Dialcentral._user_settings = "%s/settings.ini" % dc_glade.Dialcentral._data_path
+
+       try:
+               os.makedirs(dc_glade.Dialcentral._data_path)
+
+               handle = dc_glade.Dialcentral()
+               with test_utils.expected(AssertionError("Attempting login before app is fully loaded")):
+                       handle.refresh_session()
+
+               for i in xrange(10):
+                       if handle._initDone:
+                               print "Completed init on iteration %d" % i
+                               break
+                       time.sleep(1)
+               assert handle._initDone
+
+               with test_utils.expected(RuntimeError("Login Failed")):
+                       handle.refresh_session()
+
+               handle._save_settings()
+
+               del handle
+       finally:
+               os.remove(dc_glade.Dialcentral._user_settings)
+               os.removedirs(dc_glade.Dialcentral._data_path)
+
+
+def test_startup_with_basic_data_dir():
+       dc_glade.Dialcentral._data_path = os.path.join(os.path.dirname(__file__), "basic_data")
+       dc_glade.Dialcentral._user_settings = "%s/settings.ini" % dc_glade.Dialcentral._data_path
+
+       handle = dc_glade.Dialcentral()
+       with test_utils.expected(AssertionError("Attempting login before app is fully loaded")):
+               handle.refresh_session()
+
+       for i in xrange(10):
+               if handle._initDone:
+                       print "Completed init on iteration %d" % i
+                       break
+               time.sleep(1)
+       assert handle._initDone
+
+       with test_utils.expected(RuntimeError("Login Failed")):
+               handle.refresh_session()
+
+       handle._save_settings()
+
+       del handle