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
fe4db295
Commit
fe4db295
authored
Mar 22, 2016
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split out core repository tests to mixin
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
a06ed41e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
300 additions
and
289 deletions
+300
-289
weblate/trans/tests/test_models.py
weblate/trans/tests/test_models.py
+4
-289
weblate/trans/tests/utils.py
weblate/trans/tests/utils.py
+296
-0
No files found.
weblate/trans/tests/test_models.py
View file @
fe4db295
...
...
@@ -24,314 +24,29 @@ Tests for translation models.
from
__future__
import
print_function
from
unittest
import
SkipTest
import
shutil
import
os
from
django.test
import
TestCase
from
django.conf
import
settings
from
django.utils
import
timezone
from
django.contrib.auth.models
import
Permission
,
User
from
django.core.exceptions
import
ValidationError
from
weblate.trans.formats
import
FILE_FORMATS
from
weblate.trans.models
import
(
Project
,
S
ubProject
,
S
ource
,
Unit
,
WhiteboardMessage
,
Check
,
ComponentList
,
Project
,
Source
,
Unit
,
WhiteboardMessage
,
Check
,
ComponentList
,
get_related_units
,
)
from
weblate
import
appsettings
from
weblate.trans.tests
import
OverrideSettings
from
weblate.trans.tests.utils
import
get_test_file
from
weblate.trans.vcs
import
GitRepository
,
HgRepository
from
weblate.trans.search
import
clean_indexes
from
weblate.trans.tests.utils
import
get_test_file
,
RepoTestMixin
REPOWEB_URL
=
\
'https://github.com/nijel/weblate-test/blob/master/%(file)s#L%(line)s'
GIT_URL
=
'https://github.com/nijel/weblate-test.git'
HG_URL
=
'https://bitbucket.org/nijel/weblate-test'
class
RepoTestCase
(
TestCase
):
class
RepoTestCase
(
TestCase
,
RepoTestMixin
):
"""
Generic class for tests working with repositories.
"""
def
setUp
(
self
):
# Path where to clone remote repo for tests
self
.
git_base_repo_path
=
os
.
path
.
join
(
settings
.
DATA_DIR
,
'test-base-repo.git'
)
# Repository on which tests will be performed
self
.
git_repo_path
=
os
.
path
.
join
(
settings
.
DATA_DIR
,
'test-repo.git'
)
# Path where to clone remote repo for tests
self
.
hg_base_repo_path
=
os
.
path
.
join
(
settings
.
DATA_DIR
,
'test-base-repo.hg'
)
# Repository on which tests will be performed
self
.
hg_repo_path
=
os
.
path
.
join
(
settings
.
DATA_DIR
,
'test-repo.hg'
)
# Clone repo for testing
if
not
os
.
path
.
exists
(
self
.
git_base_repo_path
):
print
(
'Cloning Git test repository to {0}...'
.
format
(
self
.
git_base_repo_path
)
)
GitRepository
.
clone
(
GIT_URL
,
self
.
git_base_repo_path
,
bare
=
True
)
# Remove possibly existing directory
if
os
.
path
.
exists
(
self
.
git_repo_path
):
shutil
.
rmtree
(
self
.
git_repo_path
)
# Create repository copy for the test
shutil
.
copytree
(
self
.
git_base_repo_path
,
self
.
git_repo_path
)
if
HgRepository
.
is_supported
():
# Clone repo for testing
if
not
os
.
path
.
exists
(
self
.
hg_base_repo_path
):
print
(
'Cloning Mercurial test repository to {0}...'
.
format
(
self
.
hg_base_repo_path
)
)
HgRepository
.
clone
(
HG_URL
,
self
.
hg_base_repo_path
,
bare
=
True
)
# Remove possibly existing directory
if
os
.
path
.
exists
(
self
.
hg_repo_path
):
shutil
.
rmtree
(
self
.
hg_repo_path
)
# Create repository copy for the test
shutil
.
copytree
(
self
.
hg_base_repo_path
,
self
.
hg_repo_path
)
# Remove possibly existing project directory
test_repo_path
=
os
.
path
.
join
(
settings
.
DATA_DIR
,
'vcs'
,
'test'
)
if
os
.
path
.
exists
(
test_repo_path
):
shutil
.
rmtree
(
test_repo_path
)
# Remove indexes
clean_indexes
()
def
create_project
(
self
):
"""
Creates test project.
"""
project
=
Project
.
objects
.
create
(
name
=
'Test'
,
slug
=
'test'
,
web
=
'https://weblate.org/'
)
self
.
addCleanup
(
shutil
.
rmtree
,
project
.
get_path
(),
True
)
return
project
def
_create_subproject
(
self
,
file_format
,
mask
,
template
=
''
,
new_base
=
''
,
vcs
=
'git'
,
**
kwargs
):
"""
Creates real test subproject.
"""
project
=
self
.
create_project
()
if
vcs
==
'mercurial'
:
branch
=
'default'
repo
=
self
.
hg_repo_path
push
=
self
.
hg_repo_path
if
not
HgRepository
.
is_supported
():
raise
SkipTest
(
'Mercurial not available!'
)
else
:
branch
=
'master'
repo
=
self
.
git_repo_path
push
=
self
.
git_repo_path
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
,
filemask
=
mask
,
template
=
template
,
file_format
=
file_format
,
repoweb
=
REPOWEB_URL
,
save_history
=
True
,
new_base
=
new_base
,
vcs
=
vcs
,
**
kwargs
)
def
create_subproject
(
self
):
"""
Wrapper method for providing test subproject.
"""
return
self
.
_create_subproject
(
'auto'
,
'po/*.po'
,
)
def
create_po
(
self
):
return
self
.
_create_subproject
(
'po'
,
'po/*.po'
,
)
def
create_po_empty
(
self
):
return
self
.
_create_subproject
(
'po'
,
'po-empty/*.po'
,
new_base
=
'po-empty/hello.pot'
,
new_lang
=
'add'
,
)
def
create_po_mercurial
(
self
):
return
self
.
_create_subproject
(
'po'
,
'po/*.po'
,
vcs
=
'mercurial'
)
def
create_po_new_base
(
self
):
return
self
.
_create_subproject
(
'po'
,
'po/*.po'
,
new_base
=
'po/hello.pot'
)
def
create_po_link
(
self
):
return
self
.
_create_subproject
(
'po'
,
'po-link/*.po'
,
)
def
create_po_mono
(
self
):
return
self
.
_create_subproject
(
'po-mono'
,
'po-mono/*.po'
,
'po-mono/en.po'
,
)
def
create_ts
(
self
,
suffix
=
''
):
return
self
.
_create_subproject
(
'ts'
,
'ts{0}/*.ts'
.
format
(
suffix
),
)
def
create_ts_mono
(
self
):
return
self
.
_create_subproject
(
'ts'
,
'ts-mono/*.ts'
,
'ts-mono/en.ts'
,
)
def
create_iphone
(
self
):
return
self
.
_create_subproject
(
'strings'
,
'iphone/*.lproj/Localizable.strings'
,
)
def
create_android
(
self
):
return
self
.
_create_subproject
(
'aresource'
,
'android/values-*/strings.xml'
,
'android/values/strings.xml'
,
)
def
create_json
(
self
):
return
self
.
_create_subproject
(
'json'
,
'json/*.json'
,
)
def
create_json_mono
(
self
):
return
self
.
_create_subproject
(
'json'
,
'json-mono/*.json'
,
'json-mono/en.json'
,
)
def
create_tsv
(
self
):
return
self
.
_create_subproject
(
'csv'
,
'tsv/*.txt'
,
)
def
create_csv
(
self
):
return
self
.
_create_subproject
(
'csv'
,
'csv/*.txt'
,
)
def
create_csv_mono
(
self
):
return
self
.
_create_subproject
(
'csv'
,
'csv-mono/*.csv'
,
'csv-mono/en.csv'
,
)
def
create_php_mono
(
self
):
return
self
.
_create_subproject
(
'php'
,
'php-mono/*.php'
,
'php-mono/en.php'
,
)
def
create_java
(
self
):
return
self
.
_create_subproject
(
'properties'
,
'java/swing_messages_*.properties'
,
'java/swing_messages.properties'
,
)
def
create_xliff
(
self
,
name
=
'default'
):
return
self
.
_create_subproject
(
'xliff'
,
'xliff/*/%s.xlf'
%
name
,
)
def
create_xliff_mono
(
self
):
return
self
.
_create_subproject
(
'xliff'
,
'xliff-mono/*.xlf'
,
'xliff-mono/en.xlf'
,
)
def
create_resx
(
self
):
if
'resx'
not
in
FILE_FORMATS
:
raise
SkipTest
(
'resx not supported'
)
return
self
.
_create_subproject
(
'resx'
,
'resx/*.resx'
,
'resx/en.resx'
,
)
def
create_link
(
self
):
parent
=
self
.
create_iphone
()
return
SubProject
.
objects
.
create
(
name
=
'Test2'
,
slug
=
'test2'
,
project
=
parent
.
project
,
repo
=
'weblate://test/test'
,
file_format
=
'po'
,
filemask
=
'po/*.po'
,
new_lang
=
'contact'
,
)
self
.
clone_test_repos
()
class
ProjectTest
(
RepoTestCase
):
...
...
weblate/trans/tests/utils.py
View file @
fe4db295
...
...
@@ -19,6 +19,15 @@
#
import
os.path
import
shutil
from
unittest
import
SkipTest
from
django.conf
import
settings
from
weblate.trans.formats
import
FILE_FORMATS
from
weblate.trans.models
import
Project
,
SubProject
from
weblate.trans.search
import
clean_indexes
from
weblate.trans.vcs
import
GitRepository
,
HgRepository
# Directory holding test data
TEST_DATA
=
os
.
path
.
join
(
...
...
@@ -26,9 +35,296 @@ TEST_DATA = os.path.join(
'data'
)
# Upstream location of test repositories
GIT_URL
=
'https://github.com/nijel/weblate-test.git'
HG_URL
=
'https://bitbucket.org/nijel/weblate-test'
REPOWEB_URL
=
\
'https://github.com/nijel/weblate-test/blob/master/%(file)s#L%(line)s'
def
get_test_file
(
name
):
'''
Returns filename of test file.
'''
return
os
.
path
.
join
(
TEST_DATA
,
name
)
class
RepoTestMixin
(
object
):
def
clone_test_repos
(
self
):
# Path where to clone remote repo for tests
self
.
git_base_repo_path
=
os
.
path
.
join
(
settings
.
DATA_DIR
,
'test-base-repo.git'
)
# Repository on which tests will be performed
self
.
git_repo_path
=
os
.
path
.
join
(
settings
.
DATA_DIR
,
'test-repo.git'
)
# Path where to clone remote repo for tests
self
.
hg_base_repo_path
=
os
.
path
.
join
(
settings
.
DATA_DIR
,
'test-base-repo.hg'
)
# Repository on which tests will be performed
self
.
hg_repo_path
=
os
.
path
.
join
(
settings
.
DATA_DIR
,
'test-repo.hg'
)
# Clone repo for testing
if
not
os
.
path
.
exists
(
self
.
git_base_repo_path
):
print
(
'Cloning Git test repository to {0}...'
.
format
(
self
.
git_base_repo_path
)
)
GitRepository
.
clone
(
GIT_URL
,
self
.
git_base_repo_path
,
bare
=
True
)
# Remove possibly existing directory
if
os
.
path
.
exists
(
self
.
git_repo_path
):
shutil
.
rmtree
(
self
.
git_repo_path
)
# Create repository copy for the test
shutil
.
copytree
(
self
.
git_base_repo_path
,
self
.
git_repo_path
)
if
HgRepository
.
is_supported
():
# Clone repo for testing
if
not
os
.
path
.
exists
(
self
.
hg_base_repo_path
):
print
(
'Cloning Mercurial test repository to {0}...'
.
format
(
self
.
hg_base_repo_path
)
)
HgRepository
.
clone
(
HG_URL
,
self
.
hg_base_repo_path
,
bare
=
True
)
# Remove possibly existing directory
if
os
.
path
.
exists
(
self
.
hg_repo_path
):
shutil
.
rmtree
(
self
.
hg_repo_path
)
# Create repository copy for the test
shutil
.
copytree
(
self
.
hg_base_repo_path
,
self
.
hg_repo_path
)
# Remove possibly existing project directory
test_repo_path
=
os
.
path
.
join
(
settings
.
DATA_DIR
,
'vcs'
,
'test'
)
if
os
.
path
.
exists
(
test_repo_path
):
shutil
.
rmtree
(
test_repo_path
)
# Remove indexes
clean_indexes
()
def
create_project
(
self
):
"""
Creates test project.
"""
project
=
Project
.
objects
.
create
(
name
=
'Test'
,
slug
=
'test'
,
web
=
'https://weblate.org/'
)
self
.
addCleanup
(
shutil
.
rmtree
,
project
.
get_path
(),
True
)
return
project
def
_create_subproject
(
self
,
file_format
,
mask
,
template
=
''
,
new_base
=
''
,
vcs
=
'git'
,
**
kwargs
):
"""
Creates real test subproject.
"""
project
=
self
.
create_project
()
if
vcs
==
'mercurial'
:
branch
=
'default'
repo
=
self
.
hg_repo_path
push
=
self
.
hg_repo_path
if
not
HgRepository
.
is_supported
():
raise
SkipTest
(
'Mercurial not available!'
)
else
:
branch
=
'master'
repo
=
self
.
git_repo_path
push
=
self
.
git_repo_path
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
,
filemask
=
mask
,
template
=
template
,
file_format
=
file_format
,
repoweb
=
REPOWEB_URL
,
save_history
=
True
,
new_base
=
new_base
,
vcs
=
vcs
,
**
kwargs
)
def
create_subproject
(
self
):
"""
Wrapper method for providing test subproject.
"""
return
self
.
_create_subproject
(
'auto'
,
'po/*.po'
,
)
def
create_po
(
self
):
return
self
.
_create_subproject
(
'po'
,
'po/*.po'
,
)
def
create_po_empty
(
self
):
return
self
.
_create_subproject
(
'po'
,
'po-empty/*.po'
,
new_base
=
'po-empty/hello.pot'
,
new_lang
=
'add'
,
)
def
create_po_mercurial
(
self
):
return
self
.
_create_subproject
(
'po'
,
'po/*.po'
,
vcs
=
'mercurial'
)
def
create_po_new_base
(
self
):
return
self
.
_create_subproject
(
'po'
,
'po/*.po'
,
new_base
=
'po/hello.pot'
)
def
create_po_link
(
self
):
return
self
.
_create_subproject
(
'po'
,
'po-link/*.po'
,
)
def
create_po_mono
(
self
):
return
self
.
_create_subproject
(
'po-mono'
,
'po-mono/*.po'
,
'po-mono/en.po'
,
)
def
create_ts
(
self
,
suffix
=
''
):
return
self
.
_create_subproject
(
'ts'
,
'ts{0}/*.ts'
.
format
(
suffix
),
)
def
create_ts_mono
(
self
):
return
self
.
_create_subproject
(
'ts'
,
'ts-mono/*.ts'
,
'ts-mono/en.ts'
,
)
def
create_iphone
(
self
):
return
self
.
_create_subproject
(
'strings'
,
'iphone/*.lproj/Localizable.strings'
,
)
def
create_android
(
self
):
return
self
.
_create_subproject
(
'aresource'
,
'android/values-*/strings.xml'
,
'android/values/strings.xml'
,
)
def
create_json
(
self
):
return
self
.
_create_subproject
(
'json'
,
'json/*.json'
,
)
def
create_json_mono
(
self
):
return
self
.
_create_subproject
(
'json'
,
'json-mono/*.json'
,
'json-mono/en.json'
,
)
def
create_tsv
(
self
):
return
self
.
_create_subproject
(
'csv'
,
'tsv/*.txt'
,
)
def
create_csv
(
self
):
return
self
.
_create_subproject
(
'csv'
,
'csv/*.txt'
,
)
def
create_csv_mono
(
self
):
return
self
.
_create_subproject
(
'csv'
,
'csv-mono/*.csv'
,
'csv-mono/en.csv'
,
)
def
create_php_mono
(
self
):
return
self
.
_create_subproject
(
'php'
,
'php-mono/*.php'
,
'php-mono/en.php'
,
)
def
create_java
(
self
):
return
self
.
_create_subproject
(
'properties'
,
'java/swing_messages_*.properties'
,
'java/swing_messages.properties'
,
)
def
create_xliff
(
self
,
name
=
'default'
):
return
self
.
_create_subproject
(
'xliff'
,
'xliff/*/%s.xlf'
%
name
,
)
def
create_xliff_mono
(
self
):
return
self
.
_create_subproject
(
'xliff'
,
'xliff-mono/*.xlf'
,
'xliff-mono/en.xlf'
,
)
def
create_resx
(
self
):
if
'resx'
not
in
FILE_FORMATS
:
raise
SkipTest
(
'resx not supported'
)
return
self
.
_create_subproject
(
'resx'
,
'resx/*.resx'
,
'resx/en.resx'
,
)
def
create_link
(
self
):
parent
=
self
.
create_iphone
()
return
SubProject
.
objects
.
create
(
name
=
'Test2'
,
slug
=
'test2'
,
project
=
parent
.
project
,
repo
=
'weblate://test/test'
,
file_format
=
'po'
,
filemask
=
'po/*.po'
,
new_lang
=
'contact'
,
)
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