Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Erik Huelsmann
gajim
Commits
ed72914e
Commit
ed72914e
authored
11 years ago
by
Yann Leboulanger
Browse files
Options
Downloads
Patches
Plain Diff
start fixing last test. still a problem with sessions
parent
329a59c6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/integration/test_gui_event_integration.py
+35
-15
35 additions, 15 deletions
test/integration/test_gui_event_integration.py
test/lib/gajim_mocks.py
+7
-1
7 additions, 1 deletion
test/lib/gajim_mocks.py
with
42 additions
and
16 deletions
test/integration/test_gui_event_integration.py
+
35
−
15
View file @
ed72914e
...
...
@@ -10,6 +10,7 @@ import nbxmpp
from
common
import
gajim
from
common
import
contacts
as
contacts_module
from
common
import
caps_cache
from
gajim
import
Interface
from
gajim_mocks
import
*
...
...
@@ -21,17 +22,20 @@ import time
from
data
import
*
import
roster_window
import
plugins
import
notify
class
TestStatusChange
(
unittest
.
TestCase
):
'''
tests gajim.py
'
s incredibly complex
handle_event_notify
'''
'''
tests gajim.py
'
s incredibly complex
presence handling
'''
def
setUp
(
self
):
gajim
.
connections
=
{}
gajim
.
contacts
=
contacts_module
.
LegacyContactsAPI
()
gajim
.
interface
.
roster
=
roster_window
.
RosterWindow
()
gajim
.
plugin_manager
=
plugins
.
PluginManager
()
gajim
.
logger
=
MockLogger
()
caps_cache
.
initialize
(
gajim
.
logger
)
for
acc
in
contacts
:
gajim
.
connections
[
acc
]
=
MockConnection
(
acc
)
...
...
@@ -45,19 +49,20 @@ class TestStatusChange(unittest.TestCase):
def
tearDown
(
self
):
notify
.
notifications
=
[]
for
acc
in
contacts
:
gajim
.
connections
[
acc
].
cleanup
()
def
contact_comes_online
(
self
,
account
,
jid
,
resource
,
prio
):
def
contact_comes_online
(
self
,
account
,
jid
,
resource
,
prio
,
should_popup
=
True
):
'''
a remote contact comes online
'''
xml
=
"""
<presence from=
'
%s/%s
'
id=
'
123
'
>
xml
=
"""
<presence from=
'
%s/%s
'
id=
'
123
'
>
<priority>%s</priority>
<c node=
'
http://gajim.org
'
ver=
'
pRCD6cgQ4SDqNMCjdhRV6TECx5o=
'
hash=
'
sha-1
'
xmlns=
'
http://jabber.org/protocol/caps
'
/>
<status>I
'
m back!</status>
</presence>
"""
%
(
jid
,
resource
)
"""
%
(
jid
,
resource
,
prio
)
msg
=
nbxmpp
.
protocol
.
Presence
(
node
=
nbxmpp
.
simplexml
.
XML2Node
(
xml
))
gajim
.
connections
[
account
].
_presenceCB
(
None
,
msg
)
# gajim.interface.handle_event_notify(account, (jid, 'online', "I'm back!",
# resource, prio, None, time.time(), None))
contact
=
None
for
c
in
gajim
.
contacts
.
get_contacts
(
account
,
jid
):
...
...
@@ -70,13 +75,24 @@ class TestStatusChange(unittest.TestCase):
self
.
assertEqual
(
prio
,
contact
.
priority
)
# the most recent notification is that the contact connected
self
.
assertEqual
(
'
contact_connected
'
,
notify
.
notifications
[
-
1
][
0
])
if
should_popup
:
self
.
assertEqual
(
'
Contact Signed In
'
,
notify
.
notifications
[
-
1
].
popup_event_type
)
else
:
self
.
assertEqual
(
''
,
notify
.
notifications
[
-
1
].
popup_event_type
)
def
contact_goes_offline
(
self
,
account
,
jid
,
resource
,
prio
,
still_exists
=
True
):
'''
a remote contact goes offline.
'''
gajim
.
interface
.
handle_event_notify
(
account
,
(
jid
,
'
offline
'
,
'
Goodbye!
'
,
resource
,
prio
,
None
,
time
.
time
(),
None
))
xml
=
"""
<presence type=
'
unavailable
'
from=
'
%s/%s
'
id=
'
123
'
>
<priority>%s</priority>
<c node=
'
http://gajim.org
'
ver=
'
pRCD6cgQ4SDqNMCjdhRV6TECx5o=
'
hash=
'
sha-1
'
xmlns=
'
http://jabber.org/protocol/caps
'
/>
<status>Goodbye!</status>
</presence>
"""
%
(
jid
,
resource
,
prio
)
msg
=
nbxmpp
.
protocol
.
Presence
(
node
=
nbxmpp
.
simplexml
.
XML2Node
(
xml
))
gajim
.
connections
[
account
].
_presenceCB
(
None
,
msg
)
contact
=
None
for
c
in
gajim
.
contacts
.
get_contacts
(
account
,
jid
):
...
...
@@ -92,7 +108,8 @@ class TestStatusChange(unittest.TestCase):
self
.
assertEqual
(
'
Goodbye!
'
,
contact
.
status
)
self
.
assertEqual
(
prio
,
contact
.
priority
)
self
.
assertEqual
(
'
contact_disconnected
'
,
notify
.
notifications
[
-
1
][
0
])
self
.
assertEqual
(
'
Contact Signed Out
'
,
notify
.
notifications
[
-
1
].
popup_event_type
)
def
user_starts_chatting
(
self
,
jid
,
account
,
resource
=
None
):
'''
the user opens a chat window and starts talking
'''
...
...
@@ -150,7 +167,8 @@ class TestStatusChange(unittest.TestCase):
ctrl
=
self
.
user_starts_chatting
(
jid
,
account1
)
self
.
contact_comes_online
(
account1
,
jid
,
'
highprio
'
,
50
)
self
.
contact_comes_online
(
account1
,
jid
,
'
highprio
'
,
50
,
should_popup
=
False
)
# old session was dropped
self
.
assertEqual
(
None
,
ctrl
.
session
)
...
...
@@ -159,12 +177,13 @@ class TestStatusChange(unittest.TestCase):
jid
=
'
default1@gajim.org
'
self
.
contact_comes_online
(
account1
,
jid
,
'
lowprio
'
,
1
)
self
.
contact_comes_online
(
account1
,
jid
,
'
highprio
'
,
50
)
self
.
contact_comes_online
(
account1
,
jid
,
'
highprio
'
,
50
,
should_popup
=
False
)
ctrl
=
self
.
user_starts_chatting
(
jid
,
account1
)
self
.
contact_goes_offline
(
account1
,
jid
,
'
highprio
'
,
50
,
still_exists
=
False
)
still_exists
=
False
)
# old session was dropped
self
.
assertEqual
(
None
,
ctrl
.
session
)
...
...
@@ -176,7 +195,8 @@ class TestStatusChange(unittest.TestCase):
ctrl
=
self
.
user_starts_esession
(
jid
,
'
lowprio
'
,
account1
)
self
.
contact_comes_online
(
account1
,
jid
,
'
highprio
'
,
50
)
self
.
contact_comes_online
(
account1
,
jid
,
'
highprio
'
,
50
,
should_popup
=
False
)
# session was associated with the low priority full jid, so it should
# have been removed from the control
...
...
This diff is collapsed.
Click to expand it.
test/lib/gajim_mocks.py
+
7
−
1
View file @
ed72914e
...
...
@@ -11,9 +11,13 @@ from common.connection_handlers import ConnectionHandlers
class
MockConnection
(
Mock
,
ConnectionHandlers
):
def
__init__
(
self
,
account
,
*
args
):
Mock
.
__init__
(
self
,
*
args
)
ConnectionHandlers
.
__init__
(
self
)
self
.
connection
=
Mock
()
self
.
name
=
account
ConnectionHandlers
.
__init__
(
self
)
self
.
connected
=
2
self
.
pep
=
{}
self
.
blocked_contacts
=
{}
...
...
@@ -122,6 +126,7 @@ class MockInterface(Mock):
class
MockLogger
(
Mock
):
def
__init__
(
self
):
Mock
.
__init__
(
self
,
{
'
write
'
:
None
,
'
get_transports_type
'
:
{}})
self
.
cur
=
Mock
()
class
MockContact
(
Mock
):
...
...
@@ -139,6 +144,7 @@ class MockSession(Mock):
self
.
jid
=
jid
self
.
type_
=
type_
self
.
thread_id
=
thread_id
self
.
resource
=
''
if
not
self
.
thread_id
:
self
.
thread_id
=
'
%0x
'
%
random
.
randint
(
0
,
10000
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment