tests/api

This commit is contained in:
Tobias Lindenberg
2021-01-10 14:32:41 +01:00
parent bc1f28eda6
commit 67581c7fa4
10 changed files with 308 additions and 99 deletions

View File

@ -1,11 +1,9 @@
import json
from django.contrib import auth
from django.db.models import ProtectedError
from django.urls import reverse
from cookbook.models import Storage, Sync
from cookbook.tests.views.test_views import TestViews
from django.contrib import auth
from django.urls import reverse
class TestApiSync(TestViews):
@ -28,8 +26,16 @@ class TestApiSync(TestViews):
def test_sync_list(self):
# verify view permissions are applied accordingly
self.batch_requests([(self.anonymous_client, 403), (self.guest_client_1, 403), (self.user_client_1, 403), (self.admin_client_1, 200), (self.superuser_client, 200)],
reverse('api:sync-list'))
self.batch_requests(
[
(self.anonymous_client, 403),
(self.guest_client_1, 403),
(self.user_client_1, 403),
(self.admin_client_1, 200),
(self.superuser_client, 200)
],
reverse('api:sync-list')
)
# verify sync is returned
r = self.admin_client_1.get(reverse('api:sync-list'))
@ -41,13 +47,22 @@ class TestApiSync(TestViews):
def test_sync_update(self):
# can update sync as admin
r = self.admin_client_1.patch(reverse('api:sync-detail', args={self.sync.id}), {'path': 'new'}, content_type='application/json')
r = self.admin_client_1.patch(
reverse(
'api:sync-detail',
args={self.sync.id}
),
{'path': 'new'},
content_type='application/json'
)
response = json.loads(r.content)
self.assertEqual(r.status_code, 200)
self.assertEqual(response['path'], 'new')
def test_sync_delete(self):
# can delete sync as admin
r = self.admin_client_1.delete(reverse('api:sync-detail', args={self.sync.id}))
r = self.admin_client_1.delete(
reverse('api:sync-detail', args={self.sync.id})
)
self.assertEqual(r.status_code, 204)
self.assertEqual(Sync.objects.count(), 0)