Commit 8127d4c6 authored by Michal Čihař's avatar Michal Čihař

Add tests for ACL filtering in API

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent a1919774
......@@ -23,8 +23,8 @@ from django.core.urlresolvers import reverse
from rest_framework.test import APITestCase
from weblate.trans.tests.utils import RepoTestMixin
from weblate.trans.tests.utils import get_test_file
from weblate.trans.models import Project
from weblate.trans.tests.utils import RepoTestMixin, get_test_file
TEST_PO = get_test_file('cs.po')
......@@ -46,6 +46,19 @@ class APIBaseTest(APITestCase, RepoTestMixin):
'slug': 'test'
}
def create_acl(self):
project = Project.objects.create(
name='ACL',
slug='acl',
enable_acl=True,
)
self._create_subproject(
'po-mono',
'po-mono/*.po',
'po-mono/en.po',
project=project,
)
def authenticate(self, superuser=False):
user, dummy = User.objects.get_or_create(username='test')
user.is_superuser = superuser
......@@ -77,6 +90,18 @@ class ProjectAPITest(APIBaseTest):
self.assertEqual(response.data['count'], 1)
self.assertEqual(response.data['results'][0]['slug'], 'test')
def test_list_projects_acl(self):
self.create_acl()
response = self.client.get(
reverse('api:project-list')
)
self.assertEqual(response.data['count'], 1)
self.authenticate(True)
response = self.client.get(
reverse('api:project-list')
)
self.assertEqual(response.data['count'], 2)
def test_get_project(self):
response = self.client.get(
reverse('api:project-detail', kwargs=self.project_kwargs)
......@@ -151,6 +176,18 @@ class ComponentAPITest(APIBaseTest):
response.data['results'][0]['project']['slug'], 'test'
)
def test_list_components_acl(self):
self.create_acl()
response = self.client.get(
reverse('api:component-list')
)
self.assertEqual(response.data['count'], 1)
self.authenticate(True)
response = self.client.get(
reverse('api:component-list')
)
self.assertEqual(response.data['count'], 2)
def test_get_component(self):
response = self.client.get(
reverse(
......@@ -272,6 +309,18 @@ class TranslationAPITest(APIBaseTest):
)
self.assertEqual(response.data['count'], 3)
def test_list_translations_acl(self):
self.create_acl()
response = self.client.get(
reverse('api:translation-list')
)
self.assertEqual(response.data['count'], 3)
self.authenticate(True)
response = self.client.get(
reverse('api:translation-list')
)
self.assertEqual(response.data['count'], 7)
def test_get_translation(self):
response = self.client.get(
reverse(
......
......@@ -140,7 +140,8 @@ class RepoTestMixin(object):
"""
Creates real test subproject.
"""
project = self.create_project()
if 'project' not in kwargs:
kwargs['project'] = self.create_project()
if vcs == 'mercurial':
branch = 'default'
......@@ -156,10 +157,10 @@ class RepoTestMixin(object):
if 'new_lang' not in kwargs:
kwargs['new_lang'] = 'contact'
return SubProject.objects.create(
name='Test',
slug='test',
project=project,
repo=repo,
push=push,
branch=branch,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment