@@ -788,3 +788,115 @@ async def test_mass_contractor_create(cli, db_conn, company, image_download_url,
788788 assert result .id == 369
789789 assert result .first_name == 'Jim'
790790 assert result .last_name == 'Bell'
791+
792+
793+ async def test_mass_contractor_process_images_false (cli , db_conn , other_server , company , image_download_url , worker ):
794+ data = {'contractors' : [], 'process_images' : False }
795+ eas = [
796+ {
797+ 'machine_name' : 'terms' ,
798+ 'type' : 'checkbox' ,
799+ 'name' : 'Terms and Conditions agreement' ,
800+ 'value' : True ,
801+ 'sort_index' : 0 ,
802+ },
803+ {'machine_name' : 'bio' , 'type' : 'integer' , 'name' : 'Teaching Experience' , 'value' : 123 , 'sort_index' : 0.123 },
804+ {'machine_name' : 'date' , 'type' : 'date' , 'name' : 'The Date' , 'value' : '2032-06-01' , 'sort_index' : 0.123 },
805+ ]
806+ for i in range (1 , 3 ):
807+ data ['contractors' ].append (
808+ dict (
809+ id = 123 * i ,
810+ first_name = 'Fred' ,
811+ skills = [
812+ {
813+ 'subject_id' : 1 ,
814+ 'qual_level_id' : 1 ,
815+ 'qual_level' : 'GCSE' ,
816+ 'subject' : 'Algebra' ,
817+ 'qual_level_ranking' : 16.0 ,
818+ 'category' : 'Maths' ,
819+ },
820+ {
821+ 'subject_id' : 2 ,
822+ 'qual_level_id' : 1 ,
823+ 'qual_level' : 'GCSE' ,
824+ 'subject' : 'Language' ,
825+ 'qual_level_ranking' : 16.0 ,
826+ 'category' : 'English' ,
827+ },
828+ ],
829+ location = dict (latitude = 12.345 , longitude = 56.789 ),
830+ review_rating = 3.5 ,
831+ review_duration = 7200 ,
832+ labels = [{'machine_name' : 'foobar' , 'name' : 'Foobar' }],
833+ photo = f'{ image_download_url } ?format=JPEG' ,
834+ extra_attributes = eas ,
835+ )
836+ )
837+ r = await signed_request (
838+ cli , f'/{ company .public_key } /webhook/contractor/mass' , signing_key_ = 'this is the master key' , ** data
839+ )
840+ assert r .status == 200
841+ assert {'status' : 'success' } == await r .json ()
842+ assert 2 == await count (db_conn , sa_contractors )
843+ await worker .run_check ()
844+ assert other_server .app ['request_log' ] == []
845+
846+
847+ async def test_mass_contractor_process_images_true (
848+ cli , db_conn , other_server , company , image_download_url , monkeypatch , tmpdir , worker
849+ ):
850+ monkeypatch .setattr (boto3 , 'client' , fake_s3_client (tmpdir ))
851+
852+ data = {'contractors' : [], 'process_images' : True }
853+ eas = [
854+ {
855+ 'machine_name' : 'terms' ,
856+ 'type' : 'checkbox' ,
857+ 'name' : 'Terms and Conditions agreement' ,
858+ 'value' : True ,
859+ 'sort_index' : 0 ,
860+ },
861+ {'machine_name' : 'bio' , 'type' : 'integer' , 'name' : 'Teaching Experience' , 'value' : 123 , 'sort_index' : 0.123 },
862+ {'machine_name' : 'date' , 'type' : 'date' , 'name' : 'The Date' , 'value' : '2032-06-01' , 'sort_index' : 0.123 },
863+ ]
864+ for i in range (1 , 3 ):
865+ data ['contractors' ].append (
866+ dict (
867+ id = 123 * i ,
868+ first_name = 'Fred' ,
869+ skills = [
870+ {
871+ 'subject_id' : 1 ,
872+ 'qual_level_id' : 1 ,
873+ 'qual_level' : 'GCSE' ,
874+ 'subject' : 'Algebra' ,
875+ 'qual_level_ranking' : 16.0 ,
876+ 'category' : 'Maths' ,
877+ },
878+ {
879+ 'subject_id' : 2 ,
880+ 'qual_level_id' : 1 ,
881+ 'qual_level' : 'GCSE' ,
882+ 'subject' : 'Language' ,
883+ 'qual_level_ranking' : 16.0 ,
884+ 'category' : 'English' ,
885+ },
886+ ],
887+ location = dict (latitude = 12.345 , longitude = 56.789 ),
888+ review_rating = 3.5 ,
889+ review_duration = 7200 ,
890+ labels = [{'machine_name' : 'foobar' , 'name' : 'Foobar' }],
891+ photo = f'{ image_download_url } ?format=JPEG' ,
892+ extra_attributes = eas ,
893+ )
894+ )
895+ r = await signed_request (
896+ cli , f'/{ company .public_key } /webhook/contractor/mass' , signing_key_ = 'this is the master key' , ** data
897+ )
898+ assert r .status == 200
899+ assert {'status' : 'success' } == await r .json ()
900+ assert 2 == await count (db_conn , sa_contractors )
901+ await worker .run_check ()
902+ assert other_server .app ['request_log' ] == [('test_image' , 'JPEG' ), ('test_image' , 'JPEG' )]
0 commit comments