Commit 40765cbc authored by Kenzo-Hugo Hillion's avatar 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
......@@ -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
......
......@@ -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)
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)
......@@ -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),
]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment