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,
36 def test_not_logged_in():
37 correctUsername, correctPassword = "", ""
38 MockBrowserModule = generate_mock(False, correctUsername, correctPassword)
39 gvoice.backend.browser_emu, RealBrowser = MockBrowserModule, gvoice.backend.browser_emu
41 backend = gvoice.backend.GVoiceBackend()
42 assert not backend.is_authed()
43 assert not backend.login("bad_name", "bad_password")
45 with test_utils.expected(RuntimeError):
46 backend.dial("5551234567")
47 with test_utils.expected(RuntimeError):
48 backend.send_sms("5551234567", "Hello World")
49 assert backend.get_account_number() == "", "%s" % backend.get_account_number()
50 gvoice.backend.set_sane_callback(backend)
51 assert backend.get_callback_number() == ""
52 with test_utils.expected(Exception):
53 recent = list(backend.get_recent())
54 with test_utils.expected(Exception):
55 messages = list(backend.get_messages())
57 gvoice.backend.browser_emu = RealBrowser