Browse Source

fix webdriver tests

* introduce PhantomJS (headless webkit) (also a new dependency)
* better docstrings
* webdriver tests get their own config file (.ini) and database (.db)
Christoph Scheid 3 years ago
parent
commit
f779d11552
4 changed files with 516 additions and 73 deletions
  1. 381
    71
      c3smembership/tests/test_views_webdriver.py
  2. 110
    0
      c3smembership/tests/webdriver_utils.py
  3. 3
    2
      development.ini
  4. 22
    0
      webdrivertest.ini

+ 381
- 71
c3smembership/tests/test_views_webdriver.py View File

@@ -1,57 +1,156 @@
1 1
 # _*_ coding: utf-8 _*_
2
-import unittest
2
+"""
3
+These tests test
4
+
5
+* the join form and
6
+* the email verification form
7
+
8
+using selenium/webdriver (make a browser do things), see:
9
+
10
+* http://docs.seleniumhq.org/docs/03_webdriver.jsp#introducing-the-selenium-webdriver-api-by-example
11
+* http://selenium-python.readthedocs.org/en/latest/api.html
12
+* http://selenium.googlecode.com/svn/trunk/docs/api/py/index.html
13
+
14
+On the machine where these tests run, a virtual screen (X) must be running,
15
+e.g. Xvfb, so the browser can start and things be done,
16
+even in headless mode, e.g. on a virtual machine on a remote server
17
+with no real screen attached.
18
+
19
+While developing these tests, it comes in handy to have Xephyr installed,
20
+a nested X server, so you see what is going on:
21
+selenium/webdriver makes the browser do things.
22
+"""
23
+import os
24
+# from pyvirtualdisplay import Display
3 25
 from selenium import webdriver
4 26
 from selenium.webdriver.common.keys import Keys
5
-# from selenium.webdriver.support.ui import WebDriverWait
6
-# available since 2.4.0
7
-# from selenium.webdriver.support import expected_conditions as EC
8
-# available since 2.26.0
9
-import time
10 27
 from subprocess import call
28
+import time
29
+import unittest
30
+
31
+from webdriver_utils import (
32
+    Server,
33
+    Client
34
+)
35
+
11 36
 
12
-# maybe check https://pypi.python.org/pypi/z3c.webdriver
37
+"""
38
+this setting controls whether the browser will be visible (1) or not (0)
39
+"""
40
+is_visible = 1
41
+
42
+# configuration of testing framework
43
+cfg = {
44
+    'app': {
45
+        'host': '0.0.0.0',
46
+        'port': '6543',
47
+        'db': 'webdrivertest.db',
48
+        'ini': "webdrivertest.ini",
49
+        'appSettings': {},
50
+    },
51
+}
52
+server = Server()
53
+client = Client()
13 54
 
14 55
 
15 56
 class SeleniumTestBase(unittest.TestCase):
57
+
58
+    # overload: configuration of individual appSettings
59
+    @classmethod
60
+    def appSettings(self):
61
+        return {}
62
+
63
+    def initialize_db(self):
64
+        """
65
+        make sure we have entries in the DB
66
+        """
67
+        if os.path.isfile('webdrivertest.db'):
68
+            call(['rm', 'webdrivertest.db'])
69
+            print("old database was deleted.")
70
+        print("initialize the test database:")
71
+        call(['env/bin/initialize_c3sMembership_db', 'webdrivertest.ini'])
72
+        print("database was set up.")
73
+
16 74
     def setUp(self):
17
-        # stop the daemon iff running
18
-        call(['env/bin/pserve', 'development.ini', 'stop'])
19
-        # start the app
20
-        call(['env/bin/pserve', 'development.ini', 'start'])
21
-        time.sleep(3)
22
-        self.driver = webdriver.Firefox()  # PhantomJS()
75
+        # # daemon start/stop
76
+        # # stop the daemon iff running
77
+        # call(['env/bin/pserve', 'webdrivertest.ini', 'stop'])
78
+        # # start the app
79
+        # call(['env/bin/pserve', 'webdrivertest.ini', 'start'])
80
+
81
+        # wsgi way!
82
+        self.cfg = cfg
83
+
84
+        self.srv = server.connect(
85
+            cfg=self.cfg,
86
+            customAppSettings=self.appSettings(),
87
+            wrapper='StopableWSGIServer'
88
+        )
89
+        # self.cli = client.connect(
90
+        #        cfg=self.cfg
91
+        # )
92
+
93
+        time.sleep(0.1)
94
+
95
+        # self.display = Display(
96
+        #     visible=is_visible,
97
+        #     size=(1024, 768)
98
+        #     # size=(1600, 1200)
99
+        # )
100
+        # self.display.start()
101
+        # self.driver = webdriver.Firefox()
102
+        self.driver = webdriver.PhantomJS()
103
+        # self.driver = webdriver.Chrome()
104
+        # get rid of all cookies
105
+        self.driver.delete_all_cookies()
106
+
107
+    def tearDown(self):
108
+        self.driver.close()
109
+        self.driver.quit()
110
+        # self.display.stop()
111
+        # client.disconnect()
112
+        server.disconnect()
113
+        time.sleep(2)
23 114
 
