Implemented conversations with full testing, oh and got some addressbook stuff done
[theonering] / tests / test_gv_backend.py
1 from __future__ import with_statement
2
3 import cookielib
4 import logging
5
6 import test_utils
7
8 import sys
9 sys.path.append("../src")
10
11 import gvoice
12
13
14 logging.basicConfig(level=logging.DEBUG)
15
16
17 def generate_mock(cookiesSucceed, username, password):
18
19         class MockModule(object):
20
21                 class MozillaEmulator(object):
22
23                         def __init__(self, trycount = 1):
24                                 self.cookies = cookielib.LWPCookieJar()
25                                 self.trycount = trycount
26
27                         def download(self, url,
28                                         postdata = None, extraheaders = None, forbid_redirect = False,
29                                         trycount = None, only_head = False,
30                                 ):
31                                 return ""
32
33         return MockModule
34
35
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
40         try:
41                 backend = gvoice.backend.GVoiceBackend()
42                 assert not backend.is_authed()
43                 assert not backend.login("bad_name", "bad_password")
44                 backend.logout()
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())
56         finally:
57                 gvoice.backend.browser_emu = RealBrowser