Browse Source

test delete site

pull/2/head
Guillaume Vincent 9 years ago
parent
commit
eb32afe1c6
1 changed files with 18 additions and 5 deletions
  1. +18
    -5
      lesspass/api/tests/tests_site.py

+ 18
- 5
lesspass/api/tests/tests_site.py View File

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

Loading…
Cancel
Save