Ejemplo n.º 1
0
def test_util_tag_tool_iter_locales(locale_mock, latest_mock, stats_mock):
    tag_tool = TagTool(TagsTool(),
                       name=None,
                       pk=None,
                       priority=None,
                       project=None,
                       slug=None)

    # Set mocks
    locale_mock.return_value = "X"
    latest_mock.configure_mock(**{'return_value.get.return_value': 23})
    stats_mock.return_value = [
        dict(foo=1, locale=1),
        dict(foo=2, locale=2),
        dict(foo=3, locale=3)
    ]

    # iter_locales - should generate 3 of 'X'
    locales = tag_tool.iter_locales()
    assert isinstance(locales, types.GeneratorType)
    assert list(locales) == ['X'] * 3
    assert len(locale_mock.call_args_list) == 3
    assert stats_mock.called

    # locale_latest is called with each of the locales
    assert (list(list(a)
                 for a in latest_mock.return_value.get.call_args_list) == [[
                     (1, ), {}
                 ], [(2, ), {}], [(3, ), {}]])

    # TaggedLocale is called with locale data
    for i, args in enumerate(locale_mock.call_args_list):
        assert args[1]['foo'] == i + 1
        assert args[1]['latest_translation'] == 23
Ejemplo n.º 2
0
def test_util_tag_tool_iter_locales(locale_mock, latest_mock, stats_mock):
    tag_tool = TagTool(
        TagsTool(),
        name=None,
        pk=None,
        priority=None,
        project=None,
        slug=None)

    # Set mocks
    locale_mock.return_value = "X"
    latest_mock.configure_mock(
        **{'return_value.get.return_value': 23})
    stats_mock.return_value = [
        dict(foo=1, locale=1),
        dict(foo=2, locale=2),
        dict(foo=3, locale=3)]

    # iter_locales - should generate 3 of 'X'
    locales = tag_tool.iter_locales()
    assert isinstance(locales, types.GeneratorType)
    assert list(locales) == ['X'] * 3
    assert len(locale_mock.call_args_list) == 3
    assert stats_mock.called

    # locale_latest is called with each of the locales
    assert (
        list(list(a) for a in latest_mock.return_value.get.call_args_list)
        == [[(1,), {}], [(2,), {}], [(3,), {}]])

    # TaggedLocale is called with locale data
    for i, args in enumerate(locale_mock.call_args_list):
        assert args[1]['foo'] == i + 1
        assert args[1]['latest_translation'] == 23
Ejemplo n.º 3
0
def test_util_tag_tool_link_resources(resources_mock):
    tag_tool = TagTool(
        TagsTool(), name=None, pk=None, priority=None, project=None, slug=7
    )
    resources_mock.configure_mock(**{"return_value.link.return_value": 23})

    # link_resources returns resources.link()
    assert tag_tool.link_resources(13) == 23

    # resources.link() is called with correct args
    assert list(resources_mock.return_value.link.call_args) == [(7,), {"resources": 13}]
Ejemplo n.º 4
0
def test_util_tag_tool_linked_resources(resources_mock):
    tag_tool = TagTool(TagsTool(),
                       name=None,
                       pk=None,
                       priority=None,
                       project=None,
                       slug=7)
    resources_mock.configure_mock(
        **{
            'return_value.get_linked_resources'
            '.return_value.order_by.return_value':
            23
        })

    # linked_resources returns
    # resources.get_linked_resources().order_by()
    assert tag_tool.linked_resources == 23

    # get_linked_resources was called with slug
    linked_resources_mock = resources_mock.return_value.get_linked_resources
    assert (list(linked_resources_mock.call_args) == [(7, ), {}])

    # order_by is called with 'path'
    order_by_mock = linked_resources_mock.return_value.order_by
    assert (list(order_by_mock.call_args) == [('path', ), {}])
Ejemplo n.º 5
0
def test_util_tag_tool_locale_latest(trans_mock):
    trans_mock.configure_mock(**{"return_value.data": 23})
    tag_tool = TagTool(
        TagsTool(), name=None, pk=None, priority=None, project=None, slug=17
    )
    assert tag_tool.locale_latest == 23
    assert list(trans_mock.call_args) == [(), {"groupby": "locale", "slug": 17}]
Ejemplo n.º 6
0
def test_util_tag_tool_resource_tool(resources_mock):
    tool_mock = MagicMock(return_value=23)
    resources_mock.return_value = tool_mock
    tag_tool = TagTool(
        TagsTool(), name=None, pk=None, priority=None, project=None, slug=None
    )

    # no project set - returns the tags.resources_tool, but doesnt call it
    assert tag_tool.resource_tool is tool_mock
    assert not tool_mock.called

    # project set
    tag_tool = TagTool(
        TagsTool(), name=None, pk=None, priority=None, project=43, slug=None
    )
    # tool was called with project as args
    assert tag_tool.resource_tool == 23
    assert list(tool_mock.call_args) == [(), {"projects": [43]}]
Ejemplo n.º 7
0
def test_util_tag_tool_unlink_resources(resources_mock):
    tag_tool = TagTool(
        TagsTool(),
        name=None,
        pk=None,
        priority=None,
        project=None,
        slug=7)
    resources_mock.configure_mock(
        **{'return_value.unlink.return_value': 23})

    # unlink_resources returns resources.unlink()
    assert tag_tool.unlink_resources(13) == 23

    # resources.unlink() is called with correct args
    assert (
        list(resources_mock.return_value.unlink.call_args)
        == [(7,), {'resources': 13}])
Ejemplo n.º 8
0
def test_util_tag_tool_locale_stats(stats_mock):
    stats_mock.configure_mock(**{"return_value.data": 23})
    tag_tool = TagTool(
        TagsTool(), name=None, pk=None, priority=None, project=None, slug=7
    )

    # locale_stats returns self.tags_tool.stats_tool().data
    assert tag_tool.locale_stats == 23

    # stats_tool was called with slug and groupby
    assert list(stats_mock.call_args) == [(), {"groupby": "locale", "slug": 7}]
Ejemplo n.º 9
0
def test_util_tag_tool_locale_latest(trans_mock):
    trans_mock.configure_mock(**{'return_value.data': 23})
    tag_tool = TagTool(TagsTool(),
                       name=None,
                       pk=None,
                       priority=None,
                       project=None,
                       slug=17)
    assert tag_tool.locale_latest == 23
    assert (list(trans_mock.call_args) == [(), {
        'groupby': 'locale',
        'slug': 17
    }])
Ejemplo n.º 10
0
def test_util_tag_tool_object(tag_mock):
    tag_mock.configure_mock(
        **{"return_value.select_related" ".return_value.get.return_value": 23}
    )
    tag_tool = TagTool(
        TagsTool(), name=None, pk=13, priority=None, project=None, slug=7
    )

    # object returns tag_manager.select_related().get()
    assert tag_tool.object == 23

    # tag_manager.select_related().get() is called with the tag pk
    assert list(tag_mock.return_value.select_related.return_value.get.call_args) == [
        (),
        {"pk": 13},
    ]
Ejemplo n.º 11
0
def test_util_tag_tool_init(kwargs):
    # Test the TagTool can be instantiated with/out args
    tags_tool = TagTool(**kwargs)
    for k, v in kwargs.items():
        assert getattr(tags_tool, k) == v