Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
mathjazz committed Feb 20, 2024
1 parent cb49997 commit c241caf
Show file tree
Hide file tree
Showing 15 changed files with 5 additions and 1,176 deletions.
9 changes: 2 additions & 7 deletions pontoon/tags/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.urls import reverse

from pontoon.base.models import Priority
from pontoon.tags.utils import TagTool


@pytest.mark.django_db
Expand Down Expand Up @@ -144,14 +143,11 @@ def test_view_project_tag_locales(client, project_a, tag_a):
)

# tag is not associated with project
project_a.tag_set.remove(tag_a)
response = client.get(url)
assert response.status_code == 404

# tag has no priority so still wont show up...
project_a.tag_set.add(tag_a)
response = client.get(url)
assert response.status_code == 404

tag_a.priority = Priority.NORMAL
tag_a.save()
response = client.get(url)
Expand All @@ -165,8 +161,7 @@ def test_view_project_tag_locales(client, project_a, tag_a):
assert response.context_data["project"] == project_a

res_tag = response.context_data["tag"]
assert isinstance(res_tag, TagTool)
assert res_tag.object == tag_a
assert res_tag == tag_a


@pytest.mark.django_db
Expand Down
195 changes: 0 additions & 195 deletions pontoon/tags/tests/utils/test_stats.py

This file was deleted.

90 changes: 0 additions & 90 deletions pontoon/tags/tests/utils/test_tag.py
Original file line number Diff line number Diff line change
@@ -1,88 +1,8 @@
import types
from unittest.mock import patch, MagicMock, PropertyMock

import pytest

from pontoon.tags.utils import TagsTool, TagTool


@pytest.mark.parametrize(
"kwargs",
[
dict(
tags_tool=None, name=None, pk=None, priority=None, project=None, slug=None
),
dict(
tags_tool=1,
name=2,
pk=3,
priority=4,
project=5,
slug=6,
latest_translation=7,
total_strings=8,
approved_strings=9,
),
],
)
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


@patch("pontoon.tags.utils.tags.TagsTool.stat_tool", new_callable=PropertyMock())
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}]


@patch("pontoon.tags.utils.tag.TagTool.locale_stats", new_callable=PropertyMock)
@patch("pontoon.tags.utils.tag.TagTool.locale_latest", new_callable=PropertyMock)
@patch("pontoon.tags.utils.tag.TaggedLocale")
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


@patch("pontoon.tags.utils.TagTool.resource_tool", new_callable=PropertyMock)
def test_util_tag_tool_linked_resources(resources_mock):
tag_tool = TagTool(
Expand Down Expand Up @@ -202,13 +122,3 @@ def test_util_tag_tool_resource_tool(resources_mock):
# tool was called with project as args
assert tag_tool.resource_tool == 23
assert list(tool_mock.call_args) == [(), {"projects": [43]}]


@patch("pontoon.tags.utils.TagsTool.translation_tool")
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}]
Loading

0 comments on commit c241caf

Please sign in to comment.