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
39ede451
Commit
39ede451
authored
Aug 26, 2013
by
Weblate
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
67f65f69
92824ebb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
220 additions
and
179 deletions
+220
-179
trans/tests/__init__.py
trans/tests/__init__.py
+1
-0
trans/tests/test_remote.py
trans/tests/test_remote.py
+218
-0
trans/tests/views.py
trans/tests/views.py
+1
-179
No files found.
trans/tests/__init__.py
View file @
39ede451
...
...
@@ -50,3 +50,4 @@ from trans.tests.autofix import *
from
trans.tests.lock
import
*
from
trans.tests.formats
import
*
from
trans.tests.test_naturaldate
import
*
from
trans.tests.test_remote
import
*
trans/tests/test_remote.py
0 → 100644
View file @
39ede451
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2013 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
'''
Tests for changes done in remote repository.
'''
from
trans.models
import
SubProject
from
trans.tests.models
import
REPOWEB_URL
from
trans.tests.views
import
ViewTestCase
from
django.utils
import
timezone
EXTRA_PO
=
'''
#: accounts/models.py:319 trans/views/basic.py:104 weblate/html/index.html:21
msgid "Languages"
msgstr "Jazyky"
'''
MINIMAL_PO
=
r'''
msgid ""
msgstr ""
"Project-Id-Version: Weblate Hello World 2012\n"
"Report-Msgid-Bugs-To: <noreply@example.net>\n"
"POT-Creation-Date: 2012-03-14 15:54+0100\n"
"PO-Revision-Date: 2013-08-25 15:23+0200\n"
"Last-Translator: testuser <>\n"
"Language-Team: Czech <http://example.com/projects/test/test/cs/>\n"
"Language: cs\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"
"X-Generator: Weblate 1.7-dev\n"
#: main.c:11
#, c-format
msgid "Hello, world!\n"
msgstr "Nazdar svete!\n"
'''
class
MultiRepoTest
(
ViewTestCase
):
'''
Tests handling of remote changes, conflicts and so on.
'''
def
setUp
(
self
):
super
(
MultiRepoTest
,
self
).
setUp
()
self
.
subproject2
=
SubProject
.
objects
.
create
(
name
=
'Test 2'
,
slug
=
'test-2'
,
project
=
self
.
project
,
repo
=
self
.
repo_path
,
push
=
self
.
repo_path
,
filemask
=
'po/*.po'
,
template
=
''
,
file_format
=
'po'
,
repoweb
=
REPOWEB_URL
,
new_base
=
''
,
)
self
.
request
=
self
.
get_request
(
'/'
)
def
push_first
(
self
,
propagate
=
True
,
newtext
=
'Nazdar svete!
\
n
'
):
'''
Changes and pushes first subproject.
'''
if
not
propagate
:
# Disable changes propagating
self
.
subproject2
.
allow_translation_propagation
=
False
self
.
subproject2
.
save
()
unit
=
self
.
get_unit
()
unit
.
translate
(
self
.
request
,
[
newtext
],
False
)
self
.
assertEqual
(
self
.
get_translation
().
translated
,
1
)
self
.
subproject
.
do_push
(
self
.
request
)
def
push_replace
(
self
,
content
,
mode
):
'''
Replaces content of a po file and pushes it to remote repository.
'''
# Manually edit po file, adding new unit
translation
=
self
.
subproject
.
translation_set
.
get
(
language_code
=
'cs'
)
with
open
(
translation
.
get_filename
(),
mode
)
as
handle
:
handle
.
write
(
content
)
# Do changes in first repo
translation
.
git_commit
(
self
.
request
,
'TEST <test@example.net>'
,
timezone
.
now
(),
force_commit
=
True
)
translation
.
subproject
.
do_push
(
self
.
request
)
def
test_propagate
(
self
):
'''
Tests handling of propagating.
'''
# Do changes in first repo
self
.
push_first
()
# Verify changes got to the second one
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
self
.
assertEqual
(
translation
.
translated
,
1
)
def
test_update
(
self
):
'''
Tests handling update in case remote has changed.
'''
# Do changes in first repo
self
.
push_first
(
False
)
# Test pull
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
self
.
assertEqual
(
translation
.
translated
,
0
)
translation
.
do_update
(
self
.
request
)
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
self
.
assertEqual
(
translation
.
translated
,
1
)
def
test_conflict
(
self
):
'''
Tests conflict handling.
'''
# Do changes in first repo
self
.
push_first
(
False
)
# Do changes in the second repo
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
unit
=
translation
.
unit_set
.
get
(
source
=
'Hello, world!
\
n
'
)
unit
.
translate
(
self
.
request
,
'Ahoj svete!
\
n
'
,
False
)
self
.
assertFalse
(
translation
.
do_update
(
self
.
request
))
def
test_more_changes
(
self
):
'''
Test more string changes in remote repo.
'''
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
self
.
push_first
(
False
,
'Hello, world!
\
n
'
)
translation
.
do_update
(
self
.
request
)
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
self
.
assertEqual
(
translation
.
failing_checks
,
1
)
self
.
push_first
(
False
,
'Nazdar svete
\
n
'
)
translation
.
do_update
(
self
.
request
)
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
self
.
assertEqual
(
translation
.
failing_checks
,
0
)
def
test_new_unit
(
self
):
'''
Tests adding new unit with update.
'''
self
.
push_replace
(
EXTRA_PO
,
'a'
)
self
.
subproject2
.
do_update
(
self
.
request
)
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
self
.
assertEqual
(
translation
.
total
,
5
)
def
test_deleted_unit
(
self
):
'''
Test removing several units from remote repo.
'''
self
.
push_replace
(
MINIMAL_PO
,
'w'
)
self
.
subproject2
.
do_update
(
self
.
request
)
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
self
.
assertEqual
(
translation
.
total
,
1
)
def
test_deleted_stale_unit
(
self
):
'''
Test removing several units from remote repo with no
other reference, so full cleanup has to happen.
'''
self
.
push_replace
(
MINIMAL_PO
,
'w'
)
self
.
subproject
.
delete
()
self
.
subproject2
.
do_update
(
self
.
request
)
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
self
.
assertEqual
(
translation
.
total
,
1
)
trans/tests/views.py
View file @
39ede451
...
...
@@ -27,10 +27,8 @@ from django.contrib.auth.models import User
from
django.core.urlresolvers
import
reverse
from
django.contrib.messages.storage.fallback
import
FallbackStorage
from
trans.models.changes
import
Change
from
django.utils
import
timezone
from
trans.models.unitdata
import
Suggestion
from
trans.models
import
SubProject
from
trans.tests.models
import
RepoTestCase
,
REPOWEB_URL
from
trans.tests.models
import
RepoTestCase
from
accounts.models
import
Profile
from
PIL
import
Image
import
re
...
...
@@ -38,34 +36,6 @@ import time
from
urlparse
import
urlsplit
from
cStringIO
import
StringIO
EXTRA_PO
=
'''
#: accounts/models.py:319 trans/views/basic.py:104 weblate/html/index.html:21
msgid "Languages"
msgstr "Jazyky"
'''
MINIMAL_PO
=
r'''
msgid ""
msgstr ""
"Project-Id-Version: Weblate Hello World 2012\n"
"Report-Msgid-Bugs-To: <noreply@example.net>\n"
"POT-Creation-Date: 2012-03-14 15:54+0100\n"
"PO-Revision-Date: 2013-08-25 15:23+0200\n"
"Last-Translator: testuser <>\n"
"Language-Team: Czech <http://example.com/projects/test/test/cs/>\n"
"Language: cs\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"
"X-Generator: Weblate 1.7-dev\n"
#: main.c:11
#, c-format
msgid "Hello, world!\n"
msgstr "Nazdar svete!\n"
'''
class
ViewTestCase
(
RepoTestCase
):
def
setUp
(
self
):
...
...
@@ -1090,151 +1060,3 @@ class LanguagesViewTest(ViewTestCase):
))
self
.
assertContains
(
response
,
'Czech'
)
self
.
assertContains
(
response
,
'Test/Test'
)
class
MultiRepoTest
(
ViewTestCase
):
'''
Tests handling of remote changes, conflicts and so on.
'''
def
setUp
(
self
):
super
(
MultiRepoTest
,
self
).
setUp
()
self
.
subproject2
=
SubProject
.
objects
.
create
(
name
=
'Test 2'
,
slug
=
'test-2'
,
project
=
self
.
project
,
repo
=
self
.
repo_path
,
push
=
self
.
repo_path
,
filemask
=
'po/*.po'
,
template
=
''
,
file_format
=
'po'
,
repoweb
=
REPOWEB_URL
,
new_base
=
''
,
)
self
.
request
=
self
.
get_request
(
'/'
)
def
push_first
(
self
,
propagate
=
True
,
newtext
=
'Nazdar svete!
\
n
'
):
'''
Changes and pushes first subproject.
'''
if
not
propagate
:
# Disable changes propagating
self
.
subproject2
.
allow_translation_propagation
=
False
self
.
subproject2
.
save
()
unit
=
self
.
get_unit
()
unit
.
translate
(
self
.
request
,
[
newtext
],
False
)
self
.
assertEqual
(
self
.
get_translation
().
translated
,
1
)
self
.
subproject
.
do_push
(
self
.
request
)
def
test_propagate
(
self
):
'''
Tests handling of propagating.
'''
# Do changes in first repo
self
.
push_first
()
# Verify changes got to the second one
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
self
.
assertEqual
(
translation
.
translated
,
1
)
def
test_update
(
self
):
'''
Tests handling update in case remote has changed.
'''
# Do changes in first repo
self
.
push_first
(
False
)
# Test pull
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
self
.
assertEqual
(
translation
.
translated
,
0
)
translation
.
do_update
(
self
.
request
)
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
self
.
assertEqual
(
translation
.
translated
,
1
)
def
test_conflict
(
self
):
'''
Tests conflict handling.
'''
# Do changes in first repo
self
.
push_first
(
False
)
# Do changes in the second repo
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
unit
=
translation
.
unit_set
.
get
(
source
=
'Hello, world!
\
n
'
)
unit
.
translate
(
self
.
request
,
'Ahoj svete!
\
n
'
,
False
)
self
.
assertFalse
(
translation
.
do_update
(
self
.
request
))
def
test_more_changes
(
self
):
'''
Test more string changes in remote repo.
'''
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
self
.
push_first
(
False
,
'Hello, world!
\
n
'
)
translation
.
do_update
(
self
.
request
)
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
self
.
assertEqual
(
translation
.
failing_checks
,
1
)
self
.
push_first
(
False
,
'Nazdar svete
\
n
'
)
translation
.
do_update
(
self
.
request
)
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
self
.
assertEqual
(
translation
.
failing_checks
,
0
)
def
test_new_unit
(
self
):
'''
Tests adding new unit with update.
'''
# Manually edit po file, adding new unit
translation
=
self
.
subproject
.
translation_set
.
get
(
language_code
=
'cs'
)
with
open
(
translation
.
get_filename
(),
'a'
)
as
handle
:
handle
.
write
(
EXTRA_PO
)
# Do changes in first repo
self
.
push_first
(
False
)
self
.
subproject2
.
do_update
(
self
.
request
)
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
self
.
assertEqual
(
translation
.
total
,
5
)
def
test_deleted_unit
(
self
):
# Manually edit po file, adding new unit
translation
=
self
.
subproject
.
translation_set
.
get
(
language_code
=
'cs'
)
with
open
(
translation
.
get_filename
(),
'w'
)
as
handle
:
handle
.
write
(
MINIMAL_PO
)
# Do changes in first repo
translation
.
git_commit
(
self
.
request
,
'TEST <test@example.net>'
,
timezone
.
now
(),
force_commit
=
True
)
translation
.
subproject
.
do_push
(
self
.
request
)
self
.
subproject2
.
do_update
(
self
.
request
)
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
self
.
assertEqual
(
translation
.
total
,
1
)
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