コード例 #1
0
ファイル: test_tags.py プロジェクト: seferov/pontoon
def test_util_tags_tool_iter_tags(tag_mock, trans_mock):
    # tests that iter_tags calls instantiates a TagTool with
    # stat data and latest_translation data

    trans_mock.configure_mock(
        **{'return_value.data.get.return_value': 23})
    tags_tool = TagsTool()
    list(
        tags_tool.iter_tags(
            [dict(resource__tag=1, foo="bar"),
             dict(resource__tag=2, foo="bar"),
             dict(resource__tag=3, foo="bar")]))

    # translation_tool.data.get() was called 3 times with tag pks
    assert (
        [x[0][0] for x in trans_mock.return_value.data.get.call_args_list]
        == [1, 2, 3])

    # TagTool was called 3 times with the tags tool as arg
    assert (
        [x[0][0] for x in tag_mock.call_args_list]
        == [tags_tool] * 3)

    # and stat + translation data as kwargs
    assert (
        [x[1] for x in tag_mock.call_args_list]
        == [{'resource__tag': 1, 'latest_translation': 23, 'foo': 'bar'},
            {'resource__tag': 2, 'latest_translation': 23, 'foo': 'bar'},
            {'resource__tag': 3, 'latest_translation': 23, 'foo': 'bar'}])
コード例 #2
0
ファイル: test_tags.py プロジェクト: Pike/pontoon
def test_util_tags_tool_iter_tags(tag_mock, trans_mock):
    # tests that iter_tags calls instantiates a TagTool with
    # stat data and latest_translation data

    trans_mock.configure_mock(
        **{'return_value.data.get.return_value': 23})
    tags_tool = TagsTool()
    list(
        tags_tool.iter_tags(
            [dict(resource__tag=1, foo="bar"),
             dict(resource__tag=2, foo="bar"),
             dict(resource__tag=3, foo="bar")]))

    # translation_tool.data.get() was called 3 times with tag pks
    assert (
        [x[0][0] for x in trans_mock.return_value.data.get.call_args_list]
        == [1, 2, 3])

    # TagTool was called 3 times with the tags tool as arg
    assert (
        [x[0][0] for x in tag_mock.call_args_list]
        == [tags_tool] * 3)

    # and stat + translation data as kwargs
    assert (
        [x[1] for x in tag_mock.call_args_list]
        == [{'resource__tag': 1, 'latest_translation': 23, 'foo': 'bar'},
            {'resource__tag': 2, 'latest_translation': 23, 'foo': 'bar'},
            {'resource__tag': 3, 'latest_translation': 23, 'foo': 'bar'}])
コード例 #3
0
ファイル: test_tags.py プロジェクト: zhoumo01/pontoon
def test_util_tags_tool_iter_tags(tag_mock, trans_mock):
    # tests that iter_tags calls instantiates a TagTool with
    # stat data and latest_translation data

    trans_mock.configure_mock(**{"return_value.data.get.return_value": 23})
    tags_tool = TagsTool()
    list(
        tags_tool.iter_tags([
            dict(resource__tag=1, foo="bar"),
            dict(resource__tag=2, foo="bar"),
            dict(resource__tag=3, foo="bar"),
        ]))

    # translation_tool.data.get() was called 3 times with tag pks
    assert [x[0][0]
            for x in trans_mock.return_value.data.get.call_args_list] == [
                1,
                2,
                3,
            ]

    # TagTool was called 3 times with the tags tool as arg
    assert [x[0][0] for x in tag_mock.call_args_list] == [tags_tool] * 3

    # and stat + translation data as kwargs
    assert [x[1] for x in tag_mock.call_args_list] == [
        {
            "resource__tag": 1,
            "latest_translation": 23,
            "foo": "bar"
        },
        {
            "resource__tag": 2,
            "latest_translation": 23,
            "foo": "bar"
        },
        {
            "resource__tag": 3,
            "latest_translation": 23,
            "foo": "bar"
        },
    ]