def test_modify_OK(self): with mock.patch('D365BCAPI.D365BCv1API.requests') as mocked_req: mocked_req.get.return_value.status_code = 200 mocked_req.patch.return_value.status_code = 200 mocked_req.patch.return_value.reason = 'OK' modi = Connect('http://test.lt/test(123456789abcd)', auth={'a': 'a'}, headers={'some headers'}) respo = modi.modify(json_body={"orderid": "123456"}) mocked_req.patch.assert_called_with('http://test.lt/test(123456789abcd)', auth={'a': 'a'}, headers={'some headers'}, json={"orderid": "123456"}) self.assertEqual(respo, [200, 'OK'], 'modify: no error - returns [204, OK]')
def test_modify_FAIL(self): with mock.patch('D365BCAPI.D365BCv1API.requests') as mocked_req: mocked_req.get.return_value.status_code = 200 mocked_req.patch.return_value.status_code = 400 mocked_req.patch.return_value.reason = 'Any error reason' # error message modi = Connect('http://test.lt/test(123456789abcd)', auth={'a': 'a'}, headers={'some headers'}) respo = modi.modify(json_body={"orderid": "123456"}) mocked_req.patch.assert_called_with('http://test.lt/test(123456789abcd)', auth={'a': 'a'}, headers={'some headers'}, json={"orderid": "123456"}) self.assertEqual(respo, [], 'modify: on error returns blank') self.assertEqual(modi.except_error, [400, 'Any error reason'], 'modify: on error variable except_error ' 'must to include error code and reason')
if (len(response_list) > 0) and sol.except_error is None: line_id = response_list[0].get('id') # get line id print(f"Line id is {line_id}") print("description before update is", response_list[0].get("description")) else: raise Exception(sol.except_error) # modify exiting line: it is line no 30000 line_update = { "description": "This is updated Comments line" } # new info to update line sol.url = f"http://bs17:7048/BC/api/v1.0/salesOrderLines('{line_id}')" # adding line_id to url sol.filter_text = '' # for beta api document key was document id and sequence # sol.url = f"http://bs17:7048/BC/api/v1.0/salesOrderLines({so_id},{line_no})" response_list = sol.modify( line_update) # update line in parameters new info dic if (len(response_list) > 0) and sol.except_error is None: print( "Modified line 30000 description now is 'This is updated Comments line'", response_list) else: raise Exception(sol.except_error) # delete line line_no = 37500 # line No (sequence in response json) # in API beta order line url includes document id and line no (line primary key) # sol.url = f"http://bs17:7048/BC/api/v1.0/salesOrderLines({so_id},{line_no})" ## # in API v1.0 we need to find sales line id and identify it by id # we looking for line with sequence 37500