Quellcode durchsuchen

test delete site

pull/2/head
Guillaume Vincent vor 9 Jahren
Ursprung
Commit
eb32afe1c6
1 geänderte Dateien mit 18 neuen und 5 gelöschten Zeilen
  1. +18
    -5
      lesspass/api/tests/tests_site.py

+ 18
- 5
lesspass/api/tests/tests_site.py Datei anzeigen

@@ -1,5 +1,6 @@
from rest_framework.test import APITestCase, APIClient

from api import models
from api.tests import factories


@@ -21,13 +22,25 @@ class LoginApiTestCase(APITestCase):

def test_retrieve_its_own_sites(self):
site = factories.SiteFactory(user=self.user)
not_my_site = factories.SiteFactory(user=factories.UserFactory())

request = self.client.get('/api/sites/%s/' % not_my_site.id)
self.assertEqual(404, request.status_code)

request = self.client.get('/api/sites/')
self.assertEqual(1, len(request.data['results']))
self.assertEqual(site.name, request.data['results'][0]['name'])

def test_cant_retrieve_other_sites(self):
not_my_site = factories.SiteFactory(user=factories.UserFactory())
request = self.client.get('/api/sites/%s/' % not_my_site.id)
self.assertEqual(404, request.status_code)

def test_delete_its_own_sites(self):
site = factories.SiteFactory(user=self.user)
self.assertEqual(1, models.Site.objects.all().count())
request = self.client.delete('/api/sites/%s/' % site.id)
self.assertEqual(204, request.status_code)
self.assertEqual(0, models.Site.objects.all().count())

def test_cant_delete_other_site(self):
not_my_site = factories.SiteFactory(user=factories.UserFactory())
self.assertEqual(1, models.Site.objects.all().count())
request = self.client.delete('/api/sites/%s/' % not_my_site.id)
self.assertEqual(404, request.status_code)
self.assertEqual(1, models.Site.objects.all().count())

Laden…
Abbrechen
Speichern