24 115
 
25 116
 class JoinFormTests(SeleniumTestBase):
26 117
     """
27
-    test the join form using selenium (make a browser do things)
28
-    see
29
-    http://docs.seleniumhq.org/docs/03_webdriver.jsp
30
-           #introducing-the-selenium-webdriver-api-by-example
31
-    http://selenium-python.readthedocs.org/en/latest/api.html
32
-    http://selenium.googlecode.com/svn/trunk/docs/api/py/index.html
118
+    Test the join form with selenium/webdriver.
33 119
     """
34 120
     def setUp(self):
35 121
         super(JoinFormTests, self).setUp()
36 122
 
37 123
     def tearDown(self):
38
-        self.driver.quit()
39
-        call(['env/bin/pserve', 'development.ini', 'stop'])
124
+        # self.driver.quit()
125
+        super(JoinFormTests, self).tearDown()
126
+        # call(['env/bin/pserve', 'webdrivertest.ini', 'stop'])
40 127
 
41 128
     def test_form_submission_de(self):
42
-        from c3smembership.views.afm import join_c3s  # trigger coverage
43
-        join_c3s
44
-        self.driver.get("http://0.0.0.0:6543/?de")
129
+        """
130
+        A webdriver test for the join form, german version
131
+        """
132
+        self.assertEqual(self.driver.get_cookies(), [])
133
+        # load the page with the form, choose german
134
+        self.driver.get("http://0.0.0.0:6543?de")
45 135
         # self.driver.maximize_window()
46
-        inputElement = self.driver.find_element_by_name("firstname")
47
-        inputElement.send_keys("Christoph")
136
+
137
+        self.driver.get_screenshot_as_file('test_form_submission_de.png')
138
+        self.failUnless(
139
+            u'Mitgliedschaftsantrag' in self.driver.page_source)
140
+
141
+        # check for cookie -- should be 'de' for germen
142
+        self.assertEquals(self.driver.get_cookie('_LOCALE_')['value'], u'de')
143
+
144
+        # fill out the form
145
+        self.driver.find_element_by_name("firstname").send_keys("Christoph")
48 146
         self.driver.find_element_by_name('lastname').send_keys('Scheid')
49 147
         time.sleep(0.1)
50 148
         self.driver.find_element_by_name('email').send_keys('c@c3s.cc')
51 149
         time.sleep(0.1)
52 150
         self.driver.find_element_by_name('password').send_keys('foobar')
53 151
         time.sleep(0.1)
54
-        self.driver.find_element_by_name('password-confirm').send_keys('foobar')
152
+        self.driver.find_element_by_name('password-confirm').send_keys(
153
+            'foobar')
55 154
         time.sleep(0.1)
56 155
         self.driver.find_element_by_name('address1').send_keys('addr one')
57 156
         time.sleep(0.11)
@@ -61,7 +160,7 @@ class JoinFormTests(SeleniumTestBase):
61 160
         time.sleep(0.1)
62 161
         self.driver.find_element_by_name('city').send_keys('townish')
63 162
         time.sleep(0.1)
64
-        self.driver.find_element_by_name('country').send_keys('Gro')
163
+        self.driver.find_element_by_name('country').send_keys('Gri')
65 164
         time.sleep(0.1)
66 165
         self.driver.find_element_by_name('year').send_keys(Keys.CONTROL, "a")
67 166
         self.driver.find_element_by_name('year').send_keys('1998')
@@ -77,8 +176,7 @@ class JoinFormTests(SeleniumTestBase):
77 176
         self.driver.find_element_by_name('other_colsoc').click()  # Yes
78 177
         # self.driver.find_element_by_id('other_colsoc-1').click()  # No
