Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Metagenomics
metagenedb
Commits
40765cbc
Commit
40765cbc
authored
Jun 19, 2019
by
Kenzo-Hugo Hillion
♻
Browse files
add more tests
try desesperate move for CI
parent
4f196a10
Pipeline
#12667
passed with stage
in 1 minute and 7 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
40765cbc
...
...
@@ -21,7 +21,7 @@ cache:
before_script
:
-
cd backend
-
pip install -r requirements_dev.txt
-
pip install .
-
pip install
-e
.
test-backend
:
stage
:
lint_test_coverage_backend
...
...
backend/metagenedb/apps/accounts/test
_auth
.py
→
backend/metagenedb/apps/accounts/test
s
.py
View file @
40765cbc
...
...
@@ -4,6 +4,7 @@ from rest_framework import status
from
django.contrib.auth.models
import
User
from
rest_framework_jwt.settings
import
api_settings
class
TestAccounts
(
APITestCase
):
...
...
@@ -26,3 +27,22 @@ class TestAccounts(APITestCase):
resp
=
self
.
client
.
post
(
url
,
{
'username'
:
'user'
,
'password'
:
'pass'
},
format
=
'json'
)
self
.
assertEqual
(
resp
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertTrue
(
'token'
in
resp
.
data
)
def
test_verify_jwt
(
self
):
jwt_payload_handler
=
api_settings
.
JWT_PAYLOAD_HANDLER
jwt_encode_handler
=
api_settings
.
JWT_ENCODE_HANDLER
user
=
User
.
objects
.
create_user
(
username
=
'user'
,
email
=
'user@foo.com'
,
password
=
'pass'
)
user
.
is_active
=
True
user
.
save
()
payload
=
jwt_payload_handler
(
user
)
token
=
jwt_encode_handler
(
payload
)
verify_url
=
reverse
(
'api-jwt-verify'
)
credentials
=
{
'token'
:
token
}
resp
=
self
.
client
.
post
(
verify_url
,
credentials
,
format
=
'json'
)
self
.
assertEqual
(
resp
.
status_code
,
status
.
HTTP_200_OK
)
backend/metagenedb/apps/catalog/models/test_views.py
0 → 100644
View file @
40765cbc
from
django.contrib.auth.models
import
User
from
django.test
import
TestCase
from
django.urls
import
reverse
from
rest_framework
import
status
from
rest_framework_jwt.settings
import
api_settings
class
TestGenes
(
TestCase
):
"""Post Tests"""
def
test_get_genes_no_auth
(
self
):
"""
Unauthenticated users should not be able to access genes via APIListView
"""
url
=
reverse
(
'genes'
)
resp
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
resp
.
status_code
,
status
.
HTTP_401_UNAUTHORIZED
)
def
test_get_genes_auth
(
self
):
"""
Authenticated users should be able to access genes via APIListView
"""
jwt_payload_handler
=
api_settings
.
JWT_PAYLOAD_HANDLER
jwt_encode_handler
=
api_settings
.
JWT_ENCODE_HANDLER
user
=
User
.
objects
.
create_user
(
username
=
'user'
,
email
=
'user@foo.com'
,
password
=
'pass'
)
user
.
is_active
=
True
user
.
save
()
payload
=
jwt_payload_handler
(
user
)
token
=
jwt_encode_handler
(
payload
)
url
=
reverse
(
'genes'
)
resp
=
self
.
client
.
get
(
url
,
format
=
'json'
,
HTTP_AUTHORIZATION
=
f
"JWT
{
token
}
"
)
self
.
assertEqual
(
resp
.
status_code
,
status
.
HTTP_200_OK
)
backend/metagenedb/apps/catalog/urls.py
View file @
40765cbc
...
...
@@ -4,6 +4,6 @@ from . import views
urlpatterns
=
[
path
(
''
,
views
.
index
,
name
=
'index'
),
re_path
(
r
'^api/genes
/
$'
,
views
.
gene_list
),
re_path
(
r
'^api/genes$'
,
views
.
gene_list
,
name
=
'genes'
),
re_path
(
r
'^api/genes/(?P<gene_id>.*)$'
,
views
.
gene_detail
),
]
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment