Skip to content

Commit

Permalink
Merge pull request #221 from praekeltfoundation/add-all-language-import
Browse files Browse the repository at this point in the history
Add empty value on content import form
  • Loading branch information
rudigiesler authored Dec 20, 2023
2 parents 2abfa2b + 62b891c commit ec752a9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion home/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class UploadContentFileForm(UploadFileForm):
YES_NO = ((False, "No"), (True, "Yes"))
purge = forms.ChoiceField(choices=YES_NO)
locale = forms.ModelChoiceField(
queryset=Locale.objects.all(), empty_label="Select Locale"
queryset=Locale.objects.all(),
empty_label="Import all languages",
required=False,
)


Expand Down
29 changes: 29 additions & 0 deletions home/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest
from django.core.files.uploadedfile import SimpleUploadedFile

from home.forms import UploadContentFileForm


class TestUploadContentFileForm:
@pytest.mark.django_db
def test_empty_locale_label(self):
"""
The label for the empty locale option should be Import all languages
"""
assert "Import all languages" in UploadContentFileForm().render()

def test_default_locale(self):
"""
Not supplying a locale should give a default "None" value, which the importer
interprets as we should import all locales found in the file
"""
file = SimpleUploadedFile(
name="test.csv", content=b"foo,bar", content_type="text/csv"
)
form = UploadContentFileForm(
files={"file": file},
data={"file_type": "CSV", "purge": "False", "locale": ""},
)

assert form.errors == {}
assert form.cleaned_data["locale"] is None
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ exclude = [ # Regexes.
'^home/tests/test_(management|management_related_tag|models)\.py',
'^home/tests/test_(unique_slug_hook|views|wagtail_hooks)\.py',
'^home/tests/test_(whatsapp|whatsapp_template_name_migration)\.py',
'^home/tests/test_(forms)\.py',
]
files = "."
follow_imports = "skip"
Expand Down

0 comments on commit ec752a9

Please sign in to comment.