79 178
         time.sleep(0.1)
80
-        self.driver.find_element_by_id(
81
-            'colsoc_name').send_keys('GEMA')
179
+        self.driver.find_element_by_id('colsoc_name').send_keys('GEMA')
82 180
         time.sleep(0.1)
83 181
         self.driver.find_element_by_name('got_statute').click()
84 182
         time.sleep(0.1)
@@ -88,23 +186,184 @@ class JoinFormTests(SeleniumTestBase):
88 186
 
89 187
         self.driver.find_element_by_name('submit').click()
90 188
 
91
-        self.failUnless('E-Mail anfordern' in self.driver.page_source)
189
+        self.failUnless(
190
+            u'Bestätigungs-E-Mail schicken' in self.driver.page_source)
92 191
 
93 192
         # TODO: check contents of success page XXX
94 193
         self.assertTrue('Christoph' in self.driver.page_source)
95 194
         self.assertTrue('Scheid' in self.driver.page_source)
96 195
         self.assertTrue('Was nun passieren muss: Kontrolliere die Angaben '
97 196
                         'unten,' in self.driver.page_source)
197
+        # TODO: check case colsoc = no views.py 765-767
198
+
199
+        # TODO: check save to DB/randomstring: views.py 784-865
200
+
201
+        self.failUnless(u'Daten bearbeiten' in self.driver.page_source)
202
+
203
+        # back to the form
204
+        self.driver.find_element_by_name('edit').click()
205
+
206
+        time.sleep(1)  # wait a little
207
+        self.assertEqual(self.driver.find_element_by_name(
208
+            'lastname').get_attribute('value'), 'Scheid')
209
+        self.assertEqual(self.driver.find_element_by_name(
210
+            'firstname').get_attribute('value'), 'Christoph')
211
+        self.assertEqual(self.driver.find_element_by_name(
212
+            'email').get_attribute('value'), 'c@c3s.cc')
213
+        # self.assertEqual(self.driver.find_element_by_name(
214
+        #    'password').get_attribute('value'), 'foobar')
215
+        # print("the password: %s" % self.driver.find_element_by_name(
216
+        #        'password').get_attribute('value'))
217
+        self.assertEqual(self.driver.find_element_by_name(
218
+            'address1').get_attribute('value'), 'addr one')
219
+        self.assertEqual(self.driver.find_element_by_name(
220
+            'address2').get_attribute('value'), 'addr two')
221
+        self.assertEqual(self.driver.find_element_by_name(
222
+            'postcode').get_attribute('value'), '98765')
223
+        self.assertEqual(self.driver.find_element_by_name(
224
+            'city').get_attribute('value'), 'townish')
225
+        self.assertEqual(self.driver.find_element_by_name(
226
+            'country').get_attribute('value'), 'GR')
227
+        self.assertEqual(self.driver.find_element_by_name(
228
+            'year').get_attribute('value'), '1998')
229
+        self.assertEqual(self.driver.find_element_by_name(
230
+            'month').get_attribute('value'), '12')
231
+        self.assertEqual(self.driver.find_element_by_name(
232
+            'day').get_attribute('value'), '12')
233
+        self.assertEqual(self.driver.find_element_by_name(
234
+            'deformField14').get_attribute('value'), 'normal')
235
+        self.assertEqual(self.driver.find_element_by_name(
236
+            'other_colsoc').get_attribute('value'), 'yes')
237
+        self.assertEqual(self.driver.find_element_by_id(
238
+            'colsoc_name').get_attribute('value'), 'GEMA')
239
+        self.assertEqual(self.driver.find_element_by_name(
240
+            'num_shares').get_attribute('value'), '17')
241
+        # change a detail
242
+        self.driver.find_element_by_name('address2').send_keys(' plus')
243
+        # ok, all data checked, submit again
244
+        self.driver.find_element_by_name('submit').click()
245
+
246
+        self.assertTrue('Bitte beachten: Es gab Fehler. Bitte Eingaben unten '
247
+                        'korrigieren.' in self.driver.page_source)
248
+
249
+        # verify we have to theck this again
250
+        self.driver.find_element_by_name('got_statute').click()
251
+        self.driver.find_element_by_name('got_dues_regulations').click()
252
+        self.driver.find_element_by_id('other_colsoc-1').click()  # No colsoc
253
+        self.driver.find_element_by_id('colsoc_name').send_keys(Keys.CONTROL, "a")
254
+        self.driver.find_element_by_id('colsoc_name').send_keys(Keys.DELETE)
255
+        # enter password
256
+        self.driver.find_element_by_name('password').send_keys('foobar')
257
+        self.driver.find_element_by_name('password-confirm').send_keys(
258
+            'foobar')
259
+        time.sleep(0.1)
260
+
261
+        self.driver.find_element_by_name('submit').click()
262
+        time.sleep(0.1)
263
+        self.assertTrue(
264
+            'Bitte beachten: Es gab fehler' not in self.driver.page_source)
265
+        self.assertTrue('addr two plus' in self.driver.page_source)
266
+        # print self.driver.page_source
267
+        # time.sleep(10)
268
+
269
+        self.driver.find_element_by_name('send_email').click()
270
+        time.sleep(0.1)
271
+
272
+        page = self.driver.page_source
273
+
274
+        self.assertTrue('C3S Mitgliedsantrag: Bitte E-Mails abrufen.' in page)
275
+        self.assertTrue('Eine E-Mail wurde verschickt,' in page)
276
+        self.assertTrue('Christoph Scheid!' in page)
277
+
278
+        self.assertTrue(
279
+            u'Du wirst eine E-Mail von noreply@c3s.cc mit einem ' in page)
280
+        self.assertTrue(
281
+            u'Bestätigungslink erhalten. Bitte rufe Deine E-Mails ab.' in page)
282
+
283
+        self.assertTrue(u'Der Betreff der E-Mail lautet:' in page)
284
+        self.assertTrue(u'C3S: E-Mail-Adresse' in page)
285
+        self.assertTrue(u'tigen und Formular abrufen' in page)
286
+
287
+    def test_form_submission_en(self):
288
+        """
289
+        A webdriver test for the join form, english version
290
+        """
291
+        self.assertEqual(self.driver.get_cookies(), [])
292
+        # load the page with the form
293
+        self.driver.get("http://0.0.0.0:6543?en")
294
+        # self.driver.maximize_window()
295
+
296
+        self.driver.get_screenshot_as_file('test_form_submission_en.png')
297
+
298
+        self.failUnless(  # english !?!
299
+            u'Application for Membership' in self.driver.page_source)
300
+
301
+        # check for cookie -- should be 'en' for english
302
+        self.assertEquals(self.driver.get_cookie('_LOCALE_')['value'], u'en')
303
+
304
+        # fill out the form
305
+        self.driver.find_element_by_name("firstname").send_keys("Christoph")
306
+        self.driver.find_element_by_name('lastname').send_keys('Scheid')
307
+        time.sleep(0.1)
308
+        self.driver.find_element_by_name('email').send_keys('c@c3s.cc')
309
+        time.sleep(0.1)
310
+        self.driver.find_element_by_name('password').send_keys('foobar')
311
+        time.sleep(0.1)
312
+        self.driver.find_element_by_name('password-confirm').send_keys(
313
+            'foobar')
314
+        time.sleep(0.1)
315
+        self.driver.find_element_by_name('address1').send_keys('addr one')
316
+        time.sleep(0.11)
317
+        self.driver.find_element_by_name('address2').send_keys('addr two')
318
+        time.sleep(0.11)
319
+        self.driver.find_element_by_name('postcode').send_keys('98765')
320
+        time.sleep(0.1)
321
+        self.driver.find_element_by_name('city').send_keys('townish')
322
+        time.sleep(0.1)
323
+        self.driver.find_element_by_name('country').send_keys('Gro')
324
+        time.sleep(0.1)
325
+        self.driver.find_element_by_name('year').send_keys(Keys.CONTROL, "a")
326
+        self.driver.find_element_by_name('year').send_keys('1998')
327
+        time.sleep(0.1)
328
+        self.driver.find_element_by_name('month').send_keys(Keys.CONTROL, "a")
329
+        self.driver.find_element_by_name('month').send_keys('12')
330
+        time.sleep(0.1)
331
+        self.driver.find_element_by_name('day').send_keys(Keys.CONTROL, "a")
332
+        self.driver.find_element_by_name('day').send_keys('12')
333
+        time.sleep(0.1)
334
+        self.driver.find_element_by_name('deformField14').click()
335
+        time.sleep(0.1)
336
+        self.driver.find_element_by_name('other_colsoc').click()  # Yes
337
+        # self.driver.find_element_by_id('other_colsoc-1').click()  # No
338
+        time.sleep(0.1)
339
+        self.driver.find_element_by_id('colsoc_name').send_keys('GEMA')
340
+        time.sleep(0.1)
341
+        self.driver.find_element_by_name('got_statute').click()
342
+        time.sleep(0.1)
343
+        self.driver.find_element_by_name('got_dues_regulations').click()
344
+        time.sleep(0.1)
345
+        self.driver.find_element_by_name('num_shares').send_keys('7')
346
+
347
+        self.driver.find_element_by_name('submit').click()
348
+
349
+        # self.failUnless('E-Mail anfordern' in self.driver.page_source)
350
+        self.failUnless('Send verification email' in self.driver.page_source)
351
+
352
+        # TODO: check contents of success page XXX
353
+        self.assertTrue('Christoph' in self.driver.page_source)
354
+        self.assertTrue('Scheid' in self.driver.page_source)
355
+        self.assertTrue('What happens next: You need to check the information '
356
+                        'below to be correct, receive an email to verify your '
357
+                        'address,' in self.driver.page_source)
98 358
 
