~ubuntu-branches/ubuntu/vivid/mago/vivid

« back to all changes in this revision

Viewing changes to pidgin/pidgin_notify.py

  • Committer: Bazaar Package Importer
  • Author(s): Ara Pulido
  • Date: 2009-08-04 09:21:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090804092140-mnc0rm2tr7smo107
Tags: upstream-0.1
ImportĀ upstreamĀ versionĀ 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from mago.test_suite.pidgin import PidginTestSuite
 
2
from mago.application.pidgin import Pidgin
 
3
from ConfigParser import ConfigParser
 
4
import ldtp, ooldtp, ldtputils
 
5
from time import sleep, time
 
6
from shutil import copytree, move
 
7
from os.path import expanduser
 
8
 
 
9
class PidginNotifyApp(Pidgin):
 
10
    MNU_INDICATOR_SERVER = "mnuPidginInternetMessenger"
 
11
    EMB_INDICATOR_APPLET = "embindicator-applet"
 
12
 
 
13
    def open(self, clean_profile=True, profile_template='',credentials=''):
 
14
        Pidgin.open(self, clean_profile, profile_template, credentials)
 
15
        self.wait_for_account_connect(self.get_account_name('XMPP'), 'XMPP')
 
16
 
 
17
        # The notify plugin only starts working after 15 seconds.
 
18
        # We start waiting from now to be safe.
 
19
        sleep(15)
 
20
 
 
21
    def close(self):
 
22
        if self.buddy:
 
23
            self.buddy.disconnect()
 
24
 
 
25
        if not ldtp.hasstate(self.WINDOW, self.WINDOW, ldtp.state.SHOWING):
 
26
            self._click_in_indicator(self.MNU_INDICATOR_SERVER)
 
27
            sleep(1)
 
28
 
 
29
        Pidgin.close(self)
 
30
    
 
31
 
 
32
class PidginNotifyTest(PidginTestSuite):
 
33
    APPLICATION_FACTORY = PidginNotifyApp
 
34
    def cleanup(self):
 
35
        alias = self.application.get_account_alias('OtherXMPP')
 
36
        if ldtp.guiexist('frm%s' % alias.replace(' ', '')):
 
37
            self.application.close_conversation('frm%s' % alias.replace(' ', ''))
 
38
 
 
39
    def _click_in_indicator(self, name):
 
40
        objs = ldtp.getobjectlist(self.application.TOP_PANEL)
 
41
 
 
42
        for obj in objs:
 
43
            if obj.startswith(name):
 
44
                if self._is_in_indicator(obj):
 
45
                    ldtp.selectmenuitem(self.application.TOP_PANEL, obj)
 
46
                    return
 
47
 
 
48
        raise Exception('%s does not appear in indicator applet' % name)
 
49
 
 
50
    def _is_in_indicator(self, obj):
 
51
        parent = ldtp.getobjectproperty(self.application.TOP_PANEL, obj, 'parent')
 
52
        while parent != self.application.TOP_PANEL:
 
53
            if parent == self.application.EMB_INDICATOR_APPLET:
 
54
                return True
 
55
            parent = ldtp.getobjectproperty(self.application.TOP_PANEL, 
 
56
                                            parent, 'parent')
 
57
        return False
 
58
        
 
59
    def _is_bubble(self, frm_name):
 
60
        return ldtp.getobjectproperty(
 
61
            frm_name, frm_name, 'parent') == 'notify-osd'        
 
62
            
 
63
    def _bubble_body(self, frm_name):
 
64
        return ldtp.getobjectproperty(frm_name, frm_name, 'description')
 
65
        
 
66
    def _bubble_name_from_alias(self, name):
 
67
        return 'dlg%s' % name.replace(' ', '')        
 
68
 
 
69
    def testIndicatorServer(self):
 
70
        flipflop = []
 
71
        flipflop.append(
 
72
            ldtp.hasstate(self.application.WINDOW, self.application.WINDOW, ldtp.state.SHOWING))
 
73
 
 
74
        self._click_in_indicator(self.application.MNU_INDICATOR_SERVER)
 
75
        sleep(2)
 
76
 
 
77
        flipflop.append(
 
78
            ldtp.hasstate(self.application.WINDOW, self.application.WINDOW, ldtp.state.SHOWING))
 
79
 
 
80
        self._click_in_indicator(self.application.MNU_INDICATOR_SERVER)
 
81
        sleep(2)
 
82
            
 
83
        flipflop.append(
 
84
            ldtp.hasstate(self.application.WINDOW, self.application.WINDOW, ldtp.state.SHOWING))
 
85
 
 
86
        if flipflop not in ([1, 0, 1], [0, 1, 0]):
 
87
            raise AssertionError, \
 
88
                'indicator server menu item did not show/hide the buddy list'
 
89
 
 
90
    def testBuddyLogin(self):
 
91
        self.application.buddy_login()
 
92
        alias = self.application.get_account_alias('OtherXMPP')
 
93
 
 
94
        result = 1
 
95
        count = 0
 
96
        frm_name = ''
 
97
 
 
98
        while result:
 
99
            frm_name = self._bubble_name_from_alias(alias)
 
100
            if count != 0:
 
101
                frm_name += str(count)
 
102
            result = ldtp.waittillguiexist(frm_name)
 
103
            if result:
 
104
                frm = ooldtp.context(frm_name)
 
105
                if self._is_bubble(frm_name) and \
 
106
                        self._bubble_body(frm_name) == 'is online':
 
107
                    break
 
108
            count += 1
 
109
 
 
110
        if not result:
 
111
            raise AssertionError, 'did not recieve a notification bubble.'
 
112
        
 
113
        ldtp.remap(self.application.TOP_PANEL)
 
114
        try:
 
115
            self._click_in_indicator('mnu%s' % alias.replace(' ', ''))
 
116
        except Exception, e:
 
117
            raise AssertionError(e[-1])
 
118
        
 
119
        print 'success'
 
120
        result = ldtp.waittillguiexist('frm%s' % alias.replace(' ', ''))
 
121
        
 
122
        if not result:
 
123
            AssertionError, \
 
124
                'clicking on buddy indicator did not bring up chat dialog'
 
125
 
 
126
    def testRecieveMessageAppend(self, msg1='', msg2='', msg3='', timeout=5):
 
127
        if not self.application.buddy:
 
128
            self.application.buddy_login()
 
129
            sleep(1)
 
130
 
 
131
        jid = self.application.get_account_name('XMPP')
 
132
 
 
133
        alias = self.application.get_account_alias('OtherXMPP')
 
134
 
 
135
        #https://bugs.launchpad.net/ubuntu/+source/pidgin-libnotify/+bug/362248
 
136
        ldtp.waittillguinotexist(self._bubble_name_from_alias(alias))
 
137
 
 
138
        self.application.buddy.send_message(jid, '', msg1)
 
139
        sleep(2)
 
140
        self.application.buddy.send_message(jid, '', msg2)
 
141
 
 
142
        result = 1
 
143
        count = 0
 
144
        frm_name = ''
 
145
 
 
146
        while result:
 
147
            frm_name = self._bubble_name_from_alias(alias)
 
148
            if count != 0:
 
149
                frm_name += str(count)
 
150
            result = ldtp.waittillguiexist(frm_name)
 
151
            if result:
 
152
                if self._is_bubble(frm_name) and \
 
153
                        self._bubble_body(frm_name) == msg2:
 
154
                    break
 
155
            count += 1
 
156
 
 
157
        if not result:
 
158
            raise AssertionError, \
 
159
                'did not recieve a message notification bubble.'
 
160
 
 
161
        self.application.buddy.send_message(jid, '', msg3)
 
162
 
 
163
        for i in xrange(timeout):
 
164
            ldtp.remap(frm_name)
 
165
            try:
 
166
                if self._bubble_body(frm_name) == '%s\n%s' % (msg2, msg3):
 
167
                    return
 
168
            except ldtp.LdtpExecutionError:
 
169
                screeny = ldtputils.imagecapture()
 
170
                raise AssertionError(
 
171
                        'notification for second message does not exist',
 
172
                        screeny)
 
173
            sleep(1)
 
174
 
 
175
        raise AssertionError, 'second message was not appended'
 
176
 
 
177
    def testRecieveMessageSimple(self, msg1='', msg2='', timeout=5):
 
178
        if not self.application.buddy:
 
179
            self.application.buddy_login()
 
180
            sleep(1)
 
181
 
 
182
        jid = self.application.get_account_name('XMPP')
 
183
 
 
184
        alias = self.application.get_account_alias('OtherXMPP')
 
185
 
 
186
        #https://bugs.launchpad.net/ubuntu/+source/pidgin-libnotify/+bug/362248
 
187
        ldtp.waittillguinotexist(self._bubble_name_from_alias(alias))
 
188
 
 
189
        self.application.buddy.send_message(jid, '', msg1)
 
190
        sleep(2)
 
191
        self.application.buddy.send_message(jid, '', msg2)
 
192
 
 
193
        result = 1
 
194
        count = 0
 
195
        frm_name = ''
 
196
 
 
197
        while result:
 
198
            frm_name = self._bubble_name_from_alias(alias)
 
199
            if count != 0:
 
200
                frm_name += str(count)
 
201
            result = ldtp.waittillguiexist(frm_name)
 
202
            if result:
 
203
                if self._is_bubble(frm_name) and \
 
204
                        self._bubble_body(frm_name) == msg2:
 
205
                    break
 
206
            count += 1
 
207
 
 
208
        if not result:
 
209
            raise AssertionError, \
 
210
                'did not recieve a message notification bubble.'