Removing a lot of code that shouldn't be needed for telepathy
[theonering] / tests / test_gv_backend.py
1 from __future__ import with_statement
2
3 import os
4 import warnings
5 import cookielib
6
7 import test_utils
8
9 import sys
10 sys.path.append("../src")
11
12 import gv_backend
13
14
15 def generate_mock(cookiesSucceed, username, password):
16
17         class MockModule(object):
18
19                 class MozillaEmulator(object):
20
21                         def __init__(self, trycount = 1):
22                                 self.cookies = cookielib.LWPCookieJar()
23                                 self.trycount = trycount
24
25                         def download(self, url,
26                                         postdata = None, extraheaders = None, forbid_redirect = False,
27                                         trycount = None, only_head = False,
28                                 ):
29                                 return ""
30
31         return MockModule
32
33
34 def test_not_logged_in():
35         correctUsername, correctPassword = "", ""
36         MockBrowserModule = generate_mock(False, correctUsername, correctPassword)
37         gv_backend.browser_emu, RealBrowser = MockBrowserModule, gv_backend.browser_emu
38         try:
39                 backend = gv_backend.GVDialer()
40                 assert not backend.is_authed()
41                 assert not backend.login("bad_name", "bad_password")
42                 backend.logout()
43                 with test_utils.expected(RuntimeError):
44                         backend.dial("5551234567")
45                 with test_utils.expected(RuntimeError):
46                         backend.send_sms("5551234567", "Hello World")
47                 assert backend.get_account_number() == "", "%s" % backend.get_account_number()
48                 backend.set_sane_callback()
49                 assert backend.get_callback_number() == ""
50                 with test_utils.expected(Exception):
51                         recent = list(backend.get_recent())
52                 with test_utils.expected(Exception):
53                         messages = list(backend.get_messages())
54         finally:
55                 gv_backend.browser_emu = RealBrowser