99 359
         # TODO: check case colsoc = no views.py 765-767
100 360
 
101 361
         # TODO: check save to DB/randomstring: views.py 784-865
102 362
 
103 363
         # TODO: check re-edit of form: views.py 877-880 XXX
104
-        # self.failUnless('Angaben ändern' in self.driver.page_source)
105 364
         self.driver.find_element_by_name('edit').click()
106 365
         # back to the form
107
-        time.sleep(0.1)  # wait a little
366
+        time.sleep(1)  # wait a little
108 367
         self.assertEqual(self.driver.find_element_by_name(
109 368
             'lastname').get_attribute('value'), 'Scheid')
110 369
         self.assertEqual(self.driver.find_element_by_name(
@@ -124,7 +383,7 @@ class JoinFormTests(SeleniumTestBase):
124 383
         self.assertEqual(self.driver.find_element_by_name(
125 384
             'city').get_attribute('value'), 'townish')
126 385
         self.assertEqual(self.driver.find_element_by_name(
127
-            'country').get_attribute('value'), 'GB')
386
+            'country').get_attribute('value'), 'GR')
128 387
         self.assertEqual(self.driver.find_element_by_name(
129 388
             'year').get_attribute('value'), '1998')
130 389
         self.assertEqual(self.driver.find_element_by_name(
@@ -144,16 +403,18 @@ class JoinFormTests(SeleniumTestBase):
144 403
         # ok, all data checked, submit again
145 404
         self.driver.find_element_by_name('submit').click()
146 405
 
147
-        self.assertTrue('Bitte beachten: Es gab Fehler. Bitte Eingaben unten '
148
-                        'korrigieren.' in self.driver.page_source)
406
+        self.assertTrue('Please note: There were errors, please check the '
407
+                        'form below.' in self.driver.page_source)
149 408
 
150 409
         # verify we have to theck this again
151 410
         self.driver.find_element_by_name('got_statute').click()
152 411
         self.driver.find_element_by_name('got_dues_regulations').click()
153 412
         self.driver.find_element_by_id('other_colsoc-1').click()  # No colsoc
413
+        self.driver.find_element_by_id('colsoc_name').send_keys('')
154 414
         # enter password
155 415
         self.driver.find_element_by_name('password').send_keys('foobar')
156
-        self.driver.find_element_by_name('password-confirm').send_keys('foobar')
416
+        self.driver.find_element_by_name('password-confirm').send_keys(
417
+            'foobar')
157 418
         time.sleep(0.1)
158 419
 
159 420
         self.driver.find_element_by_name('submit').click()
@@ -169,37 +430,65 @@ class JoinFormTests(SeleniumTestBase):
169 430
 
170 431
         page = self.driver.page_source
171 432
 
172
-        self.assertTrue('C3S Mitgliedsantrag: Bitte Emails abrufen.' in page)
173
-        self.assertTrue('Eine Email wurde verschickt,' in page)
433
+        # self.assertTrue('C3S Mitgliedsantrag: Bitte Emails abrufen.' in page)
434
+        self.assertTrue('C3S Membership Application: Check your email' in page)
435
+        # self.assertTrue('Eine Email wurde verschickt,' in page)
436
+        self.assertTrue('An email was sent,' in page)
174 437
         self.assertTrue('Christoph Scheid!' in page)
175 438
 
439
+        # self.assertTrue(
440
+        #    u'Du wirst eine Email von noreply@c3s.cc mit einem ' in page)
441
+        # self.assertTrue(
442
+        #    u'Bestätigungslink erhalten. Bitte rufe Deine Emails ab.' in page)
176 443
         self.assertTrue(
177
-            u'Du wirst eine Email von noreply@c3s.cc mit einem ' in page)
444
+            u'You will receive an email from noreply@c3s.cc with ' in page)
178 445
         self.assertTrue(
179
-            u'Bestätigungslink erhalten. Bitte rufe Deine Emails ab.' in page)
446
+            u'a link. Please check your email!' in page)
180 447
 
181
-        self.assertTrue(u'Der Betreff der Email lautet:' in page)
182
-        self.assertTrue(u'C3S: Email-Adresse' in page)
448
+        # self.assertTrue(u'Der Betreff der Email lautet:' in page)
449
+        self.assertTrue(u'The email subject line will read:' in page)
450
+        # self.assertTrue(u'C3S: Email-Adresse' in page)
451
+        self.assertTrue(u'C3S: confirm your email address ' in page)
183 452
         # self.assertTrue(u'tigen und Formular abrufen.' in page)
453
+        self.assertTrue(u'and load your PDF' in page)
454
+        time.sleep(0.1)
184 455
 
185 456
 
186 457
 class EmailVerificationTests(SeleniumTestBase):
458
+    """
459
+    Tests for the view where users are sent after submitting their data.
460
+    They must enter their password and thereby confirm their email address,
461
+    as they got to this form by clicking on a link supplied by mail.
462
+    """
187 463
 
188 464
     def setUp(self):
465
+        super(EmailVerificationTests, self).initialize_db()
189 466
         super(EmailVerificationTests, self).setUp()
190 467
 
191 468
     def tearDown(self):
192
-        self.driver.quit()
193
-        call(['env/bin/pserve', 'development.ini', 'stop'])
194
-
195
-    def test_verify_email(self):  # views.py 296-298
196
-        url = "http://0.0.0.0:6543/verify/foo@shri.de/ABCDEFGHIJ"
469
+        # self.driver.quit()
470
+        super(EmailVerificationTests, self).tearDown()
471
+        # call(['env/bin/pserve', 'webdrivertest.ini', 'stop'])
472
+
473
+    def test_verify_email_de(self):  # views.py 296-298
474
+        """
475
+        This test checks -- after an application has been filled out --
476
+        for the password supplied during application.
477
+        If the password matches the email address, a link to a PDF is given.
478
+        Thus, an half-ready application must be present in the DB.
479
+        """
480
+        url = "http://0.0.0.0:6543/verify/uat.yes@c3s.cc/ABCDEFGHIJ?de"
197 481
         self.driver.get(url)
198 482
 
483
+        # print(self.driver.page_source)
199 484
         self.assertTrue(
200
-            'Bitte das Passwort eingeben.' in self.driver.page_source)
485
+            u'Bitte gib Dein Passwort ein, um' in self.driver.page_source)
486
+        self.assertTrue(
487
+            u'Deine E-Mail-Adresse zu bestätigen.' in self.driver.page_source)
201 488
         self.assertTrue(
202 489
             'Hier geht es zum PDF...' in self.driver.page_source)
490
+
491
+        # try with empty or wrong password -- must fail
203 492
         self.driver.find_element_by_name(
204 493
             'password').send_keys('')  # empty password
205 494
         self.driver.find_element_by_name('submit').click()
@@ -214,36 +503,57 @@ class EmailVerificationTests(SeleniumTestBase):
214 503
         self.assertTrue(
215 504
             'Bitte das Passwort eingeben.' in self.driver.page_source)
216 505
         self.assertTrue('Hier geht es zum PDF...' in self.driver.page_source)
506
+
507
+        # try correct password
217 508
         self.driver.find_element_by_name('password').send_keys('berries')
218 509
         self.driver.find_element_by_name('submit').click()
219 510
 
220
-        self.assertTrue('Lade dein PDF...' in self.driver.page_source)
511
+        # print(self.driver.page_source)
512
+        self.assertTrue('Lade Dein PDF...' in self.driver.page_source)
221 513
         self.assertTrue(
222 514
             'C3S_SCE_AFM_Firstn_meLastname.pdf' in self.driver.page_source)
