Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
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
Timo Ley
synapse
Commits
d1f3490e
Commit
d1f3490e
authored
7 years ago
by
Richard van der Hoff
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for user directory search
parent
46022025
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/storage/test_user_directory.py
+88
-0
88 additions, 0 deletions
tests/storage/test_user_directory.py
tests/utils.py
+1
-0
1 addition, 0 deletions
tests/utils.py
with
89 additions
and
0 deletions
tests/storage/test_user_directory.py
0 → 100644
+
88
−
0
View file @
d1f3490e
# -*- coding: utf-8 -*-
# Copyright 2018 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
twisted.internet
import
defer
from
synapse.storage
import
UserDirectoryStore
from
synapse.storage.roommember
import
ProfileInfo
from
tests
import
unittest
from
tests.utils
import
setup_test_homeserver
ALICE
=
"
@alice:a
"
BOB
=
"
@bob:b
"
BOBBY
=
"
@bobby:a
"
class
UserDirectoryStoreTestCase
(
unittest
.
TestCase
):
@defer.inlineCallbacks
def
setUp
(
self
):
self
.
hs
=
yield
setup_test_homeserver
()
self
.
store
=
UserDirectoryStore
(
None
,
self
.
hs
)
# alice and bob are both in !room_id. bobby is not but shares
# a homeserver with alice.
yield
self
.
store
.
add_profiles_to_user_dir
(
"
!room:id
"
,
{
ALICE
:
ProfileInfo
(
None
,
"
alice
"
),
BOB
:
ProfileInfo
(
None
,
"
bob
"
),
BOBBY
:
ProfileInfo
(
None
,
"
bobby
"
)
},
)
yield
self
.
store
.
add_users_to_public_room
(
"
!room:id
"
,
[
ALICE
,
BOB
],
)
yield
self
.
store
.
add_users_who_share_room
(
"
!room:id
"
,
False
,
(
(
ALICE
,
BOB
),
(
BOB
,
ALICE
),
),
)
@defer.inlineCallbacks
def
test_search_user_dir
(
self
):
# normally when alice searches the directory she should just find
# bob because bobby doesn't share a room with her.
r
=
yield
self
.
store
.
search_user_dir
(
ALICE
,
"
bob
"
,
10
)
self
.
assertFalse
(
r
[
"
limited
"
])
self
.
assertEqual
(
1
,
len
(
r
[
"
results
"
]))
self
.
assertDictEqual
(
r
[
"
results
"
][
0
],
{
"
user_id
"
:
BOB
,
"
display_name
"
:
"
bob
"
,
"
avatar_url
"
:
None
,
})
@defer.inlineCallbacks
def
test_search_user_dir_all_users
(
self
):
self
.
hs
.
config
.
user_directory_search_all_users
=
True
try
:
r
=
yield
self
.
store
.
search_user_dir
(
ALICE
,
"
bob
"
,
10
)
self
.
assertFalse
(
r
[
"
limited
"
])
self
.
assertEqual
(
2
,
len
(
r
[
"
results
"
]))
self
.
assertDictEqual
(
r
[
"
results
"
][
0
],
{
"
user_id
"
:
BOB
,
"
display_name
"
:
"
bob
"
,
"
avatar_url
"
:
None
,
})
self
.
assertDictEqual
(
r
[
"
results
"
][
1
],
{
"
user_id
"
:
BOBBY
,
"
display_name
"
:
"
bobby
"
,
"
avatar_url
"
:
None
,
})
finally
:
self
.
hs
.
config
.
user_directory_search_all_users
=
False
This diff is collapsed.
Click to expand it.
tests/utils.py
+
1
−
0
View file @
d1f3490e
...
...
@@ -59,6 +59,7 @@ def setup_test_homeserver(name="test", datastore=None, config=None, **kargs):
config
.
email_enable_notifs
=
False
config
.
block_non_admin_invites
=
False
config
.
federation_domain_whitelist
=
None
config
.
user_directory_search_all_users
=
False
# disable user directory updates, because they get done in the
# background, which upsets the test runner.
...
...
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