Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Python Briar Wrapper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
briar
Python Briar Wrapper
Commits
bffeb7ea
"README.md" did not exist on "1d4213e9c61234684dde032c7d9bfd63ca1397b8"
Commit
bffeb7ea
authored
4 years ago
by
Nico
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for Contacts.handle_connections_callback
parent
5c0683b5
No related branches found
No related tags found
1 merge request
!15
Add missing tests
Pipeline
#4983
passed
4 years ago
Stage: test
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
briar_wrapper/models/contacts.py
+2
-2
2 additions, 2 deletions
briar_wrapper/models/contacts.py
tests/briar_wrapper/models/test_contacts.py
+57
-3
57 additions, 3 deletions
tests/briar_wrapper/models/test_contacts.py
with
59 additions
and
5 deletions
briar_wrapper/models/contacts.py
+
2
−
2
View file @
bffeb7ea
...
...
@@ -89,14 +89,14 @@ class Contacts(Model):
"""
self
.
_connections_callback
=
callback
signal_ids
=
list
()
event_callback
=
self
.
_
handle_connections_callback
event_callback
=
self
.
handle_connections_callback
for
event
in
self
.
_CONNECTION_EVENTS
:
signal_id
=
self
.
_api
.
socket_listener
.
connect
(
event
,
event_callback
)
signal_ids
.
append
(
signal_id
)
return
signal_ids
def
_
handle_connections_callback
(
self
,
message
):
def
handle_connections_callback
(
self
,
message
):
contact_id
=
message
[
"
data
"
][
"
contactId
"
]
if
message
[
"
name
"
]
==
"
ContactConnectedEvent
"
:
self
.
_connections_callback
(
contact_id
,
True
)
...
...
This diff is collapsed.
Click to expand it.
tests/briar_wrapper/models/test_contacts.py
+
57
−
3
View file @
bffeb7ea
...
...
@@ -4,6 +4,7 @@
import
json
import
pytest
import
requests_mock
from
briar_wrapper.models.contacts
import
Contacts
...
...
@@ -12,6 +13,7 @@ from briar_wrapper.models.socket_listener import SocketListener
BASE_HTTP_URL
=
"
http://localhost:7000/v1/contacts/
"
TEST_ALIAS
=
"
Alice
"
TEST_CONTACT_ID
=
42
TEST_CONTACT_FIRST
=
{
"
lastChatActivity
"
:
1
...
...
@@ -109,7 +111,7 @@ def test_get_link(api, request_headers, requests_mock):
assert
contacts
.
get_link
()
==
TEST_LINK
def
test_watch_signal_added
(
api
,
mocker
):
def
test_watch_signal_added
(
api
):
contacts
=
Contacts
(
api
)
contacts
.
_api
.
socket_listener
=
SocketListener
(
api
)
contacts
.
_api
.
socket_listener
.
_highest_signal_id
=
136
...
...
@@ -121,12 +123,64 @@ def test_watch_signal_added(api, mocker):
expected_signals
=
{
137
:
{
"
event
"
:
"
ContactConnectedEvent
"
,
"
callback
"
:
contacts
.
_
handle_connections_callback
"
callback
"
:
contacts
.
handle_connections_callback
},
138
:
{
"
event
"
:
"
ContactDisconnectedEvent
"
,
"
callback
"
:
contacts
.
_
handle_connections_callback
"
callback
"
:
contacts
.
handle_connections_callback
}
}
assert
contacts
.
_api
.
socket_listener
.
_signals
==
expected_signals
def
test_handle_connections_callback_contact_connected
(
api
,
mocker
):
contacts
=
Contacts
(
api
)
contacts
.
_connections_callback
=
mocker
.
MagicMock
()
message
=
{
"
data
"
:
{
"
contactId
"
:
TEST_CONTACT_ID
},
"
name
"
:
"
ContactConnectedEvent
"
}
contacts
.
handle_connections_callback
(
message
)
contacts
.
_connections_callback
.
assert_called_once_with
(
TEST_CONTACT_ID
,
True
)
def
test_handle_connections_callback_contact_disconnected
(
api
,
mocker
):
contacts
=
Contacts
(
api
)
contacts
.
_connections_callback
=
mocker
.
MagicMock
()
message
=
{
"
data
"
:
{
"
contactId
"
:
TEST_CONTACT_ID
},
"
name
"
:
"
ContactDisconnectedEvent
"
}
contacts
.
handle_connections_callback
(
message
)
contacts
.
_connections_callback
.
assert_called_once_with
(
TEST_CONTACT_ID
,
False
)
def
test_handle_connections_callback_wrong_event
(
api
,
mocker
):
contacts
=
Contacts
(
api
)
contacts
.
_connections_callback
=
mocker
.
MagicMock
()
message
=
{
"
data
"
:
{
"
contactId
"
:
TEST_CONTACT_ID
},
"
name
"
:
"
SomeEvent
"
}
with
pytest
.
raises
(
Exception
,
match
=
"
Wrong event in callback: SomeEvent
"
):
contacts
.
handle_connections_callback
(
message
)
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