@@ -419,46 +419,21 @@ class TestOrganizationApplicationList:
419
419
def test_no_query (self , db_request ):
420
420
organization_applications = sorted (
421
421
OrganizationApplicationFactory .create_batch (30 ),
422
- key = lambda o : o .normalized_name ,
423
- )
424
- result = views .organization_applications_list (db_request )
425
-
426
- assert result == {
427
- "organization_applications" : organization_applications [:25 ],
428
- "query" : "" ,
429
- "terms" : [],
430
- }
431
-
432
- @pytest .mark .usefixtures ("_enable_organizations" )
433
- def test_with_page (self , db_request ):
434
- organization_applications = sorted (
435
- OrganizationApplicationFactory .create_batch (30 ),
436
- key = lambda o : o .normalized_name ,
422
+ key = lambda o : o .submitted ,
437
423
)
438
- db_request .GET ["page" ] = "2"
439
424
result = views .organization_applications_list (db_request )
440
425
441
426
assert result == {
442
- "organization_applications" : organization_applications [ 25 :] ,
427
+ "organization_applications" : organization_applications ,
443
428
"query" : "" ,
444
429
"terms" : [],
445
430
}
446
431
447
- @pytest .mark .usefixtures ("_enable_organizations" )
448
- def test_with_invalid_page (self ):
449
- request = pretend .stub (
450
- flags = pretend .stub (enabled = lambda * a : False ),
451
- params = {"page" : "not an integer" },
452
- )
453
-
454
- with pytest .raises (HTTPBadRequest ):
455
- views .organization_applications_list (request )
456
-
457
432
@pytest .mark .usefixtures ("_enable_organizations" )
458
433
def test_basic_query (self , db_request ):
459
434
organization_applications = sorted (
460
435
OrganizationApplicationFactory .create_batch (5 ),
461
- key = lambda o : o .normalized_name ,
436
+ key = lambda o : o .submitted ,
462
437
)
463
438
db_request .GET ["q" ] = organization_applications [0 ].name
464
439
result = views .organization_applications_list (db_request )
@@ -471,7 +446,7 @@ def test_basic_query(self, db_request):
471
446
def test_name_query (self , db_request ):
472
447
organization_applications = sorted (
473
448
OrganizationApplicationFactory .create_batch (5 ),
474
- key = lambda o : o .normalized_name ,
449
+ key = lambda o : o .submitted ,
475
450
)
476
451
db_request .GET ["q" ] = f"name:{ organization_applications [0 ].name } "
477
452
result = views .organization_applications_list (db_request )
@@ -484,7 +459,7 @@ def test_name_query(self, db_request):
484
459
def test_organization_application_query (self , db_request ):
485
460
organization_applications = sorted (
486
461
OrganizationApplicationFactory .create_batch (5 ),
487
- key = lambda o : o .normalized_name ,
462
+ key = lambda o : o .submitted ,
488
463
)
489
464
db_request .GET ["q" ] = (
490
465
f"organization:{ organization_applications [0 ].display_name } "
@@ -504,7 +479,7 @@ def test_organization_application_query(self, db_request):
504
479
def test_url_query (self , db_request ):
505
480
organization_applications = sorted (
506
481
OrganizationApplicationFactory .create_batch (5 ),
507
- key = lambda o : o .normalized_name ,
482
+ key = lambda o : o .submitted ,
508
483
)
509
484
db_request .GET ["q" ] = f"url:{ organization_applications [0 ].link_url } "
510
485
result = views .organization_applications_list (db_request )
@@ -517,7 +492,7 @@ def test_url_query(self, db_request):
517
492
def test_description_query (self , db_request ):
518
493
organization_applications = sorted (
519
494
OrganizationApplicationFactory .create_batch (5 ),
520
- key = lambda o : o .normalized_name ,
495
+ key = lambda o : o .submitted ,
521
496
)
522
497
db_request .GET ["q" ] = (
523
498
f"description:'{ organization_applications [0 ].description } '"
@@ -537,7 +512,7 @@ def test_description_query(self, db_request):
537
512
def test_is_approved_query (self , db_request ):
538
513
organization_applications = sorted (
539
514
OrganizationApplicationFactory .create_batch (5 ),
540
- key = lambda o : o .normalized_name ,
515
+ key = lambda o : o .submitted ,
541
516
)
542
517
organization_applications [0 ].is_approved = True
543
518
organization_applications [1 ].is_approved = True
@@ -557,7 +532,7 @@ def test_is_approved_query(self, db_request):
557
532
def test_is_declined_query (self , db_request ):
558
533
organization_applications = sorted (
559
534
OrganizationApplicationFactory .create_batch (5 ),
560
- key = lambda o : o .normalized_name ,
535
+ key = lambda o : o .submitted ,
561
536
)
562
537
organization_applications [0 ].is_approved = True
563
538
organization_applications [1 ].is_approved = True
@@ -577,7 +552,7 @@ def test_is_declined_query(self, db_request):
577
552
def test_is_submitted_query (self , db_request ):
578
553
organization_applications = sorted (
579
554
OrganizationApplicationFactory .create_batch (5 ),
580
- key = lambda o : o .normalized_name ,
555
+ key = lambda o : o .submitted ,
581
556
)
582
557
organization_applications [0 ].is_approved = True
583
558
organization_applications [1 ].is_approved = True
@@ -638,163 +613,84 @@ def test_invalid_type_query(self, db_request):
638
613
def test_is_invalid_query (self , db_request ):
639
614
organization_applications = sorted (
640
615
OrganizationApplicationFactory .create_batch (5 ),
641
- key = lambda o : o .normalized_name ,
616
+ key = lambda o : o .submitted ,
642
617
)
643
618
db_request .GET ["q" ] = "is:not-actually-a-valid-query"
644
619
result = views .organization_applications_list (db_request )
645
620
646
621
assert result == {
647
- "organization_applications" : organization_applications [: 25 ] ,
622
+ "organization_applications" : organization_applications ,
648
623
"query" : "is:not-actually-a-valid-query" ,
649
624
"terms" : ["is:not-actually-a-valid-query" ],
650
625
}
651
626
652
627
653
628
class TestOrganizationApplicationDetail :
654
629
@pytest .mark .usefixtures ("_enable_organizations" )
655
- def test_detail (self ):
656
- admin = pretend .stub (
657
- id = "admin-id" ,
658
- username = "admin" ,
659
- name = "Admin" ,
660
-
630
+ def test_detail (self , db_request ):
631
+ organization_application = OrganizationApplicationFactory .create ()
632
+ db_request .matchdict ["organization_application_id" ] = (
633
+ organization_application .id
661
634
)
662
- user = pretend .stub (
663
- id = "user-id" ,
664
- username = "example" ,
665
- name = "Example" ,
666
-
667
- )
668
- user_service = pretend .stub (
669
- get_user = lambda userid , ** kw : {admin .id : admin , user .id : user }[userid ],
670
- )
671
- organization_application = pretend .stub (
672
- id = pretend .stub (),
673
- name = "example" ,
674
- display_name = "Example" ,
675
- orgtype = pretend .stub (name = "Company" ),
676
- link_url = "https://www.example.com/" ,
677
- description = (
678
- "This company is for use in illustrative examples in documents "
679
- "You may use this company in literature without prior "
680
- "coordination or asking for permission."
681
- ),
682
- is_approved = None ,
683
- submitted_by_id = user .id ,
684
- submitted_by = user ,
685
- )
686
- organization_service = pretend .stub (
687
- get_organization_application = lambda * a , ** kw : organization_application ,
688
- )
689
- request = pretend .stub (
690
- flags = pretend .stub (enabled = lambda * a : False ),
691
- find_service = lambda iface , ** kw : {
692
- IUserService : user_service ,
693
- IOrganizationService : organization_service ,
694
- }[iface ],
695
- matchdict = {"organization_application_id" : pretend .stub ()},
696
- )
697
-
698
- assert views .organization_application_detail (request ) == {
699
- "user" : user ,
635
+ assert views .organization_application_detail (db_request ) == {
636
+ "user" : organization_application .submitted_by ,
637
+ "conflicting_applications" : [],
700
638
"organization_application" : organization_application ,
701
639
}
702
640
703
641
@pytest .mark .usefixtures ("_enable_organizations" )
704
- def test_detail_is_approved_true (self ):
705
- admin = pretend .stub (
706
- id = "admin-id" ,
707
- username = "admin" ,
708
- name = "Admin" ,
709
-
710
- )
711
- user = pretend .stub (
712
- id = "user-id" ,
713
- username = "example" ,
714
- name = "Example" ,
715
-
642
+ def test_detail_is_approved_true (self , db_request ):
643
+ organization_application = OrganizationApplicationFactory .create (
644
+ is_approved = True
716
645
)
717
- user_service = pretend . stub (
718
- get_user = lambda userid , ** kw : { admin .id : admin , user . id : user }[ userid ],
646
+ db_request . matchdict [ "organization_application_id" ] = (
647
+ organization_application .id
719
648
)
720
- organization_application = pretend .stub (
721
- id = pretend .stub (),
722
- name = "example" ,
723
- display_name = "Example" ,
724
- orgtype = pretend .stub (name = "Company" ),
725
- link_url = "https://www.example.com/" ,
726
- description = (
727
- "This company is for use in illustrative examples in documents "
728
- "You may use this company in literature without prior "
729
- "coordination or asking for permission."
730
- ),
731
- is_approved = True ,
732
- submitted_by_id = user .id ,
733
- submitted_by = user ,
734
- )
735
- organization_service = pretend .stub (
736
- get_organization_application = lambda * a , ** kw : organization_application ,
737
- )
738
- request = pretend .stub (
739
- flags = pretend .stub (enabled = lambda * a : False ),
740
- find_service = lambda iface , ** kw : {
741
- IUserService : user_service ,
742
- IOrganizationService : organization_service ,
743
- }[iface ],
744
- matchdict = {"organization_application_id" : pretend .stub ()},
745
- )
746
-
747
- assert views .organization_application_detail (request ) == {
748
- "user" : user ,
649
+ assert views .organization_application_detail (db_request ) == {
650
+ "user" : organization_application .submitted_by ,
651
+ "conflicting_applications" : [],
749
652
"organization_application" : organization_application ,
750
653
}
751
654
752
655
@pytest .mark .usefixtures ("_enable_organizations" )
753
- def test_detail_is_approved_false (self ):
754
- admin = pretend .stub (
755
- id = "admin-id" ,
756
- username = "admin" ,
757
- name = "Admin" ,
758
-
759
- )
760
- user = pretend .stub (
761
- id = "user-id" ,
762
- username = "example" ,
763
- name = "Example" ,
764
-
656
+ def test_detail_is_approved_false (self , db_request ):
657
+ organization_application = OrganizationApplicationFactory .create (
658
+ is_approved = False
765
659
)
766
- user_service = pretend .stub (
767
- get_user = lambda userid , ** kw : {admin .id : admin , user .id : user }[userid ],
768
- )
769
- organization_application = pretend .stub (
770
- id = pretend .stub (),
771
- name = "example" ,
772
- display_name = "Example" ,
773
- orgtype = pretend .stub (name = "Company" ),
774
- link_url = "https://www.example.com/" ,
775
- description = (
776
- "This company is for use in illustrative examples in documents "
777
- "You may use this company in literature without prior "
778
- "coordination or asking for permission."
779
- ),
780
- is_approved = False ,
781
- submitted_by_id = user .id ,
782
- submitted_by = user ,
783
- )
784
- organization_service = pretend .stub (
785
- get_organization_application = lambda * a , ** kw : organization_application ,
786
- )
787
- request = pretend .stub (
788
- flags = pretend .stub (enabled = lambda * a : False ),
789
- find_service = lambda iface , ** kw : {
790
- IUserService : user_service ,
791
- IOrganizationService : organization_service ,
792
- }[iface ],
793
- matchdict = {"organization_application_id" : pretend .stub ()},
660
+ db_request .matchdict ["organization_application_id" ] = (
661
+ organization_application .id
794
662
)
663
+ assert views .organization_application_detail (db_request ) == {
664
+ "user" : organization_application .submitted_by ,
665
+ "conflicting_applications" : [],
666
+ "organization_application" : organization_application ,
667
+ }
795
668
796
- assert views .organization_application_detail (request ) == {
797
- "user" : user ,
669
+ @pytest .mark .usefixtures ("_enable_organizations" )
670
+ @pytest .mark .parametrize (
671
+ ("name" , "conflicts" ),
672
+ [
673
+ ("pypi" , ["PyPI" , "pypi" ]),
674
+ ("py-pi" , ["Py-PI" , "PY-PI" ]),
675
+ ],
676
+ )
677
+ def test_detail_conflicting_applications (self , db_request , name , conflicts ):
678
+ organization_application = OrganizationApplicationFactory .create (
679
+ name = name , is_approved = False
680
+ )
681
+ conflicting_applications = sorted (
682
+ [
683
+ OrganizationApplicationFactory .create (name = conflict )
684
+ for conflict in conflicts
685
+ ],
686
+ key = lambda o : o .submitted ,
687
+ )
688
+ db_request .matchdict ["organization_application_id" ] = (
689
+ organization_application .id
690
+ )
691
+ assert views .organization_application_detail (db_request ) == {
692
+ "user" : organization_application .submitted_by ,
693
+ "conflicting_applications" : conflicting_applications ,
798
694
"organization_application" : organization_application ,
799
695
}
800
696
0 commit comments