def update_service_callback_api(service_id, callback_api_id): data = request.get_json() validate(data, update_service_callback_api_schema) to_update = get_service_callback_api(callback_api_id, service_id) reset_service_callback_api(service_callback_api=to_update, updated_by_id=data["updated_by_id"], url=data.get("url", None), bearer_token=data.get("bearer_token", None)) return jsonify(data=to_update.serialize()), 200
def test_update_service_callback_api(sample_service): service_callback_api = ServiceCallbackApi( service_id=sample_service.id, url="https://some_service/callback_endpoint", bearer_token="some_unique_string", updated_by_id=sample_service.users[0].id, ) save_service_callback_api(service_callback_api) results = ServiceCallbackApi.query.all() assert len(results) == 1 saved_callback_api = results[0] reset_service_callback_api( saved_callback_api, updated_by_id=sample_service.users[0].id, url="https://some_service/changed_url", ) updated_results = ServiceCallbackApi.query.all() assert len(updated_results) == 1 updated = updated_results[0] assert updated.id is not None assert updated.service_id == sample_service.id assert updated.updated_by_id == sample_service.users[0].id assert updated.url == "https://some_service/changed_url" assert updated.bearer_token == "some_unique_string" assert updated._bearer_token != "some_unique_string" assert updated.updated_at is not None versioned_results = ServiceCallbackApi.get_history_model().query.filter_by( id=saved_callback_api.id).all() assert len(versioned_results) == 2 for x in versioned_results: if x.version == 1: assert x.url == "https://some_service/callback_endpoint" assert not x.updated_at elif x.version == 2: assert x.url == "https://some_service/changed_url" assert x.updated_at else: pytest.fail("version should not exist") assert x.id is not None assert x.service_id == sample_service.id assert x.updated_by_id == sample_service.users[0].id assert encryption.decrypt(x._bearer_token) == "some_unique_string"