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
929ead31
Commit
929ead31
authored
5 years ago
by
Nico
Browse files
Options
Downloads
Patches
Plain Diff
Use pytest fixtures and no more unittest TestCases
Also randomly generate an auth_token now.
parent
c86a3f8a
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/briar/api/models/test_contacts.py
+28
-25
28 additions, 25 deletions
tests/briar/api/models/test_contacts.py
tests/briar/api/test_constants.py
+16
-15
16 additions, 15 deletions
tests/briar/api/test_constants.py
tests/briar/gtk/test_define.py
+2
-6
2 additions, 6 deletions
tests/briar/gtk/test_define.py
with
46 additions
and
46 deletions
tests/briar/api/models/test_contacts.py
+
28
−
25
View file @
929ead31
...
...
@@ -3,39 +3,42 @@
# License-Filename: LICENSE.md
import
json
from
random
import
choices
import
requests_mock
from
unittest
import
mock
,
TestCase
from
string
import
ascii_letters
,
digits
from
unittest
import
mock
import
pytest
from
briar.api.models.contacts
import
Contacts
class
TestContacts
(
TestCase
):
@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
"
,
request_headers
=
request_headers
,
text
=
json
.
dumps
(
response
))
assert
contacts
.
get
()
==
response
# TODO: randomly generate token
AUTH_TOKEN
=
"
xxhQhFNdq5R2YcipNcT3uYoMyOT2PxBl3tpWiO5Qy65w=
"
@requests_mock.Mocker
()
def
test_get_empty
(
self
,
requests_mock
):
api
=
TestContacts
.
_get_mocked_api
()
request_headers
=
TestContacts
.
_get_mocked_request_headers
()
@pytest.fixture
def
api
(
auth_token
):
api
=
mock
.
Mock
()
api
.
auth_token
=
auth_token
return
api
contacts
=
Contacts
(
api
)
response
=
list
()
requests_mock
.
register_uri
(
"
GET
"
,
"
http://localhost:7000/v1/contacts
"
,
request_headers
=
request_headers
,
text
=
json
.
dumps
(
response
))
assert
contacts
.
get
()
==
response
@pytest.fixture
def
request_headers
(
auth_token
):
request_headers
=
{
"
Authorization
"
:
'
Bearer %s
'
%
auth_token
}
return
request_headers
# TODO: Use pytest fixtures
def
_get_mocked_api
():
api
=
mock
.
Mock
()
api
.
auth_token
=
TestContacts
.
AUTH_TOKEN
return
api
# TODO: Use pytest fixtures
def
_get_mocked_request_headers
():
request_headers
=
{}
authorization_header
=
'
Bearer %s
'
%
TestContacts
.
AUTH_TOKEN
request_headers
[
"
Authorization
"
]
=
authorization_header
return
request_headers
@pytest.fixture
def
auth_token
():
return
''
.
join
(
choices
(
ascii_letters
+
digits
,
k
=
33
))
This diff is collapsed.
Click to expand it.
tests/briar/api/test_constants.py
+
16
−
15
View file @
929ead31
...
...
@@ -4,28 +4,29 @@
from
os.path
import
join
from
pathlib
import
Path
from
unittest
import
TestCase
import
pytest
from
briar.api.constants
import
BASE_HTTP_URL
,
BRIAR_AUTH_TOKEN
from
briar.api.constants
import
BRIAR_DB
,
WEBSOCKET_URL
class
TestConstants
(
TestCase
):
def
test_base_http_url
():
assert
BASE_HTTP_URL
==
"
http://localhost:7000/v1/
"
def
test_briar_auth_token
(
briar_dir
):
assert
BRIAR_AUTH_TOKEN
==
join
(
briar_dir
,
"
auth_token
"
)
def
test_b
ase_http_url
(
self
):
assert
B
ASE_HTTP_URL
==
"
http://localhost:7000/v1/
"
def
test_b
riar_db
(
briar_dir
):
assert
B
RIAR_DB
==
join
(
briar_dir
,
"
db
"
,
"
db.mv.db
"
)
def
test_briar_auth_token
(
self
):
briar_dir
=
TestConstants
.
_get_briar_dir
()
assert
BRIAR_AUTH_TOKEN
==
join
(
briar_dir
,
"
auth_token
"
)
def
test_briar_db
(
self
):
briar_dir
=
TestConstants
.
_get_briar_dir
()
assert
BRIAR_DB
==
join
(
briar_dir
,
"
db
"
,
"
db.mv.db
"
)
def
test_websocket_url
():
assert
WEBSOCKET_URL
==
"
ws://localhost:7000/v1/ws
"
def
test_websocket_url
(
self
):
assert
WEBSOCKET_URL
==
"
ws://localhost:7000/v1/ws
"
# TODO: Use
pytest
fixture
s
def
_get_
briar_dir
():
return
join
(
str
(
Path
.
home
()),
"
.briar
"
)
@
pytest
.
fixture
def
briar_dir
():
return
join
(
str
(
Path
.
home
()),
"
.briar
"
)
This diff is collapsed.
Click to expand it.
tests/briar/gtk/test_define.py
+
2
−
6
View file @
929ead31
...
...
@@ -2,14 +2,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# License-Filename: LICENSE.md
from
unittest
import
TestCase
from
gi.repository
import
Gio
from
briar.gtk.define
import
App
class
TestDefine
(
TestCase
):
def
test_app
(
self
):
assert
App
==
Gio
.
Application
.
get_default
def
test_app
():
assert
App
==
Gio
.
Application
.
get_default
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