[damned-lies: 2/4] Test team mailing list inside the form
- From: Guillaume Bernard <gbernard src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies: 2/4] Test team mailing list inside the form
- Date: Thu, 8 Sep 2022 08:53:53 +0000 (UTC)
commit 4fe383a07a913b3e2f9842137a17c0d4bc22ddb1
Author: Claude Paroz <claude 2xlibre net>
Date: Wed Sep 7 19:33:59 2022 +0200
Test team mailing list inside the form
vertimus/forms.py | 5 ++++-
vertimus/tests/tests.py | 20 ++++++++++----------
vertimus/views.py | 5 ++---
3 files changed, 16 insertions(+), 14 deletions(-)
---
diff --git a/vertimus/forms.py b/vertimus/forms.py
index 97c7438b..aec1b9ab 100644
--- a/vertimus/forms.py
+++ b/vertimus/forms.py
@@ -55,7 +55,7 @@ class ActionForm(forms.Form):
help_text=_("Upload a .po, .gz, .bz2, .xz or .png file"))
send_to_ml = forms.BooleanField(label=_("Send message to the team mailing list"), required=False)
- def __init__(self, current_user, state, actions, has_mailing_list, *args, **kwargs):
+ def __init__(self, current_user, state, actions, *args, **kwargs):
super().__init__(*args, **kwargs)
self.actions = actions
self.current_user = current_user
@@ -69,6 +69,9 @@ class ActionForm(forms.Form):
extra_user=current_user
).order_by('last_name', 'username')
self.fields['author'].initial = state.get_latest_po_file_action().person
+ has_mailing_list = (
+ state and state.language and state.language.team and bool(state.language.team.mailing_list)
+ )
if not has_mailing_list:
del self.fields['send_to_ml']
if state and state.branch.is_head():
diff --git a/vertimus/tests/tests.py b/vertimus/tests/tests.py
index b08fc7ad..d98e071d 100644
--- a/vertimus/tests/tests.py
+++ b/vertimus/tests/tests.py
@@ -226,7 +226,7 @@ class VertimusTest(TeamsAndRolesMixin, TestCase):
def test_action_menu(self):
state = StateNone(branch=self.b, domain=self.d, language=self.language)
- form = ActionForm(self.pt, state, state.get_available_actions(self.pt), False)
+ form = ActionForm(self.pt, state, state.get_available_actions(self.pt))
self.assertHTMLEqual(
str(form['action']),
'<select id="id_action" name="action">'
@@ -235,7 +235,7 @@ class VertimusTest(TeamsAndRolesMixin, TestCase):
'<option value="WC">Write a comment</option>'
'</select>'
)
- form = ActionForm(self.pcoo, state, state.get_available_actions(self.pcoo), False)
+ form = ActionForm(self.pcoo, state, state.get_available_actions(self.pcoo))
self.assertHTMLEqual(
str(form['action']),
'<select id="id_action" name="action">'
@@ -264,7 +264,7 @@ class VertimusTest(TeamsAndRolesMixin, TestCase):
self.assertEqual(len(mail.outbox), 2)
self.assertEqual(mail.outbox[1].recipients(), [self.pt.email])
# Test that submitting a comment without text generates a validation error
- form = ActionForm(self.pt, state, [ActionWC()], True, QueryDict('action=WC&comment='))
+ form = ActionForm(self.pt, state, [ActionWC()], data=QueryDict('action=WC&comment='))
self.assertTrue("A comment is needed" in str(form.errors))
self.assertNotEqual(state.updated, prev_updated)
@@ -446,7 +446,7 @@ class VertimusTest(TeamsAndRolesMixin, TestCase):
self.assertIn(ActionCI, map(type, state.get_available_actions(self.pcoo)))
- form = ActionForm(self.pcoo, state, state.get_available_actions(self.pcoo), True)
+ form = ActionForm(self.pcoo, state, state.get_available_actions(self.pcoo))
self.assertEqual(len(form.fields['author'].choices), 6)
self.assertEqual(form.fields['author'].initial, self.pr)
self.assertIn('sync_master', form.fields)
@@ -490,11 +490,11 @@ class VertimusTest(TeamsAndRolesMixin, TestCase):
'comment': '',
'send_to_ml': True
}
- form = ActionForm(self.pcoo, state, state.get_available_actions(self.pcoo), True, post_data)
+ form = ActionForm(self.pcoo, state, state.get_available_actions(self.pcoo), data=post_data)
# Missing author
self.assertFalse(form.is_valid())
post_data['author'] = str(self.pcoo.pk)
- form = ActionForm(self.pcoo, state, state.get_available_actions(self.pcoo), True, post_data)
+ form = ActionForm(self.pcoo, state, state.get_available_actions(self.pcoo), data=post_data)
self.assertTrue(form.is_valid())
# path needed when copying file to commit
(self.b.co_path / 'po').mkdir(parents=True, exist_ok=True)
@@ -720,20 +720,20 @@ class VertimusTest(TeamsAndRolesMixin, TestCase):
# Test a non valid po file
post_content = QueryDict('action=WC&comment=Test1')
post_file = MultiValueDict({'file': [SimpleUploadedFile('filename.po', b'Not valid po file
content')]})
- form = ActionForm(self.pt, None, [ActionWC()], True, post_content, post_file)
+ form = ActionForm(self.pt, None, [ActionWC()], data=post_content, files=post_file)
self.assertTrue('file' in form.errors)
post_file = MultiValueDict({'file': [SimpleUploadedFile('filename.po', 'NiƱa'.encode('latin-1'))]})
- form = ActionForm(self.pt, None, [ActionWC()], True, post_content, post_file)
+ form = ActionForm(self.pt, None, [ActionWC()], data=post_content, files=post_file)
self.assertTrue('file' in form.errors)
# Test a valid po file
with (Path(__file__).parent / "valid_po.po").open('rb') as fh:
post_file = MultiValueDict({'file': [File(fh)]})
- form = ActionForm(self.pt, None, [ActionWC()], True, post_content, post_file)
+ form = ActionForm(self.pt, None, [ActionWC()], data=post_content, files=post_file)
self.assertTrue(form.is_valid())
# Test form without file
- form = ActionForm(self.pt, None, [ActionWC()], True, post_content)
+ form = ActionForm(self.pt, None, [ActionWC()], data=post_content)
self.assertTrue(form.is_valid())
def test_feeds(self):
diff --git a/vertimus/views.py b/vertimus/views.py
index b39dfaa8..79209f04 100644
--- a/vertimus/views.py
+++ b/vertimus/views.py
@@ -89,10 +89,9 @@ def vertimus(request, branch, domain, language, stats=None, level="0"):
# Only authenticated user can act on the translation and it's not
# possible to edit an archived workflow
available_actions = state.get_available_actions(person)
- has_ml = bool(language.team.mailing_list) if language.team else False
if request.method == 'POST':
action_form = ActionForm(
- request.user, state, available_actions, has_ml, request.POST, request.FILES
+ request.user, state, available_actions, request.POST, request.FILES
)
if action_form.is_valid():
@@ -125,7 +124,7 @@ def vertimus(request, branch, domain, language, stats=None, level="0"):
)
)
elif available_actions:
- action_form = ActionForm(request.user, state, available_actions, has_ml)
+ action_form = ActionForm(request.user, state, available_actions)
context = {
'pageSection': 'module',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]