515
+        # XXX TODO: check PDF download
516
+
517
+    def test_verify_email_en(self):  # views.py 296-298
518
+        """
519
+        This test checks -- after an application has been filled out --
520
+        for the password supplied during application.
521
+        If the password matches the email address, a link to a PDF is given.
522
+        Thus, an half-ready application must be present in the DB.
523
+        """
524
+        url = "http://0.0.0.0:6543/verify/uat.yes@c3s.cc/ABCDEFGHIJ?en"
525
+        self.driver.get(url)
223 526
 
224
-#        import pdb
225
-#        pdb.set_trace()
226
-
227
-
228
-#    def test_verify_email_wrong_pass(self):  # views.py 296-298
229
-#        pass
230
-
231
-#    def test_foo(self):
232
-#        pass
527
+        # print(self.driver.page_source)
528
+        # check text on page
529
+        self.assertTrue(
530
+            'Please enter your password in order ' in self.driver.page_source)
531
+        self.assertTrue(
532
+            'to verify your email address.' in self.driver.page_source)
233 533
 
234
-# class DashboardPageObject(object):
235
-#     def __init__(self):
236
-#         pass
237
-#         # ToDo: write page object
534
+        #
535
+        # enter empty or wrong password -- must fail
536
+        self.driver.find_element_by_name(
537
+            'password').send_keys('')  # empty password
538
+        self.driver.find_element_by_name('submit').click()  # submit
238 539
 
540
+        self.assertTrue(
541
+            'Please enter your password.' in self.driver.page_source)
542
+        
543
+        self.driver.find_element_by_name(
544
+            'password').send_keys('schmoo')  # wrong password
545
+        self.driver.find_element_by_name('submit').click()  # submit
239 546
 
240
-# class OrderByTests(SeleniumTestBase):
241
-#     def setUp(self):
242
-#         super(OrderByTests, self).setUp()
243
-#         self.driver.get('')
547
+        self.assertTrue(
548
+            'Please enter your password.' in self.driver.page_source)
244 549
 
245
-#     def tearDown(self):
246
-#         self.driver.quit()
550
+        #
551
+        # try correct password
552
+        self.driver.find_element_by_name('password').send_keys('berries')
553
+        self.driver.find_element_by_name('submit').click()  # submit
247 554
 
248
-#     def test(self):
249
-#         url = "http://0.0.0.0:6543/dashboard/0/id/asc"
555
+        # print(self.driver.page_source)
556
+        self.assertTrue('Load your PDF...' in self.driver.page_source)
557
+        self.assertTrue(  # PDF form is visible
558
+            'C3S_SCE_AFM_Firstn_meLastname.pdf' in self.driver.page_source)
559
+        # XXX TODO: check PDF download

+ 110
- 0
c3smembership/tests/webdriver_utils.py View File

