Skip to content

Commit

Permalink
Merge e31b003 into bb53ec0
Browse files Browse the repository at this point in the history
  • Loading branch information
phlax committed Apr 5, 2018
2 parents bb53ec0 + e31b003 commit ff3b6fe
Showing 1 changed file with 78 additions and 15 deletions.
93 changes: 78 additions & 15 deletions tests/commands/update_stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,93 @@
# or later license. See the LICENSE file for a copy of the license and the
# AUTHORS file for copyright and authorship information.

from mock import PropertyMock, patch

import pytest

from django.core.management import CommandError, call_command

from pootle_project.models import Project
from pootle_app.management.commands.update_stores import Command


DEFAULT_OPTIONS = {
'force': False,
'settings': None,
'pythonpath': None,
'verbosity': 3,
'traceback': False,
u'skip_checks': True,
'no_rq': False,
'atomic': 'tp',
'noinput': False,
'overwrite': False,
'no_color': False}


@pytest.mark.cmd
@pytest.mark.django_db
def test_update_stores_noargs(capfd, tmpdir):
@patch('pootle_app.management.commands.PootleCommand.handle_all')
@patch(
'pootle_app.management.commands.update_stores.Project.objects',
new_callable=PropertyMock)
@patch(
'pootle_app.management.commands.update_stores.Command._create_tps_for_project')
@patch(
'pootle_app.management.commands.update_stores.Command.check_projects')
def test_update_stores_noargs(check_projects, create_mock, project_mock,
command_mock, capfd):
"""Site wide update_stores"""
for project in Project.objects.all():
fs_url = tmpdir.mkdir(project.code)
project.config["pootle_fs.fs_url"] = str(fs_url)
project_mock.configure_mock(
**{"return_value.all.return_value.iterator.return_value": [1, 2, 3],
"return_value.filter.return_value.iterator.return_value": [4, 5, 6]})
command_mock.return_value = 23
call_command('update_stores', '-v3')
out, err = capfd.readouterr()
# Store and Unit are deleted as there are no files on disk
# SO - Store Obsolete
assert 'system\tSO\t/language0/project0/store0.po' in err

# Repeat and we should have zero output
call_command('update_stores', "-v3")
out, err = capfd.readouterr()
assert 'system\tSO' not in err

assert (
[list(l) for l in create_mock.call_args_list]
== [[(1,), {}], [(2,), {}], [(3,), {}]])

assert (
list(command_mock.call_args)
== [(), DEFAULT_OPTIONS])

create_mock.reset_mock()
command_mock.reset_mock()

call_command('update_stores', '-v3', '--project', '7', '--project', '23')
assert (
list(check_projects.call_args)
== [([u'7', u'23'],), {}])
assert (
[list(l) for l in create_mock.call_args_list]
== [[(4,), {}], [(5,), {}], [(6,), {}]])
assert (
list(command_mock.call_args)
== [(), DEFAULT_OPTIONS])


@pytest.mark.cmd
@patch('pootle_app.management.commands.update_stores.FSPlugin')
def test_update_stores_tp(plugin_mock):
"""Site wide update_stores"""
command = Command()
tp = PropertyMock()
tp.configure_mock(
**{'pootle_path': 'FOO',
'project': 23})
command.handle_translation_project(tp, **DEFAULT_OPTIONS)
assert (
list(plugin_mock.return_value.add.call_args)
== [(), {'pootle_path': 'FOO*', 'update': 'pootle'}])
assert (
list(plugin_mock.return_value.rm.call_args)
== [(), {'pootle_path': 'FOO*', 'update': 'pootle'}])
assert (
list(plugin_mock.return_value.resolve.call_args)
== [(), {'pootle_path': 'FOO*', 'merge': True}])
assert (
list(plugin_mock.return_value.sync.call_args)
== [(), {'pootle_path': 'FOO*', 'update': 'pootle'}])
assert list(plugin_mock.call_args) == [(23,), {}]


@pytest.mark.cmd
Expand Down

0 comments on commit ff3b6fe

Please sign in to comment.