@@ -79,6 +79,61 @@ async def test_create_with_keys(cli, db_conn, worker):
7979 }
8080
8181
82+ async def test_create_with_keys_update_contractors_false (cli , db_conn , worker ):
83+ data = {
84+ 'name' : 'foobar' ,
85+ 'public_key' : 'x' * 20 ,
86+ 'private_key' : 'y' * 40 ,
87+ '_request_time' : int (time ()),
88+ 'update_contractors' : False ,
89+ }
90+ payload = json .dumps (data )
91+ b_payload = payload .encode ()
92+ m = hmac .new (b'this is the master key' , b_payload , hashlib .sha256 )
93+
94+ headers = {
95+ 'Webhook-Signature' : m .hexdigest (),
96+ 'Content-Type' : 'application/json' ,
97+ }
98+ r = await cli .post ('/companies/create' , data = payload , headers = headers )
99+ assert r .status == 201
100+ curr = await db_conn .execute (sa_companies .select ())
101+ result = await curr .first ()
102+ assert result .name == 'foobar'
103+ await worker .run_check ()
104+ assert {
105+ (cs .id , cs .first_name , cs .last_name ) async for cs in await db_conn .execute (sa_contractors .select ())
106+ } == set ()
107+
108+
109+ async def test_create_with_keys_update_contractors_true (cli , db_conn , worker ):
110+ data = {
111+ 'name' : 'foobar' ,
112+ 'public_key' : 'x' * 20 ,
113+ 'private_key' : 'y' * 40 ,
114+ '_request_time' : int (time ()),
115+ 'update_contractors' : True ,
116+ }
117+ payload = json .dumps (data )
118+ b_payload = payload .encode ()
119+ m = hmac .new (b'this is the master key' , b_payload , hashlib .sha256 )
120+
121+ headers = {
122+ 'Webhook-Signature' : m .hexdigest (),
123+ 'Content-Type' : 'application/json' ,
124+ }
125+ r = await cli .post ('/companies/create' , data = payload , headers = headers )
126+ assert r .status == 201
127+ curr = await db_conn .execute (sa_companies .select ())
128+ result = await curr .first ()
129+ assert result .name == 'foobar'
130+ await worker .run_check ()
131+ assert {(cs .id , cs .first_name , cs .last_name ) async for cs in await db_conn .execute (sa_contractors .select ())} == {
132+ (22 , 'James' , 'Higgins' ),
133+ (23 , None , 'Person 2' ),
134+ }
135+
136+
82137async def test_create_not_auth (cli ):
83138 data = json .dumps ({'name' : 'foobar' , '_request_time' : int (time ())})
84139 headers = {'Content-Type' : 'application/json' }
0 commit comments