Skip to content
Snippets Groups Projects
Commit 4296f03e authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

[team] Add test for undeletable team

parent 2fa520a6
No related branches found
No related tags found
1 merge request!206Issue 406
...@@ -31,11 +31,15 @@ from rest_framework import status ...@@ -31,11 +31,15 @@ from rest_framework import status
from rest_framework.test import APITestCase from rest_framework.test import APITestCase
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.conf import settings
import os
import shutil
import simplejson as json import simplejson as json
from ..common.testutils import tearDownModule from ..common.testutils import tearDownModule
from .models import Team from .models import Team
from ..dataformats.models import DataFormat
from .serializers import SimpleTeamSerializer from .serializers import SimpleTeamSerializer
...@@ -57,6 +61,19 @@ class TeamTestCase(APITestCase): ...@@ -57,6 +61,19 @@ class TeamTestCase(APITestCase):
self.invalid_username = 'janedoe' self.invalid_username = 'janedoe'
# object to test sharing/deletion
if os.path.exists(settings.DATAFORMATS_ROOT):
shutil.rmtree(settings.DATAFORMATS_ROOT)
(dataformat, errors) = DataFormat.objects.create_dataformat(
author=self.johndoe,
name='data_format_shared_with_private_team',
)
assert dataformat, errors
dataformat.share(teams=[self.teamdoe_private])
self.dataformat = dataformat
#---------------------------------------------------------- #----------------------------------------------------------
...@@ -377,14 +394,31 @@ class TeamDeletionTestCase(TeamTestCase): ...@@ -377,14 +394,31 @@ class TeamDeletionTestCase(TeamTestCase):
options['owner_name'] = self.johndoe.username options['owner_name'] = self.johndoe.username
url = self.get_url(options) url = self.get_url(options)
self.assertEqual(self.teamdoe.total_shares(), 0)
response = self.client.delete(url, format='json') response = self.client.delete(url, format='json')
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
def test_logged_in_user_own_team_shared(self):
self.client.login(username=self.johndoe.username, password=self.password)
options = self.options
options['owner_name'] = self.johndoe.username
options['team_name'] = 'teamdoe_private'
url = self.get_url(options)
self.assertEqual(self.teamdoe_private.total_shares(), 1)
response = self.client.delete(url, format='json')
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_logged_in_user_team_from_other(self): def test_logged_in_user_team_from_other(self):
self.client.login(username=self.jackdoe, password=self.password) self.client.login(username=self.jackdoe, password=self.password)
url = self.get_url(self.options) url = self.get_url(self.options)
self.assertEqual(self.teamdoe.total_shares(), 0)
response = self.client.delete(url, format='json') response = self.client.delete(url, format='json')
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
...@@ -396,6 +430,8 @@ class TeamDeletionTestCase(TeamTestCase): ...@@ -396,6 +430,8 @@ class TeamDeletionTestCase(TeamTestCase):
options['owner_name'] = self.invalid_username options['owner_name'] = self.invalid_username
url = self.get_url(options) url = self.get_url(options)
self.assertEqual(self.teamdoe.total_shares(), 0)
response = self.client.delete(url, format='json') response = self.client.delete(url, format='json')
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment