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
4972f334
Commit
4972f334
authored
4 years ago
by
Nico
Browse files
Options
Downloads
Patches
Plain Diff
Add unit tests
parent
fa408b12
No related branches found
Branches containing commit
Tags
0.0.7
No related merge requests found
Pipeline
#5947
failed
4 years ago
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
briar_wrapper/models/contacts.py
+9
-2
9 additions, 2 deletions
briar_wrapper/models/contacts.py
tests/briar_wrapper/models/test_contacts.py
+83
-0
83 additions, 0 deletions
tests/briar_wrapper/models/test_contacts.py
with
92 additions
and
2 deletions
briar_wrapper/models/contacts.py
+
9
−
2
View file @
4972f334
...
...
@@ -4,7 +4,7 @@
"""
Wrapper around Briar API
'
s _/contacts/_ resource
"""
from
json.decoder
import
JSONDecodeError
from
operator
import
itemgetter
from
typing
import
Callable
,
List
from
urllib.parse
import
urljoin
...
...
@@ -160,7 +160,14 @@ class Contacts(Model):
@staticmethod
def
_handle_add_pending_error
(
response
):
error
=
response
.
json
()
error
=
dict
()
try
:
error
=
response
.
json
()
except
JSONDecodeError
:
raise
BriarWrapperException
(
response
,
"
An unknown error occurred while
"
"
adding a pending contact:
"
"
JSONDecodeError
"
)
if
response
.
status_code
==
400
:
if
error
[
"
error
"
]
==
"
INVALID_PUBLIC_KEY
"
:
raise
PendingContactInvalidPublicKeyException
(
response
)
...
...
This diff is collapsed.
Click to expand it.
tests/briar_wrapper/models/test_contacts.py
+
83
−
0
View file @
4972f334
...
...
@@ -6,6 +6,15 @@ import json
import
pytest
import
requests_mock
from
briar_wrapper.exception
import
BriarWrapperException
from
briar_wrapper.exceptions.pending_already_exists_contact
import
\
PendingContactAlreadyExistsContact
from
briar_wrapper.exceptions.pending_already_exists_pending_contact
import
\
PendingContactAlreadyExistsPendingContact
from
briar_wrapper.exceptions.pending_invalid_link
import
\
PendingContactInvalidLinkException
from
briar_wrapper.exceptions.pending_invalid_public_key
import
\
PendingContactInvalidPublicKeyException
from
briar_wrapper.models.contacts
import
Contacts
from
briar_wrapper.models.socket_listener
import
SocketListener
...
...
@@ -14,6 +23,7 @@ BASE_HTTP_URL = "http://localhost:7000/v1/contacts/"
TEST_ALIAS
=
"
Alice
"
TEST_CONTACT_ID
=
42
TEST_PENDING_CONTACT_ID
=
"
jsTgWcsEQ2g9rnomeK1g/hmO8M1Ix6ZIGWAjgBtlS9U=
"
TEST_CONTACT_FIRST
=
{
"
lastChatActivity
"
:
1
...
...
@@ -50,6 +60,79 @@ def match_request_add_pending(request):
return
{
"
alias
"
:
TEST_ALIAS
,
"
link
"
:
TEST_LINK
}
==
request
.
json
()
@requests_mock.Mocker
(
kw
=
"
requests_mock
"
)
def
test_add_pending_invalid_public_key
(
api
,
request_headers
,
requests_mock
):
contacts
=
Contacts
(
api
)
requests_mock
.
post
(
BASE_HTTP_URL
+
"
add/pending/
"
,
status_code
=
400
,
json
=
{
"
error
"
:
"
INVALID_PUBLIC_KEY
"
})
with
pytest
.
raises
(
PendingContactInvalidPublicKeyException
):
contacts
.
add_pending
(
TEST_LINK
,
TEST_ALIAS
)
@requests_mock.Mocker
(
kw
=
"
requests_mock
"
)
def
test_add_pending_invalid_link
(
api
,
request_headers
,
requests_mock
):
contacts
=
Contacts
(
api
)
requests_mock
.
post
(
BASE_HTTP_URL
+
"
add/pending/
"
,
status_code
=
400
,
json
=
{
"
error
"
:
"
INVALID_LINK
"
})
with
pytest
.
raises
(
PendingContactInvalidLinkException
):
contacts
.
add_pending
(
TEST_LINK
,
TEST_ALIAS
)
@requests_mock.Mocker
(
kw
=
"
requests_mock
"
)
def
test_add_pending_contact_exists
(
api
,
request_headers
,
requests_mock
):
contacts
=
Contacts
(
api
)
requests_mock
.
post
(
BASE_HTTP_URL
+
"
add/pending/
"
,
status_code
=
403
,
json
=
{
"
error
"
:
"
CONTACT_EXISTS
"
})
with
pytest
.
raises
(
PendingContactAlreadyExistsContact
):
contacts
.
add_pending
(
TEST_LINK
,
TEST_ALIAS
)
@requests_mock.Mocker
(
kw
=
"
requests_mock
"
)
def
test_add_pending_pending_exists
(
api
,
request_headers
,
requests_mock
):
contacts
=
Contacts
(
api
)
requests_mock
.
post
(
BASE_HTTP_URL
+
"
add/pending/
"
,
status_code
=
403
,
json
=
{
"
error
"
:
"
PENDING_EXISTS
"
})
with
pytest
.
raises
(
PendingContactAlreadyExistsPendingContact
):
contacts
.
add_pending
(
TEST_LINK
,
TEST_ALIAS
)
@requests_mock.Mocker
(
kw
=
"
requests_mock
"
)
def
test_add_pending_unknown_error
(
api
,
request_headers
,
requests_mock
):
contacts
=
Contacts
(
api
)
requests_mock
.
post
(
BASE_HTTP_URL
+
"
add/pending/
"
,
status_code
=
500
,
json
=
{
"
error
"
:
"
CRAZY_ERROR
"
})
with
pytest
.
raises
(
BriarWrapperException
):
contacts
.
add_pending
(
TEST_LINK
,
TEST_ALIAS
)
@requests_mock.Mocker
(
kw
=
"
requests_mock
"
)
def
test_add_pending_no_json
(
api
,
request_headers
,
requests_mock
):
contacts
=
Contacts
(
api
)
requests_mock
.
post
(
BASE_HTTP_URL
+
"
add/pending/
"
,
status_code
=
500
)
with
pytest
.
raises
(
BriarWrapperException
):
contacts
.
add_pending
(
TEST_LINK
,
TEST_ALIAS
)
@requests_mock.Mocker
(
kw
=
"
requests_mock
"
)
def
test_delete_pending
(
api
,
request_headers
,
requests_mock
):
contacts
=
Contacts
(
api
)
requests_mock
.
register_uri
(
"
DELETE
"
,
BASE_HTTP_URL
+
"
add/pending/
"
,
request_headers
=
request_headers
,
additional_matcher
=
match_request_delete_pending
)
contacts
.
delete_pending
(
TEST_PENDING_CONTACT_ID
)
def
match_request_delete_pending
(
request
):
return
{
"
pendingContactId
"
:
TEST_PENDING_CONTACT_ID
}
==
request
.
json
()
@requests_mock.Mocker
(
kw
=
"
requests_mock
"
)
def
test_set_alias
(
api
,
request_headers
,
requests_mock
):
contacts
=
Contacts
(
api
)
...
...
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