diff --git a/temba/msgs/tests.py b/temba/msgs/tests.py index 922f9b4878a..f79dc161d08 100644 --- a/temba/msgs/tests.py +++ b/temba/msgs/tests.py @@ -1976,7 +1976,6 @@ def setUp(self): def _form_data( self, - org, *, translations, contacts=(), @@ -2066,7 +2065,7 @@ def test_create(self, mr_mocks): response = self.process_wizard( "create", create_url, - self._form_data(self.org, translations={"und": {"text": ""}}, contacts=[self.joe]), + self._form_data(translations={"und": {"text": ""}}, contacts=[self.joe]), ) self.assertFormError(response.context["form"], "compose", ["This field is required."]) @@ -2074,7 +2073,7 @@ def test_create(self, mr_mocks): response = self.process_wizard( "create", create_url, - self._form_data(self.org, translations={"eng": {"text": "." * 641}}, contacts=[self.joe]), + self._form_data(translations={"eng": {"text": "." * 641}}, contacts=[self.joe]), ) self.assertFormError(response.context["form"], "compose", ["Maximum allowed text is 640 characters."]) @@ -2083,21 +2082,17 @@ def test_create(self, mr_mocks): response = self.process_wizard( "create", create_url, - self._form_data( - self.org, translations={"eng": {"text": text, "attachments": attachments * 11}}, contacts=[self.joe] - ), + self._form_data(translations={"eng": {"text": text, "attachments": attachments * 11}}, contacts=[self.joe]), ) self.assertFormError(response.context["form"], "compose", ["Maximum allowed attachments is 10 files."]) # empty recipients - response = self.process_wizard( - "create", create_url, self._form_data(self.org, translations={"eng": {"text": text}}) - ) + response = self.process_wizard("create", create_url, self._form_data(translations={"eng": {"text": text}})) self.assertFormError(response.context["form"], "contact_search", ["Contacts or groups are required."]) # empty query response = self.process_wizard( - "create", create_url, self._form_data(self.org, advanced=True, translations={"eng": {"text": text}}) + "create", create_url, self._form_data(advanced=True, translations={"eng": {"text": text}}) ) self.assertFormError(response.context["form"], "contact_search", ["A contact query is required."]) @@ -2106,7 +2101,7 @@ def test_create(self, mr_mocks): response = self.process_wizard( "create", create_url, - self._form_data(self.org, advanced=True, translations={"eng": {"text": text}}, query="invalid"), + self._form_data(advanced=True, translations={"eng": {"text": text}}, query="invalid"), ) self.assertFormError(response.context["form"], "contact_search", ["Invalid query syntax."]) @@ -2114,7 +2109,7 @@ def test_create(self, mr_mocks): response = self.process_wizard( "create", create_url, - self._form_data(self.org, translations={"eng": {"text": text}}, contacts=[self.joe]), + self._form_data(translations={"eng": {"text": text}}, contacts=[self.joe]), ) self.assertFormError(response.context["form"], None, ["Select when you would like the broadcast to be sent"]) @@ -2123,7 +2118,6 @@ def test_create(self, mr_mocks): "create", create_url, self._form_data( - self.org, translations={"eng": {"text": text}}, contacts=[self.joe], start_datetime="2021-06-24 12:00Z", @@ -2142,11 +2136,10 @@ def test_create(self, mr_mocks): "create", create_url, self._form_data( - self.org, translations={"eng": {"text": text}}, contacts=[self.joe], optin=optin, - start_datetime="2021-06-24 12:00", + start_datetime="2021-06-24 12:00Z", repeat_period="W", repeat_days_of_week=["M", "F"], ), @@ -2163,7 +2156,6 @@ def test_create(self, mr_mocks): "create", create_url, self._form_data( - self.org, translations={"eng": {"text": text}}, contacts=[self.joe], send_when=ScheduleForm.SEND_NOW, @@ -2217,7 +2209,6 @@ def test_update(self): "update", update_url, self._form_data( - self.org, translations=updated_text, template=translation.template, variables=["", "World"], @@ -2238,7 +2229,6 @@ def test_update(self): "update", update_url, self._form_data( - self.org, translations=updated_text, template=translation.template, variables=["image/jpeg:http://domain/meow.jpg", "World"], @@ -2256,7 +2246,6 @@ def test_update(self): "update", update_url, self._form_data( - self.org, translations={language: {"text": "Updated broadcast"}}, contacts=[self.joe], optin=optin, @@ -2279,7 +2268,6 @@ def test_update(self): "update", update_url, self._form_data( - self.org, translations=updated_text, contacts=[self.joe], start_datetime="2021-06-24 12:00", @@ -2298,7 +2286,6 @@ def test_update(self): "update", update_url, self._form_data( - self.org, translations=updated_text, contacts=[self.joe], ), @@ -2329,7 +2316,7 @@ def get_languages(response): response = self.process_wizard( "update", update_url, - self._form_data(self.org, translations={}, contacts=[self.joe]), + self._form_data(translations={}, contacts=[self.joe]), ) # we only have a base language and don't have values for org languages, it should be first @@ -2341,7 +2328,6 @@ def get_languages(response): "update", update_url, self._form_data( - self.org, translations={"und": {"text": "undefined"}, "eng": {"text": "hello"}, "esp": {"text": "hola"}}, contacts=[self.joe], start_datetime="2021-06-24 12:00", @@ -2354,7 +2340,7 @@ def get_languages(response): response = self.process_wizard( "update", update_url, - self._form_data(self.org, translations={}, contacts=[self.joe]), + self._form_data(translations={}, contacts=[self.joe]), ) # We have a primary language, it should be first @@ -2372,7 +2358,7 @@ def get_languages(response): response = self.process_wizard( "update", update_url, - self._form_data(self.org, translations={}, contacts=[self.joe]), + self._form_data(translations={}, contacts=[self.joe]), ) languages = get_languages(response) self.assertEqual("esp", languages[0]["iso"]) diff --git a/temba/msgs/views.py b/temba/msgs/views.py index b588a4366f3..f8bacfff913 100644 --- a/temba/msgs/views.py +++ b/temba/msgs/views.py @@ -255,13 +255,17 @@ class ScheduleForm(ScheduleFormMixin): def __init__(self, org, *args, **kwargs): super().__init__(*args, **kwargs) + self.fields["start_datetime"].required = False self.set_org(org) def clean(self): - start_datetime = self.data.get("schedule-start_datetime", None) - if self.data["schedule-send_when"] == ScheduleForm.SEND_LATER and not start_datetime: + send_when = self.data.get("schedule-send_when", ScheduleForm.SEND_LATER) # doesn't exist for updates + start_datetime = self.data.get("schedule-start_datetime") + + if send_when == ScheduleForm.SEND_LATER and not start_datetime: raise forms.ValidationError(_("Select when you would like the broadcast to be sent")) + return super().clean() class Meta: