Skip to content
This repository was archived by the owner on Dec 5, 2023. It is now read-only.

Commit a58a743

Browse files
authored
Merge pull request #654 from unfoldingWord-dev/develop
Update from Develop
2 parents d0cca1a + d4f6e6f commit a58a743

File tree

6 files changed

+26
-26
lines changed

6 files changed

+26
-26
lines changed

td/receivers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ def handle_wa_region_delete(sender, instance=None, **kwargs):
2828
@receiver(post_save, sender=TempLanguage)
2929
def handle_templanguage_save(sender, instance, **kwargs):
3030
if kwargs["created"]:
31-
lang = Language.objects.create(code=instance.code)
32-
lang.name = instance.name
33-
lang.direction = instance.direction
34-
lang.country = instance.country
35-
lang.save()
31+
lang = Language.objects.create(
32+
code=instance.code,
33+
name=instance.name,
34+
direction=instance.direction,
35+
country=instance.country,
36+
)
3637
instance.lang_assigned = lang
3738
instance.save()
3839
notify_templanguage_created(instance, lang)

td/tasks.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,22 +267,25 @@ def notify_external_apps(action="", instance=None):
267267
url += "?key=" + key if key is not None else ""
268268
headers = {'Content-Type': 'application/json'}
269269

270-
post_to_ext_apps.delay(url, json.dumps(data), headers)
270+
post_to_ext_app.delay(url, json.dumps(data), headers)
271271

272272
task_status.success = True
273273
return task_status
274274

275275

276276
@task()
277-
def post_to_ext_apps(url, data, headers):
277+
def post_to_ext_app(url, data, headers):
278278
response = requests.post(url, data=data, headers=headers)
279-
if response.status_code == 202 and response.content == "":
280-
return
281-
else:
282-
message = "POST to %s has failed with code: %s and message: %s" % (url, response.status_code, response.content)
279+
if response.status_code != 202 or response.content != "":
280+
message = "POST to %s has failed." % url
281+
message += "\n"
282+
message += "\nsite_id: %s" % settings.SITE_ID
283+
message += "\ncontent: %s" % response.content
284+
message += "\ndata: %s" % data
285+
message += "\nstatus_code: %s" % response.status_code
283286
send_mail(
284-
"Ops CRM shim rejects POST",
287+
"PORT shim rejects POST",
285288
message,
286289
"admin@unfoldingword.org",
287-
["vleong2332@gmail.com"],
290+
["vicky_leong@wycliffeassociates.org"],
288291
)

td/templates/resources/language_list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ <h2>Languages</h2>
2727
<tbody>
2828
</tbody>
2929
</table>
30-
{# <p>If you don't see a language you expect to see it probably isn't in our database. You can request its creation <a href="{% url "templanguage_create" %}">here</a></p>#}
30+
<p>If you don't see a language you expect to see it probably isn't in our database. You can request its creation <a href="{% url "templanguage_create" %}">here</a></p>
3131
{% endblock %}

td/tests/test_tasks.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from mock import patch, Mock
44

55
from td.models import Language, JSONData
6-
from td.tasks import reset_langnames_cache, update_langnames_data, post_to_ext_apps, notify_external_apps
6+
from td.tasks import reset_langnames_cache, update_langnames_data, post_to_ext_app, notify_external_apps
77
from td.tests.models import NoSignalTestCase
88

99

@@ -99,7 +99,7 @@ def test_update_langnames_data(self):
9999
self.assertIn("ld", json)
100100

101101

102-
class PostToExtAppsTestCase(TestCase):
102+
class PostToExtAppTestCase(TestCase):
103103
def setUp(self):
104104
self.patcher_post = patch("td.tasks.requests.post")
105105
self.patcher_send_mail = patch("td.tasks.send_mail")
@@ -119,7 +119,7 @@ def test_accepted_with_no_message(self):
119119
response = {"status_code": 202, "content": ""}
120120
self.mock_response.configure_mock(**response)
121121

122-
post_to_ext_apps("fake_url", "fake_data", "fake_headers")
122+
post_to_ext_app("fake_url", "fake_data", "fake_headers")
123123

124124
self.mock_post.assert_called_once_with("fake_url", data="fake_data", headers="fake_headers")
125125
self.assertFalse(self.mock_send_mail.called)
@@ -131,7 +131,7 @@ def test_accepted_with_message(self):
131131
response = {"status_code": 202, "content": "something's wrong"}
132132
self.mock_response.configure_mock(**response)
133133

134-
post_to_ext_apps("fake_url", "fake_data", "fake_headers")
134+
post_to_ext_app("fake_url", "fake_data", "fake_headers")
135135

136136
self.mock_post.assert_called_once_with("fake_url", data="fake_data", headers="fake_headers")
137137
self.assertEqual(self.mock_send_mail.call_count, 1)
@@ -143,7 +143,7 @@ def test_not_accepted(self):
143143
response = {"status_code": 403}
144144
self.mock_response.configure_mock(**response)
145145

146-
post_to_ext_apps("fake_url", "fake_data", "fake_headers")
146+
post_to_ext_app("fake_url", "fake_data", "fake_headers")
147147

148148
self.mock_post.assert_called_once_with("fake_url", data="fake_data", headers="fake_headers")
149149
self.assertEqual(self.mock_send_mail.call_count, 1)
@@ -283,7 +283,7 @@ def test_bad_ext_app_setting(self, mock_settings):
283283
self.assertGreater(len(status.message), 0)
284284

285285
@patch("td.tasks.settings")
286-
@patch("td.tasks.post_to_ext_apps.delay")
286+
@patch("td.tasks.post_to_ext_app.delay")
287287
def test_no_ext_apps(self, mock_async_post, mock_settings):
288288
"""
289289
If called with the right arguments but no ext apps, function should return success status and post should
@@ -297,7 +297,7 @@ def test_no_ext_apps(self, mock_async_post, mock_settings):
297297
self.assertFalse(mock_async_post.called)
298298

299299
@patch("td.tasks.settings")
300-
@patch("td.tasks.post_to_ext_apps.delay")
300+
@patch("td.tasks.post_to_ext_app.delay")
301301
def test_with_ext_apps(self, mock_async_post, mock_settings):
302302
"""
303303
If called with the right arguments and ext app settings, function should return success status, no message

td/tests/test_views.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ def test_get_with_user(self):
177177
Requesting temporary language creation form should return a success response
178178
"""
179179
response = TempLanguageWizardView.as_view()(self.request)
180-
# self.assertEqual(response.status_code, 200)
181-
self.assertEqual(response.status_code, 302)
180+
self.assertEqual(response.status_code, 200)
182181

183182
def test_init(self):
184183
"""

td/views.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,6 @@ class TempLanguageWizardView(LoginRequiredMixin, SessionWizardView):
669669
form_list = [forms.Form]
670670
template_name = "resources/templanguage_wizard_form.html"
671671

672-
def get(self, request, *args, **kwargs):
673-
return redirect("home")
674-
675672
def __init__(self, *args, **kwargs):
676673
super(TempLanguageWizardView, self).__init__(*args, **kwargs)
677674
self.questionnaire = Questionnaire.objects.latest('created_at')

0 commit comments

Comments
 (0)