def test_pickle_roundtrip(): response = Response() response.json = MagicMock(return_value=DBT_RPC_RESPONSE_DICT) dro = DbtRpcOutput(response=response) dro_new = pickle.loads(pickle.dumps(dro)) assert dro_new.result == dro.result assert dro_new.response_dict == dro.response_dict assert dro_new.response.text == dro.response.text
def test_dbt_rpc_single_op(self, op: str): op_solid, op_config = SINGLE_OP_CONFIGS[op] mocked_rpc_client = MagicMock(spec=DbtRpcClient) mocked_client_op_method = getattr(mocked_rpc_client, op) @resource def mock_dbt_rpc_resource(_init_context): return mocked_rpc_client response_sentinel_value = "<rpc response: {}>".format(uuid.uuid4()) request_token_sentinel_value = "<request token: {}>".format( uuid.uuid4()) mock_response = MagicMock() mock_response.text = response_sentinel_value mock_response.json.return_value = { "result": { "request_token": request_token_sentinel_value } } mocked_client_op_method.return_value = DbtRpcOutput( response=mock_response) configured_solid = configured(op_solid, name="configured_solid")(op_config) instance = DagsterInstance.ephemeral() result = execute_pipeline( PipelineDefinition( [configured_solid], name="test", mode_defs=[ ModeDefinition( resource_defs={"dbt_rpc": mock_dbt_rpc_resource}) ], ), instance=instance, ) mocked_client_op_method.assert_called_once_with(**op_config) assert (result.output_for_solid( configured_solid.name, "request_token") == request_token_sentinel_value) assert any(response_sentinel_value in event.message for event in instance.all_logs(result.run_id))
def test_from_dict(self): dro = DbtRpcOutput.from_dict(DBT_RPC_RESULT_DICT) assert len(dro.result) == len(DBT_RPC_RESULT_DICT["results"])
def test_pickle_roundtrip(self): # pylint: disable=unused-argument dco = DbtRpcOutput.from_dict(DBT_RPC_RESULT_DICT) assert pickle.loads(pickle.dumps(dco)) == dco
def test_attributes(): response = Response() response.json = MagicMock(return_value=DBT_RPC_RESPONSE_DICT) dro = DbtRpcOutput(response=response) assert len(dro.result["results"]) == len( DBT_RPC_RESPONSE_DICT["result"]["results"])