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
799382cb
Commit
799382cb
authored
Dec 06, 2019
by
Kenzo-Hugo Hillion
♻
Browse files
refacto base for tests as admin
parent
23929d48
Pipeline
#19418
failed with stages
in 2 minutes and 15 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
backend/metagenedb/api/catalog/views/test_bulk_viewset.py
View file @
799382cb
from
django.contrib.auth.models
import
User
from
requests.exceptions
import
HTTPError
from
rest_framework.test
import
APITestCase
from
rest_framework_jwt.settings
import
api_settings
from
metagenedb.apps.catalog.factory
import
FunctionFactory
from
metagenedb.common.utils.mocks.metagenedb
import
MetageneDBCatalogFunctionAPIMock
from
metagenedb.common.utils.tests.apitestbase
import
AdminUserBasedTest
class
TestOperationsBulkViewSetNoCredentials
(
APITestCase
):
...
...
@@ -32,7 +31,7 @@ class TestOperationsBulkViewSetNoCredentials(APITestCase):
self
.
function_api
.
put
(
data
,
function
.
function_id
)
class
TestOperationsBulkViewSet
(
A
PITestCase
):
class
TestOperationsBulkViewSet
(
A
dminUserBasedTest
):
"""
We are testing the different functions through the API directly through the mock redirecting
requests to the test database.
...
...
@@ -41,15 +40,8 @@ class TestOperationsBulkViewSet(APITestCase):
"""
def
setUp
(
self
):
jwt_payload_handler
=
api_settings
.
JWT_PAYLOAD_HANDLER
jwt_encode_handler
=
api_settings
.
JWT_ENCODE_HANDLER
user
=
User
.
objects
.
create_user
(
username
=
'user_admin'
,
email
=
'user@admin.com'
,
password
=
'pass'
)
user
.
is_active
=
True
user
.
is_staff
=
True
user
.
save
()
payload
=
jwt_payload_handler
(
user
)
jwt_token
=
jwt_encode_handler
(
payload
)
self
.
function_api
=
MetageneDBCatalogFunctionAPIMock
(
self
.
client
,
jwt_token
=
jwt_token
)
super
().
setUp
()
self
.
function_api
=
MetageneDBCatalogFunctionAPIMock
(
self
.
client
,
jwt_token
=
self
.
jwt_token
)
def
test_create_function
(
self
):
data
=
{
...
...
backend/metagenedb/api/catalog/views/test_gene.py
View file @
799382cb
...
...
@@ -20,24 +20,6 @@ class TestGenes(TestCase):
resp
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
resp
.
status_code
,
status
.
HTTP_200_OK
)
def
test_get_genes_auth
(
self
):
"""
Authenticated users should be able to access genes
"""
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
(
'api:catalog:v1:genes-list'
)
resp
=
self
.
client
.
get
(
url
,
format
=
'json'
,
HTTP_AUTHORIZATION
=
f
"JWT
{
token
}
"
)
self
.
assertEqual
(
resp
.
status_code
,
status
.
HTTP_200_OK
)
class
TestCountWindowsAPI
(
APITestCase
):
...
...
backend/metagenedb/common/utils/tests/__init__.py
0 → 100644
View file @
799382cb
backend/metagenedb/common/utils/tests/apitestbase.py
0 → 100644
View file @
799382cb
from
django.contrib.auth.models
import
User
from
rest_framework.test
import
APITestCase
from
rest_framework_jwt.settings
import
api_settings
class
AdminUserBasedTest
(
APITestCase
):
"""
We are testing the different functions through the API directly through the mock redirecting
requests to the test database.
The extent is a bit more than a unittest since it is not just involving concerned methods.
"""
def
setUp
(
self
):
jwt_payload_handler
=
api_settings
.
JWT_PAYLOAD_HANDLER
jwt_encode_handler
=
api_settings
.
JWT_ENCODE_HANDLER
user
=
User
.
objects
.
create_user
(
username
=
'user_admin'
,
email
=
'user@admin.com'
,
password
=
'pass'
)
user
.
is_active
=
True
user
.
is_staff
=
True
user
.
save
()
payload
=
jwt_payload_handler
(
user
)
self
.
jwt_token
=
jwt_encode_handler
(
payload
)
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