Adding some unit tests
[gc-dialer] / tests / test_startup.py
1 from __future__ import with_statement
2
3 import os
4 import time
5
6 import test_utils
7
8 import sys
9 sys.path.append("../src")
10
11 import dc_glade
12
13
14 def test_startup_with_no_data_dir():
15         dc_glade.Dialcentral._data_path = os.path.join(os.path.dirname(__file__), "notexistent_data")
16         dc_glade.Dialcentral._user_settings = "%s/settings.ini" % dc_glade.Dialcentral._data_path
17
18         try:
19                 handle = dc_glade.Dialcentral()
20                 with test_utils.expected(AssertionError("Attempting login before app is fully loaded")):
21                         handle.refresh_session()
22
23                 for i in xrange(10):
24                         if handle._initDone:
25                                 print "Completed init on iteration %d" % i
26                                 break
27                         time.sleep(1)
28                 assert handle._initDone
29
30                 with test_utils.expected(RuntimeError("Login Failed")):
31                         handle.refresh_session()
32
33                 handle._save_settings()
34
35                 del handle
36         finally:
37                 os.remove(dc_glade.Dialcentral._user_settings)
38                 os.removedirs(dc_glade.Dialcentral._data_path)
39
40
41 def test_startup_with_empty_data_dir():
42         dc_glade.Dialcentral._data_path = os.path.join(os.path.dirname(__file__), "empty_data")
43         dc_glade.Dialcentral._user_settings = "%s/settings.ini" % dc_glade.Dialcentral._data_path
44
45         try:
46                 os.makedirs(dc_glade.Dialcentral._data_path)
47
48                 handle = dc_glade.Dialcentral()
49                 with test_utils.expected(AssertionError("Attempting login before app is fully loaded")):
50                         handle.refresh_session()
51
52                 for i in xrange(10):
53                         if handle._initDone:
54                                 print "Completed init on iteration %d" % i
55                                 break
56                         time.sleep(1)
57                 assert handle._initDone
58
59                 with test_utils.expected(RuntimeError("Login Failed")):
60                         handle.refresh_session()
61
62                 handle._save_settings()
63
64                 del handle
65         finally:
66                 os.remove(dc_glade.Dialcentral._user_settings)
67                 os.removedirs(dc_glade.Dialcentral._data_path)
68
69
70 def test_startup_with_basic_data_dir():
71         dc_glade.Dialcentral._data_path = os.path.join(os.path.dirname(__file__), "basic_data")
72         dc_glade.Dialcentral._user_settings = "%s/settings.ini" % dc_glade.Dialcentral._data_path
73
74         handle = dc_glade.Dialcentral()
75         with test_utils.expected(AssertionError("Attempting login before app is fully loaded")):
76                 handle.refresh_session()
77
78         for i in xrange(10):
79                 if handle._initDone:
80                         print "Completed init on iteration %d" % i
81                         break
82                 time.sleep(1)
83         assert handle._initDone
84
85         with test_utils.expected(RuntimeError("Login Failed")):
86                 handle.refresh_session()
87
88         handle._save_settings()
89
90         del handle