@@ -0,0 +1,110 @@
1
+"""
2
+This module has some useful stuff for webdriver testing.
3
+"""
4
+import os
5
+from sqlalchemy import engine_from_config
6
+from c3smembership.models import (
7
+    DBSession,
8
+    Base,
9
+    # C3sStaff,
10
+    # Group,
11
+)
12
+from paste.deploy.loadwsgi import appconfig
13
+from webtest.http import StopableWSGIServer
14
+from webtest import TestApp
15
+from selenium import webdriver
16
+
17
+
18
+class Server(object):
19
+
20
+    # singleton
21
+    _instance = None
22
+
23
+    def __new__(cls, *args, **kwargs):
24
+        if not cls._instance:
25
+            cls._instance = super(Server, cls).__new__(cls, *args, **kwargs)
26
+            return cls._instance
27
+
28
+    def connect(self, cfg, customAppSettings={}, wrapper='StopableWSGIServer'):
29
+        self.cfg = cfg
30
+        # clear old connections
31
+        # try:
32
+        # DBSession.close()
33
+        # DBSession.remove()
34
+        # os.remove(self.cfg['app']['db'])
35
+        # except:
36
+        # pass
37
+        # create appConfig from ini
38
+        self.appSettings = appconfig(
39
+            'config:' + os.path.join(
40
+                os.path.dirname(__file__), '../../', self.cfg['app']['ini']
41
+            )
42
+        )
43
+        # store some derived variables
44
+        self.appSettings['sqlalchemy.url'] = 'sqlite:///'+self.cfg['app']['db']
45
+        # merge/override appConfig with custom settings in cfg
46
+        self.appSettings.update(self.cfg['app']['appSettings'])
47
+        # merge/override appConfig with individual custom settings
48
+        self.appSettings.update(customAppSettings)
49
+        # app
50
+        engine = engine_from_config(self.appSettings)
51
+        DBSession.configure(bind=engine)
52
+        Base.metadata.create_all(engine)
53
+        from c3smembership import main
54
+        app = main({}, **self.appSettings)
55
+        # create srv
56
+        if wrapper == 'StopableWSGIServer':
57
+            self.srv = StopableWSGIServer.create(
58
+                app,
59
+                host=self.cfg['app']['host'],
60
+                port=self.cfg['app']['port']
61
+            )
62
+            # check srv
63
+            if not self.srv.wait():
64
+                raise Exception('Server could not be fired up. Exiting ...')
65
+        elif wrapper == 'TestApp':
66
+            self.srv = TestApp(app)
67
+        else:
68
+            raise Exception('Wrapper could not be found. Exiting ...')
69
+        # store some variables
70
+        self.srv.db = DBSession
71
+        self.srv.url = 'http://' + self.cfg['app']['host'] + ':' \
72
+                       + self.cfg['app']['port'] + '/'
73
+        # self.srv.lu = 'lu/' + self.cfg['member']['token'] + '/' \
74
+        #              + self.cfg['member']['email']
75
+        return self.srv
76
+
77
+    def disconnect(self):
78
+        self.srv.db.close()
79
+        self.srv.db.remove()
80
+        os.remove(self.cfg['app']['db'])
81
+        if isinstance(self.srv, StopableWSGIServer):
82
+                self.srv.shutdown()
83
+
84
+    def shutdown(self):
85
+        # self.srv.db.close()
86
+        # self.srv.db.remove()
87
+        # os.remove(self.cfg['app']['db'])
88
+        if isinstance(self.srv, StopableWSGIServer):
89
+                self.srv.shutdown()
90
+
91
+
92
+class Client(object):
93
+
94
+    # singleton
95
+    _instance = None
96
+
97
+    def __new__(cls, *args, **kwargs):
98
+        if not cls._instance:
99
+            cls._instance = super(Client, cls).__new__(cls, *args, **kwargs)
100
+        return cls._instance
101
+
102
+    def connect(self, cfg):
103
+        self.cfg = cfg
104
+        # self.cli = webdriver.PhantomJS()
105
+        # self.cli = webdriver.Firefox()
106
+        self.cli = webdriver.Chromium()
107
+        return self.cli
108
+
109
+    def disconnect(self):
110
+            self.cli.quit()

+ 3
- 2
development.ini View File

@@ -4,7 +4,7 @@ use = egg:c3sMembership
4 4
 pyramid.reload_templates = true
5 5
 pyramid.debug_authorization = false
6 6
 pyramid.debug_notfound = false
7
-pyramid.debug_routematch = false
7
+pyramid.debug_routematch = true
8 8
 pyramid.debug_templates = true
9 9
 pyramid.default_locale_name = de
10 10
 pyramid.includes = pyramid_debugtoolbar
@@ -22,7 +22,8 @@ c3smembership.dashboard_number = 30
22 22
 c3smembership.adminpass = rut
23 23
 c3smembership.adminlogin = berries
24 24
 c3smembership.url = http://0.0.0.0:6543
25
-available_languages = de en # da es fr
25
+available_languages = de en
26
+# da es fr
26 27
 startnext_importfile = /the/path/to/c3sMembership/import/test_startnext.csv
27 28
 founders_importfile = /path/to/c3sMembership/import/test_founders.csv
28 29
 api_auth_token = 1234567890ABCDEFGHIJKL

+ 22
- 0
webdrivertest.ini View File

@@ -0,0 +1,22 @@
1
+[app:main]
2
+use = egg:c3sMembership
3
+
4
+sqlalchemy.url = sqlite:///%(here)s/webdrivertest.db
5
+
6
+# settings for c3sMembership
7
+c3smembership.runmode = dev
8
+c3smembership.mailaddr = c@c3s.cc
9
+c3smembership.offset = 15
10
+c3smembership.dashboard_number = 30
11
+c3smembership.adminpass = rut
12
+c3smembership.adminlogin = berries
13
+c3smembership.url = http://0.0.0.0:6543
14
+available_languages = de en
15
+# da es fr
16
+
17
+testing.mail_to_console = true
18
+
19
+[server:main]
20
+use = egg:waitress#main
21
+host = 0.0.0.0
22
+port = 6543

Loading…
Cancel
Save