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
Weblate
gajim
Commits
ca03f88f
Commit
ca03f88f
authored
15 years ago
by
steve-e
Browse files
Options
Downloads
Patches
Plain Diff
Write tests and fix the caps preload alternative on the EntityCapabilities.
parent
499f3dff
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
src/common/caps.py
+6
-5
6 additions, 5 deletions
src/common/caps.py
test/test_caps.py
+52
-10
52 additions, 10 deletions
test/test_caps.py
with
58 additions
and
15 deletions
src/common/caps.py
+
6
−
5
View file @
ca03f88f
...
...
@@ -58,9 +58,10 @@ class AbstractEntityCapabilities(object):
Query will only be sent if the data is not already cached.
'''
q
=
self
.
_lookup_in_cache
()
if
q
and
q
.
query_status
==
q
.
NOT_QUERIED
:
q
.
query_status
=
q
.
QUERIED
q
.
_discover
(
connection
,
jid
)
if
q
and
q
.
queried
==
0
:
self
.
_discover
(
connection
,
jid
)
q
.
queried
=
1
def
_discover
(
self
,
connection
,
jid
):
'''
To be implemented by subclassess
'''
...
...
@@ -92,8 +93,8 @@ class OldEntityCapabilities(AbstractEntityCapabilities):
def
__init__
(
self
,
caps_cache
,
caps_hash
,
node
):
AbstractEntityCapabilities
.
__init__
(
self
,
caps_cache
,
caps_hash
,
node
)
def
_lookup_in_cache
(
self
,
caps_cache
):
return
caps_cache
[(
'
old
'
,
self
.
_node
+
'
#
'
+
self
.
_hash
)]
def
_lookup_in_cache
(
self
):
return
self
.
_
caps_cache
[(
'
old
'
,
self
.
_node
+
'
#
'
+
self
.
_hash
)]
def
_discover
(
self
,
connection
,
jid
):
connection
.
discoverInfo
(
jid
)
...
...
This diff is collapsed.
Click to expand it.
test/test_caps.py
+
52
−
10
View file @
ca03f88f
...
...
@@ -8,7 +8,7 @@ lib.setup_env()
from
common
import
helpers
from
common.contacts
import
Contact
from
common.caps
import
CapsCache
from
common.caps
import
CapsCache
,
EntityCapabilities
,
OldEntityCapabilities
from
mock
import
Mock
...
...
@@ -28,21 +28,18 @@ class CommonCapsTest(unittest.TestCase):
self
.
identities
=
[
self
.
identity
]
self
.
features
=
[
self
.
muc
]
class
TestCapsCache
(
CommonCapsTest
):
def
setUp
(
self
):
CommonCapsTest
.
setUp
(
self
)
# Simulate a filled db
db_caps_cache
=
[
(
self
.
caps_method
,
self
.
caps_hash
,
self
.
identities
,
self
.
features
),
(
self
.
caps_method
,
self
.
caps_hash
,
self
.
identities
,
self
.
features
)]
(
'
old
'
,
self
.
node
+
'
#
'
+
self
.
caps_hash
,
self
.
identities
,
self
.
features
)]
self
.
logger
=
Mock
(
returnValues
=
{
"
iter_caps_data
"
:
db_caps_cache
})
self
.
cc
=
CapsCache
(
self
.
logger
)
class
TestCapsCache
(
CommonCapsTest
):
def
test_set_retrieve
(
self
):
'''
Test basic set / retrieve cycle
'''
...
...
@@ -117,6 +114,51 @@ class TestCapsCache(CommonCapsTest):
self
.
assertEqual
(
self
.
caps_hash
,
computed_hash
)
class
TestEntityCapabilities
(
CommonCapsTest
):
def
setUp
(
self
):
CommonCapsTest
.
setUp
(
self
)
self
.
entity
=
EntityCapabilities
(
self
.
cc
,
self
.
caps_hash
,
self
.
node
,
self
.
caps_method
)
def
test_no_query_client_of_jid
(
self
):
'''
Client must not be queried if the data is already cached
'''
connection
=
Mock
()
self
.
cc
.
initialize_from_db
()
self
.
entity
.
query_client_of_jid_if_unknown
(
connection
,
"
test@gajim.org
"
)
self
.
assertEqual
(
0
,
len
(
connection
.
mockGetAllCalls
()))
def
test_query_client_of_jid_if_unknown
(
self
):
'''
Client must be queried if the data is unkown
'''
connection
=
Mock
()
self
.
entity
.
query_client_of_jid_if_unknown
(
connection
,
"
test@gajim.org
"
)
connection
.
mockCheckCall
(
0
,
"
discoverInfo
"
,
'
test@gajim.org
'
,
'
http://gajim.org#RNzJvJnTWqczirzu+YF4V8am9ro=
'
)
class
TestOldEntityCapabilities
(
TestEntityCapabilities
):
def
setUp
(
self
):
TestEntityCapabilities
.
setUp
(
self
)
self
.
entity
=
OldEntityCapabilities
(
self
.
cc
,
self
.
caps_hash
,
self
.
node
)
def
test_no_query_client_of_jid
(
self
):
'''
Client must not be queried if the data is already cached
'''
connection
=
Mock
()
self
.
cc
.
initialize_from_db
()
self
.
entity
.
query_client_of_jid_if_unknown
(
connection
,
"
test@gajim.org
"
)
self
.
assertEqual
(
0
,
len
(
connection
.
mockGetAllCalls
()))
def
test_query_client_of_jid_if_unknown
(
self
):
'''
Client must be queried if the data is unkown
'''
connection
=
Mock
()
self
.
entity
.
query_client_of_jid_if_unknown
(
connection
,
"
test@gajim.org
"
)
connection
.
mockCheckCall
(
0
,
"
discoverInfo
"
,
"
test@gajim.org
"
)
if
__name__
==
'
__main__
'
:
...
...
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