Skip to content

Commit

Permalink
Removed test code, cleaned up CSS & added skips for tests unless `APP…
Browse files Browse the repository at this point in the history
…LICATION_TRANSLATIONS_ENABLED` is true
  • Loading branch information
wes-otf committed Nov 18, 2024
1 parent 2d7a54d commit a9c1299
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 38 deletions.
4 changes: 0 additions & 4 deletions hypha/apply/funds/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import nh3
from django import forms
from django.conf import settings
from django.db.models import Q
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
Expand All @@ -25,9 +24,6 @@
from .widgets import MetaTermSelect2Widget, Select2MultiCheckboxesWidget
from .workflow import get_action_mapping

if settings.APPLICATION_TRANSLATIONS_ENABLED:
pass


class ApplicationSubmissionModelForm(forms.ModelForm):
"""
Expand Down
44 changes: 18 additions & 26 deletions hypha/apply/funds/templates/funds/includes/rendered_answers.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
{% load i18n wagtailusers_tags workflow_tags translate_tags heroicons %}
{% if request.user|can_translate_submission and from_lang_name and to_lang_name %}
<div class="w-full text-center my-2 py-5 border rounded-lg shadow-md">
<span>
{% heroicon_outline "language" aria_hidden="true" size=15 stroke_width=2 class="inline align-baseline me-1" %}
{% blocktrans %} This application is translated from {{from_lang_name}} to {{to_lang_name}}. {% endblocktrans %}
<a href="{% url 'funds:submissions:detail' object.id %}">
{% trans "See original" %}
</a>
</span>
</div>
{% else %}
<div id="translate-card-loading" class="w-full text-center my-2 py-5 border rounded-lg shadow-md animate-pulse htmx-indicator">
<span class="w-full bg-gray-200 rounded-lg"></span>
</div>
{% if request.user|can_translate_submission %}
{% if from_lang_name and to_lang_name %}
{# For active translations #}
<div class="w-full text-center my-2 py-5 border rounded-lg shadow-md">
<span>
{% heroicon_outline "language" aria_hidden="true" size=15 stroke_width=2 class="inline align-baseline me-1" %}
{% blocktrans %} This application is translated from {{from_lang_name}} to {{to_lang_name}}. {% endblocktrans %}
<a href="{% url 'funds:submissions:detail' object.id %}">
{% trans "See original" %}
</a>
</span>
</div>
{% else %}
{# For a translation loading indicator #}
<div id="translate-card-loading" class="w-full text-center h-0 m-0 p-0 overflow-hidden content-center rounded-lg shadow-md animate-pulse htmx-indicator">
<span class="w-[490px] bg-gray-200 rounded-lg"></span>
</div>
{% endif %}
{% endif %}
<h3 class="text-xl border-b pb-2 font-bold">{% trans "Proposal Information" %}</h3>
<div class="hypha-grid hypha-grid--proposal-info">
Expand Down Expand Up @@ -60,18 +64,6 @@ <h5 class="text-base">{% trans "Organization name" %}</h5>
</div>

<style type="text/css">
#translate-card-loading span {
width: 490px;
}

#translate-card-loading.htmx-indicator{
height: 0;
margin: 0;
padding: 0;
overflow: hidden;
align-content: center;
border-width: 0px;
}
#translate-card-loading.htmx-request.htmx-indicator{
height: 64px;
transition: height 0.25s ease-in;
Expand Down
9 changes: 8 additions & 1 deletion hypha/apply/translate/tests/test_translate.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from typing import List
from unittest import skipUnless
from unittest.mock import Mock, patch

from django.conf import settings
from django.test import SimpleTestCase

from hypha.apply.translate.translate import translate
if settings.APPLICATION_TRANSLATIONS_ENABLED:
from hypha.apply.translate.translate import translate


@skipUnless(
settings.APPLICATION_TRANSLATIONS_ENABLED,
"Attempts to import translate dependencies",
)
class TestTranslate(SimpleTestCase):
@staticmethod
def mocked_translate(string: str, from_code, to_code):
Expand Down
38 changes: 31 additions & 7 deletions hypha/apply/translate/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
import json
from typing import Optional
from unittest import skipUnless
from unittest.mock import Mock, patch
from urllib.parse import parse_qs, urlparse

from django.conf import settings
from django.http import QueryDict
from django.test import RequestFactory, SimpleTestCase, TestCase, override_settings

from hypha.apply.funds.tests.factories import ApplicationSubmissionFactory
from hypha.apply.translate.utils import (
get_available_translations,
get_lang_name,
get_language_choices_json,
get_translation_params,
translate_application_form_data,
)
from hypha.apply.users.tests.factories import ApplicantFactory

if settings.APPLICATION_TRANSLATIONS_ENABLED:
from hypha.apply.translate.utils import (
get_available_translations,
get_lang_name,
get_language_choices_json,
get_translation_params,
translate_application_form_data,
)


@skipUnless(
settings.APPLICATION_TRANSLATIONS_ENABLED,
"Attempts to import translate dependencies",
)
class TesGetAvailableTranslations(SimpleTestCase):
@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -54,6 +62,10 @@ def test_get_available_translations_with_codes(self):
self.assertEqual(codes, {("en", "ar"), ("zh", "en")})


@skipUnless(
settings.APPLICATION_TRANSLATIONS_ENABLED,
"Attempts to import translate dependencies",
)
class TestGetTranslationParams(SimpleTestCase):
def get_test_get_request(self, extra_params: Optional[str] = None) -> Mock:
extra_params = f"{extra_params}&" if extra_params else ""
Expand Down Expand Up @@ -99,6 +111,10 @@ def test_get_translation_params_with_invalid_params(self):
self.assertIsNone(get_translation_params(url=url))


@skipUnless(
settings.APPLICATION_TRANSLATIONS_ENABLED,
"Attempts to import translate dependencies",
)
class TestGetLangName(SimpleTestCase):
def test_get_lang_name(self):
# "!" added to ensure mock is working rather than actually calling argos
Expand All @@ -122,6 +138,10 @@ def test_get_lang_name_invalid_code(self):
from_code_mock.assert_called_once_with("nope")


@skipUnless(
settings.APPLICATION_TRANSLATIONS_ENABLED,
"Attempts to import translate dependencies",
)
class TestTranslateSubmissionFormData(TestCase):
@staticmethod
def mocked_translate(string: str, from_code, to_code):
Expand Down Expand Up @@ -262,6 +282,10 @@ def equal_ignore_order(a: list, b: list) -> bool:
return not unmatched


@skipUnless(
settings.APPLICATION_TRANSLATIONS_ENABLED,
"Attempts to import translate dependencies",
)
class TestGetLanguageChoices(SimpleTestCase):
@staticmethod
def mocked_get_lang_name(code):
Expand Down

0 comments on commit a9c1299

Please sign in to comment.