3
'''py.test test cases to test OpenStudio.
5
These tests run based on webclient and need web2py server running.
10
from gluon.contrib.populate import populate
11
from populate_os_tables import prepare_classes
12
from populate_os_tables import populate_classes
13
from populate_os_tables import populate_customers
14
from populate_os_tables import populate_customers_with_subscriptions
15
from populate_os_tables import populate_customers_with_classcards
16
from populate_os_tables import populate_customers_payment_info
17
from populate_os_tables import populate_workshops_products_customers
18
from populate_os_tables import populate_workshops_with_activity
19
from populate_os_tables import populate_school_subscriptions
20
from populate_os_tables import populate_school_classcards
22
def test_customers_add(client, web2py):
26
client.get('/customers/add')
27
assert 'name="first_name"' in client.text
28
assert 'name="last_name"' in client.text
29
data = dict(first_name='Edwin',
30
last_name='van de Ven',
31
email='test@openstudioproject.com',
33
client.post('/customers/add', data=data)
34
assert client.status == 200
35
assert 'Profile' in client.text # verify redirection to edit page
37
client.get('/customers')
38
assert client.status == 200
39
assert data['first_name'] in client.text
40
assert data['last_name'] in client.text
41
assert not 'class="error"' in client.text # make sure the form validated
43
assert web2py.db(web2py.db.auth_user).count() == 2 # customer we just created and admin user
44
assert web2py.db(web2py.db.auth_user.first_name == data['first_name']).count() == 1
47
def test_customers_edit(client, web2py):
49
Can we edit a customer
51
populate_customers(web2py)
52
assert web2py.db(web2py.db.auth_user).count() > 0
54
url = '/customers/edit/1001'
56
assert client.status == 200
60
'first_name' : 'gorilla',
61
'last_name' : 'monkey',
62
'email' : 'gorilla@monkey.nl'
65
client.post(url, data=data)
66
assert client.status == 200
68
customer = web2py.db.auth_user(1001)
69
assert customer.first_name == data['first_name']
73
def test_customers_edit_teacher(client, web2py):
75
Is the edit teacher page accepting submitted data?
77
populate_customers(web2py, 2)
78
assert web2py.db(web2py.db.auth_user).count() > 0
80
url = '/customers/edit_teacher?cuID=1001'
82
assert client.status == 200
86
'teacher_bio' : 'bananas',
87
'education' : 'cherries',
88
'teacher_bio_link' : 'mangoes',
89
'teacher_website' : 'pineapple'
92
client.post(url, data=data)
93
assert client.status == 200
95
customer = web2py.db.auth_user(1001)
97
assert customer.teacher_bio == data['teacher_bio']
98
assert customer.teacher_website == data['teacher_website']
101
def test_customers_archive(client, web2py):
103
Can we archive a customer?
105
populate_customers(web2py, 1)
106
assert web2py.db(web2py.db.auth_user).count() == 1
109
client.get('/customers/archive?uID=1001')
110
assert client.status == 200
112
query = (web2py.db.auth_user.archived == True)
113
assert web2py.db(query).count() == 1
116
client.get('/customers/archive?uID=1001')
117
assert client.status == 200
119
query = (web2py.db.auth_user.archived == True)
120
assert web2py.db(query).count() == 0
123
def test_load_list_birthday_icon(client, web2py):
125
Is the birthday icon showing in load_list
127
populate_customers(web2py, 1)
129
# make it the first customers' birthday today
130
today = datetime.date.today()
131
customer = web2py.db.auth_user(1001)
132
customer.date_of_birth = today
133
customer.birthday = datetime.date(1900, today.month, today.day)
134
customer.update_record()
138
url = '/customers/load_list?list_type=customers_index&initial_list=True&archived=False&items_per_page=7'
140
assert client.status == 200
141
assert 'fa-birthday-cake' in client.text
144
def populate_account_merge(client, web2py):
146
Populates all tables with reference to auth_user for user 1002
147
Also created user 1001 so we have an id to merge into
149
# get a random url to initialize payment methods
150
url = '/default/user/login'
152
assert client.status == 200
157
prepare_classes(web2py, nr_of_customers=2, cuID=merge_from_id)
158
# let's make merge_from_id a teacher as well
159
user = web2py.db.auth_user(merge_from_id)
164
populate_customers_payment_info(web2py, 2)
166
# remove payment info for merge_into_id, so we're sure that the info from merge_from_id appears in the test data
167
query = (web2py.db.customers_payment_info.auth_customer_id == merge_into_id)
168
web2py.db(query).delete()
170
populate_school_subscriptions(web2py)
171
web2py.db.customers_subscriptions.insert(
172
auth_customer_id = merge_from_id,
173
school_subscriptions_id = 1,
174
Startdate = '2014-01-01',
175
payment_methods_id = 3
178
populate_school_classcards(web2py)
179
web2py.db.customers_classcards.insert(
180
auth_customer_id = merge_from_id,
181
school_classcards_id = 1,
182
Startdate = '2014-01-01',
183
Enddate = '2014-01-31'
186
web2py.db.customers_notes.insert(
187
auth_customer_id = merge_from_id,
188
auth_user_id = merge_from_id, # to check if the task assignment also mergesz
189
BackofficeNote = True,
190
NoteDate = '2014-01-01',
195
web2py.db.tasks.insert(
196
auth_customer_id = merge_from_id,
197
Task = 'Fix some bugs',
198
Description = 'Test',
199
Duedate = '2014-02-01',
200
auth_user_id = merge_from_id, # to check if the task assignment also merges
203
web2py.db.alternativepayments.insert(
204
auth_customer_id = merge_from_id,
211
iID = web2py.db.invoices.insert(
212
invoices_groups_id = 100,
213
auth_customer_id = merge_from_id,
214
payment_methods_id = 3,
216
InvoiceID = 'INV' + unicode(merge_from_id),
217
DateCreated = '2014-01-01',
218
DateDue = '2014-01-31'
221
web2py.db.invoices_amounts.insert(invoices_id = iID)
223
web2py.db.payment_batches.insert(
224
BatchType = 'collection',
226
Description = 'test',
229
Exdate = '2014-01-01'
231
web2py.db.payment_batches_items.insert(
232
payment_batches_id = 1,
233
auth_customer_id = merge_from_id,
236
web2py.db.customers_payments.insert(
237
auth_customer_id = merge_from_id,
239
PaymentDate = '2014-01-01',
240
payment_methods_id = 3,
243
web2py.db.customers_documents.insert(
244
auth_customer_id = merge_from_id,
245
Description = 'test',
246
DocumentFile = 'DocumentFile.txt',
249
populate(web2py.db.messages, 1)
250
web2py.db.customers_messages.insert(
251
auth_customer_id = merge_from_id,
256
populate_workshops_with_activity(web2py, teachers=False)
257
web2py.db.workshops_products_customers.insert(
258
auth_customer_id = merge_from_id,
259
workshops_products_id = 1
261
web2py.db.workshops_activities_customers.insert(
262
auth_customer_id = merge_from_id,
263
workshops_activities_id = 1
266
# customer tables end
268
# teacher tables begin
270
web2py.db.teachers_holidays.insert(
271
auth_teacher_id = merge_from_id,
272
Startdate = '2014-01-01',
273
Enddate = '2014-01-31',
274
Note = 'Winter holiday'
277
web2py.db.teachers_classtypes.insert(
278
auth_user_id = merge_from_id,
279
school_classtypes_id = 1
282
cl_te = web2py.db.classes_teachers(1) # from prepare_classes
283
cl_te.auth_teacher_id = merge_from_id
284
cl_te.auth_teacher_id2 = merge_from_id
285
cl_te.update_record()
287
web2py.db.classes_subteachers.insert(
289
ClassDate = '2014-01-06',
290
auth_teacher_id = merge_from_id,
291
auth_teacher_id2 = merge_from_id
294
workshop = web2py.db.workshops(1)
295
workshop.auth_teacher_id = merge_from_id
296
workshop.auth_teacher_id2 = merge_from_id
297
workshop.update_record()
299
wsa = web2py.db.workshops_activities(1)
300
wsa.auth_teacher_id = merge_from_id
301
wsa.auth_teacher_id2 = merge_from_id
308
web2py.db.payment_batches_exports.insert(
309
auth_user_id = merge_from_id,
310
payment_batches_id = 1,
318
def test_account_merge(client, web2py):
320
Can we merge an account?
321
We'll create 2 customers, attach all data to 2nd customer,
322
then merge into first and check if we still have all data.
324
def assert_count_customer(table, count):
325
print 'Testing customer table: ' + unicode(table)
326
query = (table.auth_customer_id == 1001)
327
#print web2py.db().select(table.ALL)
329
assert web2py.db(query).count() == count
332
def assert_count_user(table, count):
333
print 'Testing user table: ' + unicode(table)
334
query = (table.auth_user_id == 1001)
335
assert web2py.db(query).count() == count
338
def assert_count_teacher(table, count):
339
print 'Testing teacher table: ' + unicode(table)
340
query = (table.auth_teacher_id == 1001)
341
assert web2py.db(query).count() == count
344
def assert_count_teacher2(table, count):
345
print 'Testing teacher2 table: ' + unicode(table)
346
query = (table.auth_teacher_id2 == 1001)
347
assert web2py.db(query).count() == count
350
populate_account_merge(client, web2py)
354
url = '/customers/account_merge_execute?cuID=1001&auth_merge_id=' + unicode(auth_merge_id)
356
assert client.status == 200
358
## check all tables in the DB
360
[ 1, web2py.db.alternativepayments ],
361
[ 4, web2py.db.classes_attendance ],
362
[ 3, web2py.db.classes_reservation ],
363
[ 1, web2py.db.classes_waitinglist ],
364
[ 3, web2py.db.customers_classcards ],
365
[ 1, web2py.db.customers_documents ],
366
[ 1, web2py.db.customers_messages ],
367
[ 2, web2py.db.customers_payment_info ],
368
[ 1, web2py.db.customers_payments ],
369
[ 3, web2py.db.customers_subscriptions ],
370
[ 1, web2py.db.customers_notes ],
371
[ 1, web2py.db.invoices ],
372
[ 1, web2py.db.payment_batches_items ],
373
[ 1, web2py.db.tasks ],
374
[ 1, web2py.db.workshops_activities_customers ],
375
[ 1, web2py.db.workshops_products_customers ]
378
for count, table in customer_tables:
379
assert_count_customer(table, count)
382
[ 1, web2py.db.customers_notes ],
383
[ 1, web2py.db.payment_batches_exports ],
384
[ 1, web2py.db.tasks ],
387
for count, table in auth_user_tables:
388
assert_count_user(table, count)
390
auth_teacher_tables = [
391
[ 1, web2py.db.classes_teachers ],
392
[ 1, web2py.db.classes_subteachers ],
393
[ 1, web2py.db.teachers_holidays ],
394
[ 1, web2py.db.workshops ],
395
[ 1, web2py.db.workshops_activities ],
398
for count, table in auth_teacher_tables:
399
assert_count_teacher(table, count)
401
auth_teacher2_tables = [
402
[ 1, web2py.db.classes_teachers ],
403
[ 1, web2py.db.classes_subteachers ],
404
[ 1, web2py.db.workshops ],
405
[ 1, web2py.db.workshops_activities ],
408
for count, table in auth_teacher2_tables:
409
assert_count_teacher2(table, count)
412
# check if the user is a teacher now
413
user = web2py.db.auth_user(1001)
414
assert user.teacher == True
415
assert user.enabled == True
418
merged_user = web2py.db.auth_user(1002)
419
assert merged_user.merged
420
assert merged_user.merged_into == 1001
421
assert not merged_user.merged_on is None
423
# verify the flash message
424
assert 'Merge success' in client.text
427
def test_customers_subscription_add(client, web2py):
429
Can we add a customers_subscription?
431
populate_school_subscriptions(web2py)
432
populate_customers(web2py)
433
assert web2py.db(web2py.db.school_subscriptions).count() > 0
434
assert web2py.db(web2py.db.auth_user).count() > 0
436
url = '/customers/subscription_add/?cuID=1'
439
assert client.status == 200
441
data = dict(school_subscriptions_id='1',
442
Startdate='2014-01-01',
444
client.post(url, data=data)
445
assert client.status == 200
446
assert web2py.db(web2py.db.customers_subscriptions).count() == 1
448
mstype_name = web2py.db.school_subscriptions(1).Name
450
client.get('/customers/subscriptions?cuID=1')
451
assert client.status == 200
452
assert mstype_name in client.text
455
def populate_customer_subscriptions(client, web2py):
456
# get random url to initialize payment methods in db
457
url = '/default/user/login'
459
assert client.status == 200
461
populate_school_subscriptions(web2py)
462
populate_customers(web2py)
463
web2py.db.customers_subscriptions.insert(
464
auth_customer_id = 1001,
465
school_subscriptions_id = 1,
466
Startdate = '2014-01-01',
467
payment_methods_id = 3,
468
Note = "Hello world!")
472
assert web2py.db(web2py.db.school_subscriptions).count() > 0
473
assert web2py.db(web2py.db.auth_user).count() > 0
474
assert web2py.db(web2py.db.customers_subscriptions).count() > 0
477
def populate_customer_subscriptions_paused(client, web2py):
479
Adds pause to subcription starting from 2014-01-01
481
populate_customer_subscriptions(client, web2py)
483
web2py.db.customers_subscriptions_paused.insert(
484
customers_subscriptions_id = 1,
485
Startdate = '2014-01-01',
486
Enddate = '2014-01-31',
487
Description = 'Bananas')
492
def test_customers_subscription_edit(client, web2py):
494
can we edit a subscription?
496
populate_customer_subscriptions(client, web2py)
498
url = '/customers/subscription_edit?cuID=1001&csID=1'
501
assert client.status == 200
502
assert web2py.db(web2py.db.customers_subscriptions).count() == 1
505
school_subscriptions_id = '1',
506
Startdate = '2016-01-01',
508
client.post(url, data=data)
509
assert client.status == 200
511
assert 'Subscriptions' in client.text # verify redirection to customers/subscriptions
512
assert data['Startdate'] in client.text
515
def test_customers_subscription_delete(client, web2py):
517
Is the custom delete function for customer subscriptions working?
519
# get random url to initialize payment methods
520
url = '/default/user/login'
522
assert client.status == 200
524
populate_customers_with_subscriptions(web2py, 2)
526
# insert invoice and check that the subscription isn't deletable anymore
527
web2py.db.invoices.insert(
528
invoices_groups_id = 100,
529
auth_customer_id = 1001,
530
customers_subscriptions_id = 1,
531
SubscriptionMonth = 1,
532
SubscriptionYear = 2014,
534
DateCreated = '2014-01-01',
535
DateDue = '2014-01-31',
540
url = '/customers/subscription_delete?cuID=1001&csID=1'
542
assert client.status == 200
544
assert 'Unable to delete' in client.text
546
# now remove invoices and try again
547
web2py.db(web2py.db.invoices.id > 0).delete()
550
url = '/customers/subscription_delete?cuID=1001&csID=1'
552
assert client.status == 200
554
assert 'Deleted subscription' in client.text
557
def test_customers_subscriptions_list_recent_pauses(client, web2py):
559
Is the list of paused subscriptions showing?
561
# get random url to initialize payment methods in db
562
url = '/default/user/login'
564
assert client.status == 200
566
populate_customer_subscriptions_paused(client, web2py)
568
assert web2py.db(web2py.db.customers_subscriptions).count() == 1
570
client.get('/customers/subscriptions?cuID=1001')
571
assert client.status == 200
572
assert 'Pauses' in client.text
574
# check recent pauses
575
assert '2014-01-01 - 2014-01-31' in client.text
578
def test_customers_subscriptions_pauses(client, web2py):
580
Is the list of pauzed showing?
582
# get random url to initialize payment methods in db
583
url = '/default/user/login'
585
assert client.status == 200
587
populate_customer_subscriptions_paused(client, web2py)
589
assert web2py.db(web2py.db.customers_subscriptions).count() == 1
591
client.get('/customers/subscription_pauses?csID=1&cuID=1001')
592
assert client.status == 200
593
assert 'Pauses' in client.text
596
pause = web2py.db.customers_subscriptions_paused(1)
597
assert pause.Description in client.text
600
def test_customers_subscriptions_pause_add(client, web2py):
602
Test adding of a pause
604
# get random url to initialize payment methods in db
605
url = '/default/user/login'
607
assert client.status == 200
609
populate_customer_subscriptions(client, web2py)
611
url = '/customers/subscription_pause_add?csID=1'
613
assert client.status == 200
615
data = {'from_month' : '1',
616
'from_year' : '2014',
619
'description' : 'Custard apple'}
620
client.post(url, data=data)
621
assert client.status == 200
624
assert 'Subscriptions' in client.text
627
assert data['description'] in client.text
630
assert web2py.db(web2py.db.customers_subscriptions_paused).count() == 1
633
def test_classcard_add_classic(client, web2py):
635
Add a classcard using a drop down menu
637
populate_school_classcards(web2py, 8, trialcard = True)
638
populate_customers(web2py, 1)
640
# check redirection of add_classcard
641
url = '/customers/classcard_add?cuID=1'
643
assert client.status == 200
644
assert not 'panel-primary' in client.text
646
# check automatic calculating of enddate
647
url = '/customers/classcard_add_classic?cuID=1'
648
data = {'school_classcards_id' : 1,
649
'Startdate' : '2014-01-01',
651
client.post(url, data=data)
652
assert client.status == 200
655
assert web2py.db(web2py.db.customers_classcards).count() == 1
656
# check automatich adding of enddate
657
assert web2py.db.customers_classcards(1).Enddate == datetime.date(2014, 3, 31)
659
# check classcard invoice
660
check_classcard_invoice(web2py)
663
def check_classcard_invoice(web2py):
665
Check if an invoice is created correctly after adding a classcard
668
assert web2py.db(web2py.db.invoices).count() == 1
669
invoice = web2py.db.invoices(1)
670
assert invoice.invoices_groups_id == 100
672
iccd = web2py.db.invoices_customers_classcards(1)
673
assert iccd.customers_classcards_id == 1
675
price = web2py.db.school_classcards(1).Price
676
invoice_amount = web2py.db.invoices_amounts(1).TotalPriceVAT
678
assert price == invoice_amount
681
def test_classcard_add_classic_trialcard_removed_after_getting_one(client, web2py):
683
Check that the trialcard options are no longer listed
686
populate_school_classcards(web2py, nr_cards, trialcard = True)
687
populate_customers(web2py, 1)
689
trialcard_id = nr_cards + 1
691
web2py.db.customers_classcards.insert(
692
auth_customer_id = 1001,
693
school_classcards_id = trialcard_id,
694
Startdate = '2014-01-01',
695
Enddate = '2014-01-31',
700
assert web2py.db(web2py.db.customers_classcards).count() == 1
702
# check automatic calculating of enddate
703
url = '/customers/classcard_add_classic?cuID=1001'
705
assert client.status == 200
706
assert web2py.db.school_classcards(trialcard_id).Name not in client.text
709
def test_classcard_add_modern(client, web2py):
711
Add a classcard using fancy layout
713
populate_school_classcards(web2py, 6, trialcard = True)
714
populate_customers(web2py, 1)
716
# check redirection of add_classcard
717
url = '/customers/classcard_add?cuID=1'
719
assert client.status == 200
720
assert 'panel-primary' in client.text # now we're on the modern one
721
# check automatic calculating of enddate
723
# check automatic calculating of enddate
724
url = '/customers/classcard_add_modern_add_card?cuID=1&scdID=1'
725
data = {'school_classcards_id' : 1,
726
'Startdate' : '2014-01-01',
728
client.post(url, data=data)
729
assert client.status == 200
732
assert web2py.db(web2py.db.customers_classcards).count() == 1
733
# check automatich adding of enddate
734
assert web2py.db.customers_classcards(1).Enddate == datetime.date(2014, 3, 31)
736
# check classcard invoice
737
check_classcard_invoice(web2py)
740
def test_classcard_add_modern_trialcard_removed_after_getting_one(client, web2py):
742
Check that the trialcard options are no longer listed
745
populate_school_classcards(web2py, nr_cards, trialcard = True)
746
populate_customers(web2py, 1)
748
trialcard_id = nr_cards + 1
750
web2py.db.customers_classcards.insert(
751
auth_customer_id = 1001,
752
school_classcards_id = trialcard_id,
753
Startdate = '2014-01-01',
754
Enddate = '2014-01-31',
759
assert web2py.db(web2py.db.customers_classcards).count() == 1
761
# check that the trialcard isn't listed
762
url = '/customers/classcard_add_modern?cuID=1001'
764
assert client.status == 200
765
assert not web2py.db.school_classcards(trialcard_id).Name in client.text
768
def test_classcard_edit(client, web2py):
770
can we edit a classcard?
773
populate_school_classcards(web2py, nr_cards, trialcard = True)
774
populate_customers(web2py, 1)
776
trialcard_id = nr_cards + 1
778
web2py.db.customers_classcards.insert(
779
auth_customer_id = 1001,
780
school_classcards_id = 1,
781
Startdate = '2014-01-01',
782
Enddate = '2014-01-31',
787
assert web2py.db(web2py.db.auth_user).count() > 0
788
assert web2py.db(web2py.db.customers_classcards).count() > 0
790
url = '/customers/classcard_edit?cuID=1001&ccdID=1'
792
assert client.status == 200
795
Startdate='2016-01-01',
796
Enddate='2016-02-01',
797
Note='Mango smoothie')
798
client.post(url, data=data)
799
assert client.status == 200
801
assert 'Class cards' in client.text # check redirection
802
assert data['Startdate'] in client.text # check form submission
803
assert data['Enddate'] in client.text
806
def test_classcard_classes_taken(client, web2py):
808
Is the list of classes taken on a class card working?
809
Is classes_otc applied to this list?
811
populate_classes(web2py, with_otc=True)
812
populate_customers_with_classcards(web2py)
814
web2py.db.classes_attendance.insert(
816
ClassDate = '2014-01-06',
817
auth_customer_id = 1001,
818
customers_classcards_id = 1,
824
url = '/customers/classcard_classes?ccID=1'
826
assert client.status == 200
828
# check classes_otc application
829
location = web2py.db.school_locations(2).Name.split(' ')[0]
830
assert location in client.text
832
classtype = web2py.db.school_classtypes(2).Name.split(' ')[0]
833
assert classtype in client.text
836
def test_classes_reservations_recurring(client, web2py):
838
List reservations for a customer (this is the default)
840
prepare_classes(web2py)
842
url = '/customers/classes_reservations?cuID=1001'
844
assert client.status == 200
846
location_name = web2py.db.school_locations(1).Name.split(' ')[0]
847
# make sure one reservation is showing
848
assert client.text.count(location_name) == 1
851
def test_classes_reservations_filter_single(client, web2py):
853
Check filter for single classes
855
prepare_classes(web2py)
857
url = '/customers/classes_reservations?cuID=1001&filter=single'
859
assert client.status == 200
861
location_name = web2py.db.school_locations(1).Name.split(' ')[0]
862
# make sure one reservation is showing
863
assert client.text.count(location_name) == 1
866
def test_classes_reservations_filter_trial(client, web2py):
868
Check filter for trialclasses
870
prepare_classes(web2py)
872
url = '/customers/classes_reservations?cuID=1001&filter=trial'
874
assert client.status == 200
876
location_name = web2py.db.school_locations(1).Name.split(' ')[0]
877
# make sure one reservation is showing
878
assert client.text.count(location_name) == 1
881
def test_classes_reservation_add_list_classes_for_date(client, web2py):
883
Does the listing of classes for a specified date work?
885
prepare_classes(web2py)
886
# we'll have to use a Monday ^ the function above only adds a class on Monday
887
url = '/customers/classes_reservation_add?cuID=1001&date=2014-01-06'
889
assert client.status == 200
891
# check if we have a location and an add button
892
assert 'Add' in client.text
893
location_name = web2py.db.school_locations(1).Name.split(' ')[0]
894
assert client.text.count(location_name) == 1
899
Reservation add and edit are tested in the classes controller
904
def test_classes_waitinglist(client, web2py):
906
Waitinglist for a customer
908
prepare_classes(web2py)
910
url = '/customers/classes_waitinglist?cuID=1001'
912
assert client.status == 200
914
#print web2py.db().select(web2py.db.classes_waitinglist.ALL)
916
location_name = web2py.db.school_locations(1).Name.split(' ')[0]
917
# make sure one reservation is showing
918
assert client.text.count(location_name) == 1
921
def test_classes_attendance(client, web2py):
923
Attendance for a customer
925
prepare_classes(web2py)
927
url = '/customers/classes_attendance?cuID=1001'
929
assert client.status == 200
931
location_name = web2py.db.school_locations(1).Name.split(' ')[0]
932
# make sure one reservation is showing
933
assert client.text.count(location_name) == 3
936
def test_payments_info_add(client, web2py):
938
Can we add info for a customer?
940
populate_customers(web2py)
941
assert web2py.db(web2py.db.auth_user).count() > 0
943
url = '/customers/payment_info_add/1001'
945
assert client.status == 200
947
data = dict(payments_methods_id='3',
948
AccountNumber='123456',
949
AccountHolder='Hello',
951
MandateSignatureDate='2014-01-01',
955
client.post(url, data=data)
956
assert client.status == 200
957
assert "info" in client.text # check redirection
958
assert data['AccountNumber'] in client.text
960
client.get(url) # check if we can add only once
961
assert client.status == 200
962
assert 'already' in client.text
964
def test_payments_info_edit(client, web2py):
966
Can we edit info for a customer?
968
populate_customers(web2py, 1)
970
# get a random url to make sure the setup function runs to populate the
971
# payment_methods table
972
url = '/customers/index'
974
assert client.status == 200
976
web2py.db.customers_payment_info.insert(auth_customer_id = 1001,
977
payment_methods_id = 3)
979
assert web2py.db(web2py.db.auth_user).count() > 0
980
assert web2py.db(web2py.db.customers_payment_info).count() == 1
982
url = '/customers/payment_info_edit/1001/1'
985
assert client.status == 200
988
auth_customer_id = 1001,
989
payment_methods_id='3',
990
AccountNumber='123456',
991
AccountHolder='Hello',
993
MandateSignatureDate='2014-01-01',
997
client.post(url, data=data)
998
assert client.status == 200
999
assert "info" in client.text # check redirection
1000
assert data['AccountNumber'] in client.text
1003
def test_payments_ap_add(client, web2py):
1005
Can we add an alternative payment?
1007
today = datetime.date.today()
1008
populate_customers(web2py, 1)
1009
assert web2py.db(web2py.db.auth_user).count() == 1
1011
url = '/customers/alternativepayment_add/1001'
1013
assert client.status == 200
1015
assert 'value="' + unicode(today.year) + '"' in client.text # check default year value
1016
assert 'selected="selected" value="' + unicode(today.month) + '"' in client.text # check default month value
1018
data = dict(PaymentYear=today.year,
1019
PaymentMonth=today.month,
1022
client.post(url, data=data)
1023
assert client.status == 200
1024
assert "info" in client.text # check redirection
1025
assert data['Amount'] in client.text
1027
def test_payments_ap_edit(client, web2py):
1029
Can we edit an alternative payment?
1031
populate_customers(web2py, 1)
1032
populate(web2py.db.payment_categories, 4)
1033
populate(web2py.db.alternativepayments, 1)
1034
assert web2py.db(web2py.db.auth_user).count() == 1
1035
assert web2py.db(web2py.db.alternativepayments).count() > 0
1037
url = '/customers/alternativepayment_edit/1001/1'
1039
assert client.status == 200
1041
data = dict(PaymentYear='2015',
1045
client.post(url, data=data)
1046
assert client.status == 200
1047
assert "info" in client.text # check redirection
1048
assert data['Amount'] in client.text
1051
def test_documents(client, web2py):
1053
Can we get a list of the documents available?
1055
populate_customers(web2py, 1)
1056
assert web2py.db(web2py.db.auth_user).count() == 1
1058
url = '/customers/documents?cuID=1001'
1060
assert client.status == 200
1061
assert "Documents" in client.text
1064
def test_notes(client, web2py):
1066
Can we get a list of notes and add a new note?
1068
populate_customers(web2py, 1)
1069
assert web2py.db(web2py.db.auth_user).count() == 1
1072
url = '/customers/notes?cuID=1001'
1074
assert client.status == 200
1077
data = dict(Note='Bananas',
1079
client.post(url, data=data)
1080
assert client.status == 200
1081
assert "Add a new note" in client.text # check if we're at the notes page
1082
assert data['Note'] in client.text
1085
url = '/customers/note_delete.json'
1088
client.post(url, data=data)
1089
assert client.status == 200
1091
assert web2py.db(web2py.db.customers_notes).count() == 0
1094
def test_workshops(client, web2py):
1096
Test display of workshops
1098
populate_workshops_products_customers(web2py)
1100
url = '/customers/workshops?cuID=1001'
1102
assert client.status == 200
1104
workshop = web2py.db.workshops(1)
1105
assert workshop.Name.split(' ')[0] in client.text
1106
# check label (product 2 is defined for cuID 1 in populate function)
1107
product = web2py.db.workshops_products(2)
1108
assert product.Name.split(' ')[0] in client.text
1109
# check payment and info form
1110
assert 'Workshop Info' in client.text
1113
def test_workshops_add(client, web2py):
1115
Is the list of workshops showing?
1117
populate_workshops_products_customers(web2py)
1119
url = '/customers/workshops_add?cuID=1001'
1121
assert client.status == 200
1123
# check that the workshop is listed
1124
workshop = web2py.db.workshops(1)
1125
assert workshop.Name.split(' ')[0] in client.text
1126
# assert that the products button is showing
1127
assert 'Products' in client.text
1130
def test_workshop_add_list_products(client, web2py):
1132
Is the list of workshop products showing from a customer?
1134
populate_workshops_products_customers(web2py)
1136
url = '/customers/workshops_add_list_products?cuID=1001&wsID=1'
1138
assert client.status == 200
1140
# check if the name of the workshop is showing
1141
workshop = web2py.db.workshops(1)
1142
assert workshop.Name.split(' ')[0] in client.text
1144
# check if the add button is showing
1145
assert 'Add' in client.text
1146
assert 'waitinglist' in client.text
1149
# def test_load_list_sell_workshop_product(client, web2py):
1151
# Test if the list shows
1153
# populate_workshops_products_customers(web2py)
1155
# url = '/customers/load_list?list_type=workshops_products_sell&wsID=1&wspID=1'
1157
# assert client.status == 200
1159
# customer = web2py.db.auth_user(1001)
1160
# assert customer.first_name in client.text
1163
def test_payment_info_dutch_iban_validator_length_fail(client, web2py):
1165
Checks if the validator fails when the length of the number is too short
1167
# by getting some page the payment methods get initialized
1168
url = '/default/user/login'
1170
assert client.status == 200
1172
populate_customers(web2py, 1)
1173
populate_customers_payment_info(web2py, 1)
1175
url = '/customers/payment_info_edit/1001/1'
1177
assert client.status == 200
1180
'AccountNumber' : 'NL21INGB012345678'} # 1 digit too short for valid Dutch IBAN
1181
client.post(url, data=data)
1182
assert client.status == 200
1184
assert 'Dutch IBAN should be 18 characters' in client.text
1187
def test_payment_info_dutch_iban_validator_validation_fail(client, web2py):
1189
Checks if the validator fails when the IBAN isn't valid
1191
# by getting some page the payment methods get initialized
1192
url = '/default/user/login'
1194
assert client.status == 200
1196
populate_customers(web2py, 1)
1197
populate_customers_payment_info(web2py, 1)
1199
url = '/customers/payment_info_edit/1001/1'
1201
assert client.status == 200
1204
'AccountNumber' : 'NL21INGB0123456789'} # Invalid Dutch IBAN
1205
client.post(url, data=data)
1206
assert client.status == 200
1208
assert 'IBAN validation failed' in client.text
1211
def test_payment_info_dutch_iban_validator_pass(client, web2py):
1213
Checks if the validator passes on a correct number
1215
# by getting some page the payment methods get initialized
1216
url = '/default/user/login'
1218
assert client.status == 200
1220
populate_customers(web2py, 1)
1221
populate_customers_payment_info(web2py, 1)
1223
url = '/customers/payment_info_edit/1001/1'
1225
assert client.status == 200
1228
'AccountNumber' : 'NL89TRIO0390502103'} # Valid Dutch IBAN
1229
client.post(url, data=data)
1230
assert client.status == 200
1232
# verify redirection
1233
assert 'Payment info' in client.text
1236
row = web2py.db.customers_payment_info(1)
1237
assert row.AccountNumber == data['AccountNumber']
1240
def test_payment_info_not_iban_pass(client, web2py):
1242
Checks if the validator passes when something other than a dutch IBAN nr is added
1244
# by getting some page the payment methods get initialized
1245
url = '/default/user/login'
1247
assert client.status == 200
1249
populate_customers(web2py, 1)
1250
populate_customers_payment_info(web2py, 1)
1252
url = '/customers/payment_info_edit/1001/1'
1254
assert client.status == 200
1257
'AccountNumber' : '12445565ef39i65'} # Random stuff
1258
client.post(url, data=data)
1259
assert client.status == 200
1261
# verify redirection
1262
assert 'Payment info' in client.text
1265
row = web2py.db.customers_payment_info(1)
1266
assert row.AccountNumber == data['AccountNumber'].upper()