Преглед на файлове

test delete site

pull/2/head
Guillaume Vincent преди 9 години
родител
ревизия
eb32afe1c6
променени са 1 файла, в които са добавени 18 реда и са изтрити 5 реда
  1. +18
    -5
      lesspass/api/tests/tests_site.py

+ 18
- 5
lesspass/api/tests/tests_site.py Целия файл

@@ -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())

Зареждане…
Отказ
Запис