We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0e4cb80 commit f17e64eCopy full SHA for f17e64e
PROCESS.md
@@ -153,5 +153,8 @@ Now we create a database called Messages
153
154
Then create a unit test to create that model
155
156
+Then our view can now accept request with csrf_exempt
157
158
159
+Then we show the data in browser using table.
160
+
functional_test.py
@@ -98,12 +98,11 @@ def test_can_view_the_page(self):
98
# 09152087801 Elpedio Adoptante
99
self.browser.refresh()
100
table_replies = self.browser.find_element_by_id("id_table_replies")
101
- rows = table_replies.find_element_by_tag_name("tr")
+ rows = table_replies.find_elements_by_tag_name("tr")
102
self.assertTrue(
103
- any(row.text == "09152087801 JayR" for row in rows)
+ any("0945983495439" in row.text for row in rows)
104
)
105
106
-
107
# He is now happy and closes the browser.
108
109
sms_survey/engagement/templates/index.html
@@ -5,7 +5,13 @@
5
<a href="/send_sms/" id="id_send_sms_page">Want to send SMS, click here!</a>
6
7
<table id="id_table_replies">
8
- <tr></tr>
+ <tr></tr>
9
+ {% for message in messages %}
10
+ <tr>
11
+ <td>{{ message.mobile_number }}</td>
12
+ <td>{{ message.message }}</td>
13
+ </tr>
14
+ {% endfor %}
15
</table>
16
17
</body>
sms_survey/engagement/tests.py
@@ -16,6 +16,17 @@ def test_index_return_correct_html(self):
self.assertTrue(html.strip().endswith('</html>'))
18
self.assertTemplateUsed(response, 'index.html')
19
20
21
+ def test_should_return_content_data(self):
22
+ Messages.objects.create(
23
+ id=1,
24
+ mobile_number="9847543895",
25
+ message="This is a message",
26
+ )
27
+ response = self.client.get("/")
28
+ html = response.content.decode('utf8')
29
+ self.assertIn("This is a message", html)
30
31
32
class SendSMSPageTest(TestCase):
@@ -71,4 +82,12 @@ def test_should_return_200(self):
71
82
})
72
83
self.assertEqual(response.status_code, 200)
73
84
74
85
+ def test_it_should_save_to_database(self):
86
+ # it should save to database
87
+ self.client.post("/chikka_receiver/", data={
88
+ "mobile_number": "0945983495439",
89
+ "message": "Elpedio Adoptante"
90
+ })
91
+ m = Messages.objects.all()
92
+ self.assertTrue(len(m) > 0)
93
+ self.assertEqual(m[0].mobile_number, '0945983495439')
sms_survey/engagement/views.py
@@ -1,10 +1,12 @@
1
import requests
2
+from django.http import HttpResponse
3
from django.shortcuts import render, redirect
-# from .models import Messages
4
+from django.views.decorators.csrf import csrf_exempt
+from .models import Messages
# Create your views here.
def index(request):
- return render(request, 'index.html')
+ return render(request, 'index.html', {"messages": Messages.objects.all()})
def send_sms(request):
@@ -18,11 +20,14 @@ def send_sms(request):
return render(request, 'send_sms.html')
+@csrf_exempt
def chikka_receiver(request):
- from django.http import HttpResponse
+ mobile_number=request.POST.get('mobile_number'),
+ message=request.POST.get('message')
return HttpResponse({"message": "Success"})
def chikka_proxy(request):
33
0 commit comments