-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctional_test.py
119 lines (89 loc) · 3.99 KB
/
functional_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
from selenium import webdriver
import time
import unittest
from unittest.mock import patch
class NewVisitorTest(unittest.TestCase):
def setUp(self):
self.browser = webdriver.Firefox()
def tearDown(self):
self.browser.quit()
def test_can_view_the_page(self):
# JayR went to the website, he notice the title as "Surveyor".
self.browser.get('http://localhost:8000')
self.assertIn('Surveyor', self.browser.title)
header_text = self.browser.find_element_by_tag_name('header').text
self.assertIn('Surveyor', header_text)
# He saw a button that invites him to send an SMS and clicked the button
send_sms_page_button = self.browser.find_element_by_id('id_send_sms_page')
self.assertEqual(
send_sms_page_button.text,
"Want to send SMS, click here!"
)
send_sms_page_button.click()
time.sleep(1)
send_sms_page = self.browser.current_url
self.assertEqual(send_sms_page, "http://localhost:8000/send_sms/")
# On the next page, there's header that says:
# Fill this information to send an SMS
header_text = self.browser.find_element_by_tag_name('header').text
self.assertIn('Fill this information to send an SMS', header_text)
# He notice that there are 2 fields and a button.
# The first field is for adding contact information.
input_contact = self.browser.find_element_by_id('id_contact')
self.assertEqual(
input_contact.get_attribute('placeholder'),
'Enter phone number'
)
# The second field is for adding the message.
input_message = self.browser.find_element_by_id('id_message')
self.assertEqual(
input_message.get_attribute('placeholder'),
'Enter your message'
)
# Lastly a button to submit the form.
send_sms_button = self.browser.find_element_by_id('id_send_sms')
self.assertEqual(
send_sms_button.text,
"Send SMS"
)
# So he add his contact number on the first field. 09152087801
input_contact.send_keys("09152087801")
# And added message on the second.
# What is your Full Name?
input_message.send_keys("What is your Full Name?")
# Lastly he clicked the submit button!
send_sms_button.click()
time.sleep(1)
# After clicking the button he is immediately redirected to the home page.
# With a notification that says, "Message sent, please wait for reply!"
# message_notification = self.browser.find_element_by_css_selector('.messages li:first-child').text()
self.assertEqual(self.browser.current_url, "http://localhost:8000/")
# He still didn't see any reply.
table_replies = self.browser.find_element_by_id("id_table_replies")
rows = table_replies.find_elements_by_tag_name("tr")
self.assertTrue(
any(row.text == "" for row in rows)
)
# He got a notification from his phone, check and recieve the message
# that he sent earlier. He immediately replied:
# Elpedio Adoptante
self.assertEqual(self.reply_from_chikka().status_code, 200)
time.sleep(2)
# He tries to refresh the page and saw the message like this.
# Number Name
# 09152087801 Elpedio Adoptante
self.browser.refresh()
table_replies = self.browser.find_element_by_id("id_table_replies")
rows = table_replies.find_elements_by_tag_name("tr")
self.assertTrue(
any("0945983495439" in row.text for row in rows)
)
# He is now happy and closes the browser.
def reply_from_chikka(self):
import requests
return requests.post("http://localhost:8000/chikka_receiver/", data={
"mobile_number": "0945983495439",
"message": "Elpedio Adoptante"
})
if __name__ == '__main__':
unittest.main(warnings='ignore')