-
Notifications
You must be signed in to change notification settings - Fork 23
/
test_suppliers.py
3022 lines (2524 loc) · 124 KB
/
test_suppliers.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# coding=utf-8
from datetime import datetime
from urllib.parse import urlparse
from flask import session, current_app
from lxml import html
import mock
import pytest
from werkzeug.exceptions import ServiceUnavailable
from dmapiclient import APIError, HTTPError
from dmapiclient.audit import AuditTypes
from dmtestutils.api_model_stubs import FrameworkStub, SupplierFrameworkStub
from tests.app.helpers import BaseApplicationTest, assert_args_and_return
from app.main.forms.suppliers import CompanyOrganisationSizeForm, CompanyTradingStatusForm
def framework_stub_dates(month):
return {
'applications_close_at': datetime(2000, month, 3),
'intention_to_award_at': datetime(2000, month, 4),
'clarifications_close_at': datetime(2000, month, 1),
'clarifications_publish_at': datetime(2000, month, 2),
'framework_live_at': datetime(2000, month, 5),
}
FIND_FRAMEWORKS_RETURN_VALUE = {
"frameworks": [
FrameworkStub(
status='expired',
slug='h-cloud-88',
name='H-Cloud 88',
framework_family='g-cloud',
**framework_stub_dates(1)
).response(),
FrameworkStub(status='live', slug='g-cloud-6', **framework_stub_dates(2)).response(),
FrameworkStub(status='open', slug='digital-outcomes-and-specialists', **framework_stub_dates(4)).response(),
FrameworkStub(
status='live',
slug='digital-rhymes-and-reasons',
name='Digital Rhymes and Reasons',
framework_family='digital-outcomes-and-specialists',
**framework_stub_dates(3)
).response(),
FrameworkStub(status='open', slug='g-cloud-7', **framework_stub_dates(5)).response(),
]
}
def get_supplier(*args, **kwargs):
supplier_info = {
"id": 1234,
"dunsNumber": "987654321",
"companiesHouseNumber": "CH123456",
"registeredName": "Official Name Inc",
"registrationCountry": "country:BZ",
"otherCompanyRegistrationNumber": "BEL153",
"organisationSize": "small",
"tradingStatus": "Open for business",
"name": "Supplier Name",
"description": "Supplier Description",
"companyDetailsConfirmed": True,
"contactInformation": [{
"id": 2,
"website": "supplier.dmdev",
"email": "supplier@user.dmdev",
"contactName": "Supplier Person",
"phoneNumber": "0800123123",
"address1": "1 Street",
"address2": "2 Building",
"city": "Supplierville",
"country": "Supplierland",
"postcode": "11 AB",
}],
"service_counts": {
"G-Cloud 6": 12,
"G-Cloud 5": 34
}
}
supplier_info.update(kwargs)
return {"suppliers": dict(
filter(lambda x: x[1] is not None, supplier_info.items())
)}
def get_user():
return [{
'id': 123,
'name': "User Name",
'emailAddress': "email@email.com",
'loggedInAt': "2015-05-06T11:57:28.008690Z",
'locked': False,
'active': True,
'role': 'supplier',
'supplier': {
'name': "Supplier Name",
'supplierId': 1234,
'supplierOrganisationSize': 'small'
}
}]
class TestSuppliersDashboard(BaseApplicationTest):
def setup_method(self, method):
super().setup_method(method)
self.data_api_client_patch = mock.patch('app.main.views.suppliers.data_api_client', autospec=True)
self.data_api_client = self.data_api_client_patch.start()
def teardown_method(self, method):
self.data_api_client_patch.stop()
super().teardown_method(method)
def test_error_and_success_flashed_messages_only_are_shown_in_banner_messages(self):
with self.client.session_transaction() as session:
session['_flashes'] = [
('error', 'This is an error'),
('success', 'This is a success'),
('track-page-view', '/suppliers?account-created=true')
]
self.data_api_client.get_framework.return_value = self.framework('open')
self.data_api_client.get_supplier.side_effect = get_supplier
self.data_api_client.find_audit_events.return_value = {
"auditEvents": []
}
self.login()
res = self.client.get("/suppliers")
data = self.strip_all_whitespace(res.get_data(as_text=True))
assert '<pclass="banner-message">Thisisanerror</p>' in data
assert '<pclass="banner-message">Thisisasuccess</p>' in data
assert '<pclass="banner-message">account-created</p>' not in data
def test_data_analytics_track_page_view_is_shown_if_account_created_flag_flash_message(self):
with self.client.session_transaction() as session:
session['_flashes'] = [('track-page-view', '/suppliers?account-created=true')]
self.login()
res = self.client.get("/suppliers")
data = res.get_data(as_text=True)
assert 'data-analytics="trackPageView" data-url="/suppliers?account-created=true"' in data
def test_data_analytics_track_page_view_is_not_shown_if_no_account_created_flag_flash_message(self):
self.login()
res = self.client.get("/suppliers")
data = res.get_data(as_text=True)
assert 'data-analytics="trackPageView" data-url="/suppliers?account-created=true"' not in data
def test_shows_edit_buttons(self):
self.data_api_client.get_supplier.side_effect = get_supplier
self.data_api_client.find_frameworks.return_value = FIND_FRAMEWORKS_RETURN_VALUE
self.data_api_client.get_supplier_frameworks.return_value = {
'frameworkInterest': [
{
'frameworkSlug': 'h-cloud-88',
'services_count': 12,
"onFramework": True,
"agreementReturned": True,
},
{
'frameworkSlug': 'g-cloud-6',
'services_count': 99,
"onFramework": True,
"agreementReturned": True,
},
],
}
self.login()
res = self.client.get("/suppliers")
assert res.status_code == 200
document = html.fromstring(res.get_data(as_text=True))
assert document.xpath(
"//*[(.//h3)[1][normalize-space(string())=$f]][.//a[normalize-space(string())=$t][@href=$u]]",
f="G-Cloud 6",
t="View services",
u="/suppliers/frameworks/g-cloud-6/services",
)
assert not document.xpath(
"//*[(.//h3)[1][normalize-space(string())=$f]][.//a[normalize-space(string())=$t]]",
f="G-Cloud 7",
t="View services",
)
assert not document.xpath("//a[@href=$u]", u="/suppliers/frameworks/g-cloud-7/services")
assert not document.xpath(
"//*[(.//h3)[1][normalize-space(string())=$f]][.//a[normalize-space(string())=$t]]",
f="H-Cloud 88",
t="View services",
)
assert not document.xpath("//a[@href=$u]", u="/suppliers/frameworks/h-cloud-88/services")
assert not document.xpath(
"//*[(.//h3)[1][normalize-space(string())=$f]][.//a[normalize-space(string())=$t]]",
f="Digital Rhymes and Reasons",
t="View services",
)
assert not document.xpath("//a[@href=$u]", u="/suppliers/frameworks/digital-rhymes-and-reasons/services")
@pytest.mark.parametrize('on_framework', (True, False))
def test_only_shows_expired_dos3_if_supplier_was_on_framework(self, on_framework):
self.data_api_client.get_supplier.side_effect = get_supplier
self.data_api_client.find_frameworks.return_value = {
"frameworks": [
FrameworkStub(status='expired', slug='digital-outcomes-and-specialists-3').response(),
]
}
self.data_api_client.get_supplier_frameworks.return_value = {
'frameworkInterest': [
{
'frameworkSlug': 'digital-outcomes-and-specialists-3',
'onFramework': on_framework,
}
]
}
self.login()
response = self.client.get("/suppliers")
assert response.status_code == 200
document = html.fromstring(response.get_data(as_text=True))
if on_framework:
assert document.xpath(
"//h3[normalize-space(string())=$f]"
"[(following::a)[1][normalize-space(string())=$t1][@href=$u1]]",
f="Digital Outcomes and Specialists 3",
t1="View your opportunities",
u1="/suppliers/opportunities/frameworks/digital-outcomes-and-specialists-3",
)
assert not document.xpath(
"//h3[normalize-space(string())=$f]"
"/..//a[normalize-space(string())=$t1]",
f="Digital Outcomes and Specialists 3",
t1="View services",
)
assert not document.xpath(
"//h3[normalize-space(string())=$f]"
"/..//a[normalize-space(string())=$t1]",
f="Digital Outcomes and Specialists 3",
t1="View documents",
)
else:
assert not document.xpath("//h3[normalize-space(string())='Digital Outcomes and Specialists 3']")
def test_shows_correct_expired_framework(self):
self.data_api_client.get_supplier.side_effect = get_supplier
self.data_api_client.find_frameworks.return_value = {
"frameworks": [
FrameworkStub(
status='expired',
slug='digital-outcomes-and-specialists-2',
frameworkExpiresAtUTC='2000-01-01T01:00:00.000000Z'
).response(),
FrameworkStub(
status='expired',
slug='digital-outcomes-and-specialists-1',
frameworkExpiresAtUTC='2001-01-01T01:00:00.000000Z'
).response(),
]
}
self.data_api_client.get_supplier_frameworks.return_value = {
'frameworkInterest': [
{'frameworkSlug': 'digital-outcomes-and-specialists-1', 'onFramework': True},
{'frameworkSlug': 'digital-outcomes-and-specialists-2', 'onFramework': True},
]
}
self.login()
response = self.client.get("/suppliers")
assert response.status_code == 200
document = html.fromstring(response.get_data(as_text=True))
assert document.xpath("//h3[normalize-space(string())='Digital Outcomes and Specialists 1']")
assert not document.xpath("//h3[normalize-space(string())='Digital Outcomes and Specialists 2']")
def test_shows_gcloud_7_application_button(self):
self.data_api_client.get_framework_interest.return_value = {'frameworks': []}
self.data_api_client.get_supplier.side_effect = get_supplier
self.data_api_client.find_frameworks.return_value = {
"frameworks": [
FrameworkStub(status='expired', slug='digital-outcomes-and-specialists').response(),
FrameworkStub(status='open', slug='g-cloud-7').response(),
]
}
self.login()
response = self.client.get("/suppliers")
document = html.fromstring(response.get_data(as_text=True))
assert response.status_code == 200
apply_button = document.xpath(
"//h2[normalize-space()='G-Cloud 7 is open for applications']/following::input[1]"
)[0]
assert apply_button.value == "Apply"
def test_shows_gcloud_7_continue_link(self):
self.data_api_client.get_supplier.side_effect = get_supplier
self.data_api_client.get_supplier_frameworks.return_value = {
'frameworkInterest': [
{'frameworkSlug': 'g-cloud-7'}
]
}
self.data_api_client.find_frameworks.return_value = FIND_FRAMEWORKS_RETURN_VALUE
self.login()
response = self.client.get("/suppliers")
document = html.fromstring(response.get_data(as_text=True))
assert response.status_code == 200
continue_link = document.xpath(
"//h2[normalize-space()='Your G-Cloud 7 application']"
"/following::a[1][normalize-space()='Continue your application']"
)
assert continue_link
assert continue_link[0].values()[0] == "/suppliers/frameworks/g-cloud-7"
def test_shows_gcloud_7_closed_message_if_pending_and_no_interest(self): # noqa
self.data_api_client.get_framework.return_value = self.framework('pending')
self.data_api_client.get_supplier.side_effect = get_supplier
self.data_api_client.get_supplier_frameworks.return_value = {'frameworkInterest': []}
self.data_api_client.find_frameworks.return_value = {
"frameworks": [
FrameworkStub(status='pending', slug='g-cloud-7').response(),
]
}
self.login()
res = self.client.get("/suppliers")
doc = html.fromstring(res.get_data(as_text=True))
message = doc.xpath('//aside[@class="temporary-message"]')
assert len(message) > 0
assert u"G-Cloud 7 is closed for applications" in message[0].xpath('h2/text()')[0]
def test_shows_gcloud_7_closed_message_if_pending_and_no_application(self): # noqa
self.data_api_client.get_framework.return_value = self.framework('pending')
self.data_api_client.get_supplier.side_effect = get_supplier
self.data_api_client.get_supplier_frameworks.return_value = {
'frameworkInterest': [
{
'frameworkSlug': 'g-cloud-7',
'declaration': {'status': 'started'},
'drafts_count': 1,
'complete_drafts_count': 0
}
]
}
self.data_api_client.find_frameworks.return_value = {
"frameworks": [
FrameworkStub(status='pending', slug='g-cloud-7').response(),
]
}
self.login()
res = self.client.get("/suppliers")
doc = html.fromstring(res.get_data(as_text=True))
message = doc.xpath('//aside[@class="temporary-message"]')
assert len(message) > 0
assert u"G-Cloud 7 is closed for applications" in message[0].xpath('h2/text()')[0]
assert u"You didn’t submit an application" in message[0].xpath('p[1]/text()')[0]
assert len(message[0].xpath('p[2]/a[contains(@href, "suppliers/frameworks/g-cloud-7")]')) > 0
def test_shows_gcloud_7_closed_message_if_pending_and_application_done(self):
self.data_api_client.get_supplier.side_effect = get_supplier
self.data_api_client.get_supplier_frameworks.return_value = {
'frameworkInterest': [
{
'frameworkSlug': 'g-cloud-7',
'declaration': {'status': 'complete'},
'drafts_count': 0,
'complete_drafts_count': 99
}
]
}
self.data_api_client.find_frameworks.return_value = {
"frameworks": [
FrameworkStub(status='pending', slug='g-cloud-7').response(),
]
}
self.login()
res = self.client.get("/suppliers")
doc = html.fromstring(res.get_data(as_text=True))
headings = doc.xpath('//h2[@class="summary-item-heading"]')
assert len(headings) > 0
assert u"G-Cloud 7 is closed for applications" in headings[0].xpath('text()')[0]
assert u"You submitted 99 services for consideration" in headings[0].xpath('../p[1]/text()')[0]
assert len(headings[0].xpath('../p[1]/a[contains(@href, "suppliers/frameworks/g-cloud-7")]')) > 0
assert u"View your submitted application" in headings[0].xpath('../p[1]/a/text()')[0]
def test_shows_gcloud_7_in_standstill_application_passed_with_message(self):
self.data_api_client.get_supplier.side_effect = get_supplier
self.data_api_client.get_supplier_frameworks.return_value = {
'frameworkInterest': [
{
'frameworkSlug': 'g-cloud-7',
'declaration': {'status': 'complete'},
'drafts_count': 0,
'complete_drafts_count': 99,
'onFramework': True,
'agreementReturned': False
}
]
}
self.data_api_client.find_frameworks.return_value = {
'frameworks': [self.framework(status='standstill', slug='g-cloud-7')['frameworks']]
}
self.login()
res = self.client.get("/suppliers")
doc = html.fromstring(res.get_data(as_text=True))
headings = doc.xpath('//h2[@class="summary-item-heading"]')
assert u"Pending services" in headings[0].xpath('text()')[0]
first_table = doc.xpath(
'//table[@class="summary-item-body"]'
)
assert u"Pending services" in first_table[0].xpath('caption/text()')[0]
first_row = "".join(first_table[0].xpath('tbody/descendant::*/text()'))
assert u"G-Cloud 7" in first_row
assert u"Live from Monday 23 November 2015" in first_row
assert u"99 services" in first_row
assert u"99 services" in first_row
assert u"You must sign the framework agreement to sell these services" in first_row
def test_shows_gcloud_7_in_standstill_fw_agreement_returned(self):
self.data_api_client.get_supplier.side_effect = get_supplier
self.data_api_client.get_supplier_frameworks.return_value = {
'frameworkInterest': [
{
'frameworkSlug': 'g-cloud-7',
'declaration': {'status': 'complete'},
'drafts_count': 0,
'complete_drafts_count': 99,
'onFramework': True,
'agreementReturned': True
}
]
}
self.data_api_client.find_frameworks.return_value = {
"frameworks": [self.framework(status='standstill', slug='g-cloud-7')['frameworks']]
}
self.login()
res = self.client.get("/suppliers")
doc = html.fromstring(res.get_data(as_text=True))
headings = doc.xpath('//h2[@class="summary-item-heading"]')
assert u"Pending services" in headings[0].xpath('text()')[0]
first_table = doc.xpath(
'//table[@class="summary-item-body"]'
)
assert u"Pending services" in first_table[0].xpath('caption/text()')[0]
first_row = "".join(first_table[0].xpath('tbody/descendant::*/text()'))
assert u"G-Cloud 7" in first_row
assert u"Live from Monday 23 November 2015" in first_row
assert u"99 services" in first_row
assert u"You must sign the framework agreement to sell these services" not in first_row
def test_shows_gcloud_7_in_standstill_no_application(self):
self.data_api_client.get_supplier.side_effect = get_supplier
self.data_api_client.get_supplier_frameworks.return_value = {
'frameworkInterest': []
}
self.data_api_client.find_frameworks.return_value = {
"frameworks": [
FrameworkStub(status='standstill', slug='g-cloud-7').response(),
]
}
self.login()
res = self.client.get("/suppliers")
doc = html.fromstring(res.get_data(as_text=True))
assert not doc.xpath('//h2[normalize-space(string())=$t]', t="Pending services")
def test_shows_gcloud_7_in_standstill_application_failed(self):
self.data_api_client.get_supplier.side_effect = get_supplier
self.data_api_client.get_supplier_frameworks.return_value = {
'frameworkInterest': [
{
'frameworkSlug': 'g-cloud-7',
'declaration': {'status': 'complete'},
'drafts_count': 0,
'complete_drafts_count': 99,
'onFramework': False,
'agreementReturned': False
}
]
}
self.data_api_client.find_frameworks.return_value = {
"frameworks": [
FrameworkStub(status='standstill', slug='g-cloud-7').response(),
]
}
self.login()
res = self.client.get("/suppliers")
doc = html.fromstring(res.get_data(as_text=True))
headings = doc.xpath('//h2[@class="summary-item-heading"]')
assert u"Pending services" in headings[0].xpath('text()')[0]
first_table = doc.xpath(
'//table[@class="summary-item-body"]'
)
assert u"Pending services" in first_table[0].xpath('caption/text()')[0]
first_row = "".join(first_table[0].xpath('tbody/descendant::*/text()'))
assert u"G-Cloud 7" in first_row
assert u"Live from Monday 23 November 2015" not in first_row
assert u"99 services submitted" in first_row
assert u"You must sign the framework agreement to sell these services" not in first_row
assert u"View your services" in first_row
def test_shows_gcloud_7_in_standstill_application_passed(self):
self.data_api_client.get_supplier.side_effect = get_supplier
self.data_api_client.get_supplier_frameworks.return_value = {
'frameworkInterest': [
{
'frameworkSlug': 'g-cloud-7',
'declaration': {'status': 'complete'},
'drafts_count': 0,
'complete_drafts_count': 99,
'onFramework': True,
'agreementReturned': True
}
]
}
self.data_api_client.find_frameworks.return_value = {
"frameworks": [
FrameworkStub(
status='standstill', slug='g-cloud-7', framework_live_at=datetime(2015, 11, 23)
).response(),
]
}
self.login()
res = self.client.get("/suppliers")
doc = html.fromstring(res.get_data(as_text=True))
headings = doc.xpath('//h2[@class="summary-item-heading"]')
assert u"Pending services" in headings[0].xpath('text()')[0]
first_table = doc.xpath(
'//table[@class="summary-item-body"]'
)
assert u"Pending services" in first_table[0].xpath('caption/text()')[0]
first_row = "".join(first_table[0].xpath('tbody/descendant::*/text()'))
assert u"G-Cloud 7" in first_row
assert u"Live from Monday 23 November 2015" in first_row
assert u"99 services" in first_row
assert u"You must sign the framework agreement to sell these services" not in first_row
def test_shows_register_for_dos_button(self):
self.data_api_client.get_framework.return_value = self.framework(status='other')
self.data_api_client.get_supplier.side_effect = get_supplier
self.data_api_client.find_frameworks.return_value = {
"frameworks": [
FrameworkStub(status='open', slug='digital-outcomes-and-specialists').response(),
FrameworkStub(status='live', slug='g-cloud-7').response(),
]
}
self.login()
response = self.client.get("/suppliers")
document = html.fromstring(response.get_data(as_text=True))
assert response.status_code == 200
apply_button = document.xpath(
"//h2[normalize-space()='Digital Outcomes and Specialists is open for applications']"
"/following::input[1]"
)[0]
assert apply_button.value == "Apply"
def test_shows_continue_with_dos_link(self):
self.data_api_client.get_supplier.side_effect = get_supplier
self.data_api_client.get_supplier_frameworks.return_value = {
'frameworkInterest': [
{'frameworkSlug': 'digital-outcomes-and-specialists'}
]
}
self.data_api_client.find_frameworks.return_value = {
"frameworks": [
FrameworkStub(status='open', slug='digital-outcomes-and-specialists').response(),
FrameworkStub(status='live', slug='g-cloud-7').response(),
]
}
self.login()
response = self.client.get("/suppliers")
document = html.fromstring(response.get_data(as_text=True))
assert response.status_code == 200
continue_link = document.xpath(
"//h2[normalize-space()='Your Digital Outcomes and Specialists application']"
"/following::a[1][normalize-space()='Continue your application']"
)
assert continue_link
assert continue_link[0].values()[0] == "/suppliers/frameworks/digital-outcomes-and-specialists"
def test_shows_placeholder_to_recovery_supplier(self):
self.data_api_client.get_supplier.return_value = get_supplier(id='577184') # Test.DM_G12_RECOVERY_SUPPLIER_IDS
self.login()
with self.app.app_context():
response = self.client.get("/suppliers")
document = html.fromstring(response.get_data(as_text=True))
assert document.xpath("//h2[normalize-space(string())='G-Cloud 12 recovery']")
def test_does_not_show_placeholder(self):
self.data_api_client.get_supplier.return_value = get_supplier(id='123456')
self.login()
with self.app.app_context():
response = self.client.get("/suppliers")
document = html.fromstring(response.get_data(as_text=True))
assert not document.xpath("//h2[normalize-space(string())='G-Cloud 12 recovery']")
class TestSupplierDetails(BaseApplicationTest):
def setup_method(self, method):
super().setup_method(method)
self.data_api_client_patch = mock.patch('app.main.views.suppliers.data_api_client', autospec=True)
self.data_api_client = self.data_api_client_patch.start()
def teardown_method(self, method):
self.data_api_client_patch.stop()
super().teardown_method(method)
def test_shows_supplier_info(self):
self.data_api_client.get_supplier.side_effect = get_supplier
self.login()
res = self.client.get("/suppliers/details")
assert res.status_code == 200
page_html = res.get_data(as_text=True)
document = html.fromstring(page_html)
assert document.xpath(
"//a[normalize-space(string())=$t][@href=$u][contains(@class, $c)]",
t="Edit",
u="/suppliers/what-buyers-will-see/edit",
c="summary-change-link",
)
for property_str in (
# "Company details" section at the top
"Supplier Person", # Contact name
"supplier@user.dmdev", # Contact email
"0800123123", # Phone number
"1 Street", # Address: "2 Building" and "Supplierland" are not shown, even though in contactInformation
"Supplierville", # Town or City
"11 AB", # Postcode
"Supplier Description", # Supplier summary
# "Registration information" section
"Official Name Inc", # Registered company name
"CH123456", # Companies House number
"987654321", # DUNS number
"Open for business", # Trading status
"Small", # Size
):
assert document.xpath("//*[normalize-space(string())=$t]", t=property_str), property_str
# Registration number not shown if Companies House ID exists
assert "BEL153" not in page_html
self.data_api_client.get_supplier.assert_called_once_with(1234)
def test_registration_number_field_shows_other_registration_num_if_no_companies_house_num(self):
self.data_api_client.get_supplier.return_value = get_supplier(
companiesHouseNumber=None, otherCompanyRegistrationNumber="42, EARTH"
)
self.login()
res = self.client.get("/suppliers/details")
assert res.status_code == 200
page_html = res.get_data(as_text=True)
document = html.fromstring(page_html)
assert document.xpath("//span[text()='Registration number']/following::td[1]/span[text()='42, EARTH']")
def test_shows_united_kingdom_for_old_style_country_code(self):
self.data_api_client.get_supplier.return_value = get_supplier(
companiesHouseNumber=None, registrationCountry="gb"
)
self.login()
res = self.client.get("/suppliers/details")
assert res.status_code == 200
page_html = res.get_data(as_text=True)
document = html.fromstring(page_html)
assert document.xpath("//*[normalize-space(string())='United Kingdom']") # Country United Kingdom is shown
def test_handles_supplier_with_no_registration_country_key(self):
supplier = get_supplier()
del supplier['suppliers']['registrationCountry']
self.data_api_client.get_supplier.return_value = supplier
self.login()
res = self.client.get("/suppliers/details")
assert res.status_code == 200
def test_shows_address_details(self):
self.data_api_client.get_supplier.return_value = get_supplier(registrationCountry="country:GB")
self.login()
response = self.client.get("/suppliers/details")
assert response.status_code == 200
page_html = response.get_data(as_text=True)
document = html.fromstring(page_html)
street = document.xpath("//span[text()='Registered company address']/following::td[1]/span/p/span[1]")
town = document.xpath("//span[text()='Registered company address']/following::td[1]/span/p/span[2]")
postcode = document.xpath("//span[text()='Registered company address']/following::td[1]/span/p/span[3]")
country = document.xpath("//span[text()='Registered company address']/following::td[1]/span/p/span[4]")
assert "1 Street" in street[0].text
assert "Supplierville" in town[0].text
assert "11 AB" in postcode[0].text
assert "United Kingdom" in country[0].text
@pytest.mark.parametrize(
"question,null_attribute,link_address",
[
("Registered company name", {"registeredName": None}, "/suppliers/registered-company-name/edit"),
("Registered company address", {"registrationCountry": None}, "/suppliers/registered-address/edit"),
(
"Registration number",
{"companiesHouseNumber": None, "otherCompanyRegistrationNumber": None},
"/suppliers/registration-number/edit"
),
("Trading status", {"tradingStatus": None}, "/suppliers/trading-status/edit"),
("Company size", {"organisationSize": None}, "/suppliers/organisation-size/edit"),
]
)
def test_question_field_requires_answer_if_empty(self, question, null_attribute, link_address):
self.data_api_client.get_supplier.return_value = get_supplier(**null_attribute)
self.login()
response = self.client.get("/suppliers/details")
assert response.status_code == 200
page_html = response.get_data(as_text=True)
document = html.fromstring(page_html)
answer_required_link = document.xpath(
"//span[text()='{}']/following::td[1]/span/a[text()='Answer required']".format(question)
)
assert answer_required_link
assert answer_required_link[0].values()[0] == link_address
@pytest.mark.parametrize(
"question,filled_in_attribute,link_address",
[
(
"Registered company name", {"companyDetailsConfirmed": True, "registeredName": "Digital Ponies"},
"/suppliers/registered-company-name/edit",
),
(
"Registered company name", {"companyDetailsConfirmed": False, "registeredName": "Digital Ponies"},
"/suppliers/registered-company-name/edit",
),
("Registered company address", {"companyDetailsConfirmed": True, "registrationCountry": "country:GB"},
"/suppliers/registered-address/edit",),
("Registered company address", {"companyDetailsConfirmed": False, "registrationCountry": "country:GB"},
"/suppliers/registered-address/edit",),
(
"Registration number",
{
"companyDetailsConfirmed": True, "companiesHouseNumber": "CH123456",
"otherCompanyRegistrationNumber": None
},
"/suppliers/registration-number/edit",
),
(
"Registration number",
{
"companyDetailsConfirmed": False, "companiesHouseNumber": "CH123456",
"otherCompanyRegistrationNumber": None
},
"/suppliers/registration-number/edit",
),
(
"Registration number",
{
"companyDetailsConfirmed": True, "companiesHouseNumber": None,
"otherCompanyRegistrationNumber": "EQ789"
},
"/suppliers/registration-number/edit",
),
(
"Registration number",
{
"companyDetailsConfirmed": False, "companiesHouseNumber": None,
"otherCompanyRegistrationNumber": "EQ789"
},
"/suppliers/registration-number/edit",
),
("Trading status", {"companyDetailsConfirmed": False, "tradingStatus": "limited company (LTD)"},
"/suppliers/trading-status/edit",),
("Company size", {"companyDetailsConfirmed": False, "organisationSize": "small"},
"/suppliers/organisation-size/edit",),
("DUNS number", {"companyDetailsConfirmed": True, "dunsNumber": "123456789"},
"/suppliers/duns-number/edit",),
("DUNS number", {"companyDetailsConfirmed": False, "dunsNumber": "123456789"},
"/suppliers/duns-number/edit",),
]
)
def test_filled_in_question_field_has_a_change_or_correct_a_mistake_link(
self, question, filled_in_attribute, link_address
):
self.data_api_client.get_supplier.return_value = get_supplier(**filled_in_attribute)
self.login()
response = self.client.get("/suppliers/details")
assert response.status_code == 200
page_html = response.get_data(as_text=True)
document = html.fromstring(page_html)
answer_required_link = document.xpath(
"//span[text()='{}']/following::td[2]/span/a[text()='Edit']".format(question)
)
assert answer_required_link
assert answer_required_link[0].values()[0] == link_address
@pytest.mark.parametrize(
"summary,is_hint_visible",
[
({"description": "Our company is the best for digital ponies."}, False),
({"description": ""}, True),
]
)
def test_hint_text_for_summary_only_visible_if_field_empty(self, summary, is_hint_visible):
self.data_api_client.get_supplier.return_value = get_supplier(**summary)
self.login()
response = self.client.get("/suppliers/details")
assert response.status_code == 200
page_html = response.get_data(as_text=True)
document = html.fromstring(page_html)
optional_hint_text = (document.xpath("//span[text()='Summary']/following::td[2]/span")[0].text).strip()
assert bool(optional_hint_text) == is_hint_visible
@pytest.mark.parametrize(
"framework_slug,framework_name,link_address",
[
(
"digital-outcomes-and-specialists-2",
"Digital Outcomes and Specialists 2",
"/suppliers/frameworks/digital-outcomes-and-specialists-2"
),
("g-cloud-9", "G-Cloud 9", "/suppliers/frameworks/g-cloud-9")
]
)
def test_back_to_application_link_is_visible_if_currently_applying_to_in_session(
self, framework_slug, framework_name, link_address
):
self.data_api_client.get_supplier.return_value = get_supplier()
framework = FrameworkStub(name=framework_name, slug=framework_slug, status='open')
self.data_api_client.find_frameworks.return_value = {
"frameworks": [framework.response()],
}
self.data_api_client.get_framework.return_value = framework.single_result_response()
self.data_api_client.get_supplier_frameworks.return_value = {
'frameworkInterest': [
SupplierFrameworkStub(framework_slug=framework_slug).response()
]
}
self.login()
with self.client.session_transaction() as session:
session["currently_applying_to"] = framework_slug
response = self.client.get("/suppliers/details")
assert response.status_code == 200
page_html = response.get_data(as_text=True)
document = html.fromstring(page_html)
return_link = (document.xpath("//a[text()='Return to your {} application']".format(framework_name)))
assert return_link
assert return_link[0].values()[0] == link_address
def test_back_to_application_link_not_visible_if_currently_applying_to_not_in_session(self):
self.data_api_client.get_supplier.return_value = get_supplier()
self.login()
response = self.client.get("/suppliers/details")
assert response.status_code == 200
page_html = response.get_data(as_text=True)
document = html.fromstring(page_html)
assert "Return to your" not in document.text_content()
def test_currently_applying_to_removed_from_session_after_account_dashboard_visit(self):
self.data_api_client.get_supplier.return_value = get_supplier()
self.login()
with self.client.session_transaction() as session:
session["currently_applying_to"] = 'g-bork-2'
with self.client.session_transaction() as session:
assert "currently_applying_to" in session
response = self.client.get("/suppliers")
assert response.status_code == 200
with self.client.session_transaction() as session:
assert "currently_applying_to" not in session
@pytest.mark.parametrize(
"supplier_details,open_application,button_should_be_shown",
[
# Details complete but not confirmed
(get_supplier(companyDetailsConfirmed=False), False, True),
# Details complete and already confirmed
(get_supplier(companyDetailsConfirmed=True), False, False),
# Details not complete or confirmed
(get_supplier(companyDetailsConfirmed=False, dunsNumber=None), False, False),
]
)
def test_green_button_is_shown_when_details_are_complete_but_not_confirmed(
self, supplier_details, open_application, button_should_be_shown
):
self.data_api_client.get_supplier.return_value = supplier_details
self.data_api_client.get_supplier_frameworks.return_value = {
'frameworkInterest': [
SupplierFrameworkStub().response()
]
}
self.login()
response = self.client.get("/suppliers/details")
assert response.status_code == 200
document = html.fromstring(response.get_data(as_text=True))
submit_button = document.xpath("//form//button[normalize-space(string())=$t]", t="Save and confirm")
assert bool(submit_button) == button_should_be_shown
@pytest.mark.parametrize('application_company_details_confirmed', (False, None))
def test_green_button_is_shown_when_company_details_confirmed_for_account_but_not_application(
self, application_company_details_confirmed
):
self.data_api_client.get_supplier.return_value = get_supplier(companyDetailsConfirmed=True)
self.data_api_client.find_frameworks.return_value = {
"frameworks": [FrameworkStub(status='open', slug='g-cloud-9').response()]
}
self.data_api_client.get_supplier_frameworks.return_value = {
'frameworkInterest': [
SupplierFrameworkStub(
framework_slug='g-cloud-9',
application_company_details_confirmed=application_company_details_confirmed
).response(),
]
}
self.login()
response = self.client.get('/suppliers/details')
assert response.status_code == 200
assert (