def test_upsert_index_as_primary_key(): s = utils.session() dataset = utils.dataset() url = tc.URL(path="datasets/1:updateRecords") updates = [ tc.record._create_command(record, primary_key_name="primary_key") for record in _records_with_keys_json_2 ] snoop: Dict = {} responses.add_callback( responses.POST, str(url), partial( utils.capture_payload, snoop=snoop, status=200, response_json=_response_json ), ) df = pd.DataFrame( _records_json_2, index=[record["primary_key"] for record in _records_with_keys_json_2], ) df.index.name = "primary_key" response = tc.dataframe.upsert(s, dataset, df, primary_key_name="primary_key") assert response == _response_json assert snoop["payload"] == utils.stringify(updates)
def test_upsert(): s = utils.session() dataset = utils.dataset() url = tc.URL(path="datasets/1:updateRecords") updates = [ tc.record._create_command(record, primary_key_name="primary_key") for record in _records_json ] snoop: Dict = {} responses.add_callback( responses.POST, str(url), partial(utils.capture_payload, snoop=snoop, status=200, response_json=_response_json), ) response = tc.record.upsert(s, dataset, _records_json, primary_key_name="primary_key") assert response == _response_json assert snoop["payload"] == utils.stringify(updates)