Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
7aa1c1c2
Commit
7aa1c1c2
authored
May 18, 2016
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for the new commands
parent
f88181ac
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
139 additions
and
12 deletions
+139
-12
pavelib/i18n.py
+5
-12
pavelib/paver_tests/test_i18n.py
+134
-0
No files found.
pavelib/i18n.py
View file @
7aa1c1c2
...
@@ -244,9 +244,6 @@ def i18n_release_push():
...
@@ -244,9 +244,6 @@ def i18n_release_push():
Push release-specific resources to Transifex.
Push release-specific resources to Transifex.
"""
"""
resources
=
find_release_resources
()
resources
=
find_release_resources
()
if
resources
is
None
:
return
sh
(
"i18n_tool transifex push "
+
" "
.
join
(
resources
))
sh
(
"i18n_tool transifex push "
+
" "
.
join
(
resources
))
...
@@ -259,9 +256,6 @@ def i18n_release_pull():
...
@@ -259,9 +256,6 @@ def i18n_release_pull():
Pull release-specific translations from Transifex.
Pull release-specific translations from Transifex.
"""
"""
resources
=
find_release_resources
()
resources
=
find_release_resources
()
if
resources
is
None
:
return
sh
(
"i18n_tool transifex pull "
+
" "
.
join
(
resources
))
sh
(
"i18n_tool transifex pull "
+
" "
.
join
(
resources
))
...
@@ -273,7 +267,8 @@ def find_release_resources():
...
@@ -273,7 +267,8 @@ def find_release_resources():
two resources defined named "release-*". Check that this is true. If
two resources defined named "release-*". Check that this is true. If
there's a problem, print messages about it.
there's a problem, print messages about it.
Returns a list of resource names, or None if the file doesn't validate.
Returns a list of resource names, or raises ValueError if .tx/config
doesn't have two resources.
"""
"""
# An entry in .tx/config for a release will look like this:
# An entry in .tx/config for a release will look like this:
...
@@ -298,9 +293,7 @@ def find_release_resources():
...
@@ -298,9 +293,7 @@ def find_release_resources():
return
resources
return
resources
if
len
(
resources
)
==
0
:
if
len
(
resources
)
==
0
:
print
"You need two release-* resources defined to use this command."
raise
ValueError
(
"You need two release-* resources defined to use this command."
)
else
:
else
:
print
"Strange Transifex config! Found these release-* resources:"
msg
=
"Strange Transifex config! Found these release-* resources:
\n
"
+
"
\n
"
.
join
(
resources
)
print
"
\n
"
.
join
(
resources
)
raise
ValueError
(
msg
)
return
None
pavelib/paver_tests/test_i18n.py
0 → 100644
View file @
7aa1c1c2
"""
Tests for pavelib/i18n.py.
"""
import
textwrap
import
unittest
from
mock
import
mock_open
,
patch
from
paver.easy
import
task
import
pavelib.i18n
from
pavelib.paver_tests.utils
import
PaverTestCase
TX_CONFIG_SIMPLE
=
"""
\
[main]
host = https://www.transifex.com
[edx-platform.django-partial]
file_filter = conf/locale/<lang>/LC_MESSAGES/django-partial.po
source_file = conf/locale/en/LC_MESSAGES/django-partial.po
source_lang = en
type = PO
[edx-platform.django-studio]
file_filter = conf/locale/<lang>/LC_MESSAGES/django-studio.po
source_file = conf/locale/en/LC_MESSAGES/django-studio.po
source_lang = en
type = PO
"""
TX_CONFIG_RELEASE
=
TX_CONFIG_SIMPLE
+
"""
\
[edx-platform.release-zebrawood]
file_filter = conf/locale/<lang>/LC_MESSAGES/django.po
source_file = conf/locale/en/LC_MESSAGES/django.po
source_lang = en
type = PO
[edx-platform.release-zebrawood-js]
file_filter = conf/locale/<lang>/LC_MESSAGES/djangojs.po
source_file = conf/locale/en/LC_MESSAGES/djangojs.po
source_lang = en
type = PO
"""
def
mocked_i18n_open
(
*
content
):
"""
Helper decorator to mock open() in pavelib.i18n.
Arguments:
content (str): any number of strings, which are dedented, then
concatenated, and then returned as f.read() when pavelib.i18n opens
a file.
"""
read_data
=
""
.
join
(
textwrap
.
dedent
(
c
)
for
c
in
content
)
return
patch
.
object
(
pavelib
.
i18n
,
'open'
,
create
=
True
,
new
=
mock_open
(
read_data
=
read_data
))
@task
def
do_nothing
():
"""
Don't do anything, for replacing prerequisite tasks we want to skip.
"""
pass
class
FindReleaseResourcesTest
(
unittest
.
TestCase
):
"""
Tests of pavelib/i18n.py:find_release_resources.
"""
@mocked_i18n_open
(
TX_CONFIG_SIMPLE
)
def
test_no_resources
(
self
):
errmsg
=
r"You need two release-\* resources defined to use this command."
with
self
.
assertRaisesRegexp
(
ValueError
,
errmsg
):
pavelib
.
i18n
.
find_release_resources
()
@mocked_i18n_open
(
TX_CONFIG_SIMPLE
,
"""
\
[edx-platform.release-zebrawood]
file_filter = conf/locale/<lang>/LC_MESSAGES/django.po
source_file = conf/locale/en/LC_MESSAGES/django.po
source_lang = en
type = PO
"""
)
def
test_one_resource
(
self
):
errmsg
=
r"Strange Transifex config! Found these release-\* resources:\nedx-platform.release-zebrawood"
with
self
.
assertRaisesRegexp
(
ValueError
,
errmsg
):
pavelib
.
i18n
.
find_release_resources
()
@mocked_i18n_open
(
TX_CONFIG_RELEASE
)
def
test_good_resources
(
self
):
self
.
assertEqual
(
pavelib
.
i18n
.
find_release_resources
(),
[
'edx-platform.release-zebrawood'
,
'edx-platform.release-zebrawood-js'
],
)
class
ReleasePushPullTest
(
PaverTestCase
):
"""
Tests of i18n_release_push and i18n_release_pull.
"""
@mocked_i18n_open
(
TX_CONFIG_SIMPLE
)
@patch.object
(
pavelib
.
i18n
,
'i18n_generate'
,
new
=
do_nothing
)
def
test_cant_push_nothing
(
self
):
with
self
.
assertRaises
(
SystemExit
)
as
sysex
:
pavelib
.
i18n
.
i18n_release_push
()
# Check that we exited with a failure status code.
self
.
assertEqual
(
sysex
.
exception
.
args
,
(
1
,))
@mocked_i18n_open
(
TX_CONFIG_SIMPLE
)
def
test_cant_pull_nothing
(
self
):
with
self
.
assertRaises
(
SystemExit
)
as
sysex
:
pavelib
.
i18n
.
i18n_release_pull
()
# Check that we exited with a failure status code.
self
.
assertEqual
(
sysex
.
exception
.
args
,
(
1
,))
@mocked_i18n_open
(
TX_CONFIG_RELEASE
)
@patch.object
(
pavelib
.
i18n
,
'i18n_generate'
,
new
=
do_nothing
)
@patch.object
(
pavelib
.
i18n
,
'sh'
)
def
test_can_push_release
(
self
,
mock_sh
):
pavelib
.
i18n
.
i18n_release_push
()
mock_sh
.
assert_called_once_with
(
'i18n_tool transifex push edx-platform.release-zebrawood edx-platform.release-zebrawood-js'
)
@mocked_i18n_open
(
TX_CONFIG_RELEASE
)
@patch.object
(
pavelib
.
i18n
,
'sh'
)
def
test_can_pull_release
(
self
,
mock_sh
):
pavelib
.
i18n
.
i18n_release_pull
()
mock_sh
.
assert_called_once_with
(
'i18n_tool transifex pull edx-platform.release-zebrawood edx-platform.release-zebrawood-js'
)
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