Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
8127d4c6
Commit
8127d4c6
authored
Mar 25, 2016
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for ACL filtering in API
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
a1919774
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
4 deletions
+54
-4
weblate/api/tests.py
weblate/api/tests.py
+51
-2
weblate/trans/tests/utils.py
weblate/trans/tests/utils.py
+3
-2
No files found.
weblate/api/tests.py
View file @
8127d4c6
...
...
@@ -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
(
...
...
weblate/trans/tests/utils.py
View file @
8127d4c6
...
...
@@ -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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment