Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Briar GTK
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
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
Briar GTK
Commits
23952bb8
Commit
23952bb8
authored
5 years ago
by
Nico
Browse files
Options
Downloads
Patches
Plain Diff
Add method in API wrapper for pending contacts
parent
ea0f0890
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
src/briar/api/models/contacts.py
+14
-3
14 additions, 3 deletions
src/briar/api/models/contacts.py
tests/briar/api/models/test_contacts.py
+32
-1
32 additions, 1 deletion
tests/briar/api/models/test_contacts.py
with
46 additions
and
4 deletions
src/briar/api/models/contacts.py
+
14
−
3
View file @
23952bb8
...
...
@@ -5,15 +5,26 @@
from
urllib.parse
import
urljoin
from
requests
import
get
as
_get
from
requests
import
post
as
_post
from
briar.api.constants
import
BASE_HTTP_URL
from
briar.api.model
import
Model
# TODO: remove pylint disable once we have more methods
class
Contacts
(
Model
):
# pylint: disable=too-few-public-methods
class
Contacts
(
Model
):
API_ENDPOINT
=
"
contacts/
"
def
add_pending
(
self
,
link
,
alias
):
url
=
urljoin
(
BASE_HTTP_URL
,
self
.
API_ENDPOINT
+
"
add/
"
+
"
pending/
"
)
_post
(
url
,
headers
=
self
.
_headers
,
json
=
{
"
link
"
:
link
,
"
alias
"
:
alias
})
def
get
(
self
):
url
=
urljoin
(
BASE_HTTP_URL
,
'
contacts
'
)
url
=
urljoin
(
BASE_HTTP_URL
,
self
.
API_ENDPOINT
)
request
=
_get
(
url
,
headers
=
self
.
_headers
)
return
request
.
json
()
def
get_link
(
self
):
url
=
urljoin
(
BASE_HTTP_URL
,
self
.
API_ENDPOINT
+
"
add/
"
+
"
link/
"
)
request
=
_get
(
url
,
headers
=
self
.
_headers
).
json
()
return
request
[
'
link
'
]
This diff is collapsed.
Click to expand it.
tests/briar/api/models/test_contacts.py
+
32
−
1
View file @
23952bb8
...
...
@@ -8,13 +8,44 @@ import requests_mock
from
briar.api.models.contacts
import
Contacts
BASE_HTTP_URL
=
"
http://localhost:7000/v1/contacts/
"
TEST_LINK
=
"
briar://wvui4uvhbfv4tzo6xwngknebsxrafainnhldyfj63x6ipp4q2vigy
"
TEST_ALIAS
=
"
Alice
"
@requests_mock.Mocker
(
kw
=
"
requests_mock
"
)
def
test_add_pending
(
api
,
request_headers
,
requests_mock
):
contacts
=
Contacts
(
api
)
requests_mock
.
register_uri
(
"
POST
"
,
BASE_HTTP_URL
+
"
add/pending/
"
,
request_headers
=
request_headers
,
additional_matcher
=
match_request_add_pending
)
contacts
.
add_pending
(
TEST_LINK
,
TEST_ALIAS
)
@requests_mock.Mocker
(
kw
=
'
requests_mock
'
)
def
test_get_empty
(
api
,
request_headers
,
requests_mock
):
contacts
=
Contacts
(
api
)
response
=
[]
requests_mock
.
register_uri
(
"
GET
"
,
"
http://localhost:7000/v1/contacts
"
,
requests_mock
.
register_uri
(
"
GET
"
,
BASE_HTTP_URL
,
request_headers
=
request_headers
,
text
=
json
.
dumps
(
response
))
assert
contacts
.
get
()
==
response
@requests_mock.Mocker
(
kw
=
'
requests_mock
'
)
def
test_get_link
(
api
,
request_headers
,
requests_mock
):
contacts
=
Contacts
(
api
)
response
=
{
"
link
"
:
TEST_LINK
}
requests_mock
.
register_uri
(
"
GET
"
,
BASE_HTTP_URL
+
"
add/link/
"
,
request_headers
=
request_headers
,
text
=
json
.
dumps
(
response
))
assert
contacts
.
get_link
()
==
TEST_LINK
def
match_request_add_pending
(
request
):
return
{
"
alias
"
:
TEST_ALIAS
,
"
link
"
:
TEST_LINK
}
==
request
.
json
()
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