1 from __future__ import with_statement
9 sys.path.append("../src")
14 logging.basicConfig(level=logging.DEBUG)
17 def generate_mock(cookiesSucceed, username, password):
19 class MockModule(object):
21 class MozillaEmulator(object):
23 def __init__(self, trycount = 1):
24 self.cookies = cookielib.LWPCookieJar()
25 self.trycount = trycount
27 def download(self, url,
28 postdata = None, extraheaders = None, forbid_redirect = False,
29 trycount = None, only_head = False,
33 def load_cookies(self, *args):
36 def save_cookies(self, *args):
39 def clear_cookies(self, *args):
45 def test_not_logged_in():
46 correctUsername, correctPassword = "", ""
47 MockBrowserModule = generate_mock(False, correctUsername, correctPassword)
48 gvoice.backend.browser_emu, RealBrowser = MockBrowserModule, gvoice.backend.browser_emu
50 backend = gvoice.backend.GVoiceBackend()
51 assert not backend.is_authed()
52 assert not backend.login("bad_name", "bad_password")
54 with test_utils.expected(RuntimeError):
55 backend.call("5551234567")
56 with test_utils.expected(RuntimeError):
57 backend.send_sms("5551234567", "Hello World")
58 assert backend.get_account_number() == "", "%s" % backend.get_account_number()
59 gvoice.backend.set_sane_callback(backend)
60 assert backend.get_callback_number() == ""
61 with test_utils.expected(Exception):
62 recent = list(backend.get_recent())
63 with test_utils.expected(Exception):
64 messages = list(backend.get_messages())
66 gvoice.backend.browser_emu = RealBrowser