add tests for authenticated backup views

This commit is contained in:
Andreas Zweili 2020-12-06 14:18:48 +01:00
parent 2d880b689c
commit 3cb5a1f0b9
2 changed files with 50 additions and 0 deletions

View File

@ -10,6 +10,13 @@ def test_unauthorized_request_backup_method(api_client):
assert response.status_code == 403
@pytest.mark.django_db
def test_authorized_request_backup_method(api_client_authenticatet):
url = reverse('backupmethod-list')
response = api_client_authenticatet.get(url)
assert response.status_code == 200
@pytest.mark.django_db
def test_unauthorized_request_backup(api_client):
url = reverse('backup-list')
@ -17,6 +24,13 @@ def test_unauthorized_request_backup(api_client):
assert response.status_code == 403
@pytest.mark.django_db
def test_authorized_request_backup(api_client_authenticatet):
url = reverse('backup-list')
response = api_client_authenticatet.get(url)
assert response.status_code == 200
@pytest.mark.django_db
def test_unauthorized_request_target_device(api_client):
url = reverse('targetdevice-list')
@ -24,6 +38,13 @@ def test_unauthorized_request_target_device(api_client):
assert response.status_code == 403
@pytest.mark.django_db
def test_authorized_request_target_device(api_client_authenticatet):
url = reverse('targetdevice-list')
response = api_client_authenticatet.get(url)
assert response.status_code == 200
@pytest.mark.django_db
def test_unauthorized_request_notificaton_from_backup(api_client):
url = reverse('notificationfrombackup-list')
@ -31,6 +52,13 @@ def test_unauthorized_request_notificaton_from_backup(api_client):
assert response.status_code == 403
@pytest.mark.django_db
def test_authorized_request_notificaton_from_backup(api_client_authenticatet):
url = reverse('notificationfrombackup-list')
response = api_client_authenticatet.get(url)
assert response.status_code == 200
@pytest.mark.django_db
def test_unauthorized_request_notificaton(api_client):
url = reverse('notification-list')
@ -38,8 +66,22 @@ def test_unauthorized_request_notificaton(api_client):
assert response.status_code == 403
@pytest.mark.django_db
def test_authorized_request_notificaton(api_client_authenticatet):
url = reverse('notification-list')
response = api_client_authenticatet.get(url)
assert response.status_code == 200
@pytest.mark.django_db
def test_unauthorized_request_notificaton_type(api_client):
url = reverse('notificationtype-list')
response = api_client.get(url)
assert response.status_code == 403
@pytest.mark.django_db
def test_authorized_request_notificaton_type(api_client_authenticatet):
url = reverse('notificationtype-list')
response = api_client_authenticatet.get(url)
assert response.status_code == 200

View File

@ -42,3 +42,11 @@ def create_admin_user():
def api_client():
from rest_framework.test import APIClient
return APIClient()
@pytest.fixture
def api_client_authenticatet(db, create_admin_user, api_client):
fixture = create_admin_user()
api_client.force_authenticate(user=fixture['admin'])
yield api_client
api_client.force_authenticate(user=None)