def action_of_complex_value():
    print r"==action_of_complex_value=="
    client.send_data_to_server(r"ResetDataSource").get()
    home_address = r"People(1)/HomeAddress"
    home_address_value = odata_client_python.to_complex_value(client.get_data_from_server(home_address).get()[0])
    property_value = odata_client_python.odata_value()
    home_address_value.get_property_value(r"City", property_value)
    print odata_client_python.to_primitive_value(property_value).to_string() == r"Tokyo"
    model = client.get_model().get()
    address_type = model.find_complex_type(r"Address")
    new_address1 = odata_client_python.odata_complex_value(address_type)
    new_address1.set_value(r"City", r"Shanghai")
    new_address1.set_value(r"PostalCode", r"200000")
    new_address1.set_value(r"Street", r"Zixing Road")
    addresses = odata_client_python.odata_collection_value(odata_client_python.edm_collection_type(r"AddressCollection", address_type))
    addresses.add_collection_value(new_address1)
    parameters = odata_client_python.vector_odata_parameter()
    parameters.push_back(odata_client_python.odata_parameter(r"addresses", addresses))
    parameters.push_back(odata_client_python.odata_parameter(r"index", odata_client_python.odata_primitive_value.make_primitive_value(0)))
    returned_values = odata_client_python.vector_odata_value()
    client.send_data_to_server(r"People(1)/Microsoft.Test.OData.Services.ODataWCFService.ResetAddress", parameters, returned_values).get()
    print len(returned_values) == 1
    returned_value = returned_values[0]
    home_address_value = odata_client_python.to_complex_value(client.get_data_from_server(home_address).get()[0])
    home_address_value.get_property_value(r"City", property_value)
    print odata_client_python.to_primitive_value(property_value).to_string() == r"Shanghai"
    returned_entity_value = odata_client_python.to_entity_value(returned_value)
    returned_entity_value.get_property_value(r"HomeAddress", property_value)
    odata_client_python.to_complex_value(property_value).get_property_value(r"City", property_value)
    print odata_client_python.to_primitive_value(property_value).to_string() == r"Shanghai"
def create_entity():
    print r"==create_entity=="
    client.send_data_to_server(r"ResetDataSource").get()
    model = client.get_model().get()
    entity_set_name = r"Accounts"
    entity = odata_client_python.odata_entity_value(
        model.find_container().find_entity_set(
            entity_set_name).get_entity_type())
    entity.set_value(r"AccountID", 130)
    entity.set_value(r"CountryRegion", "CN")
    account_info = odata_client_python.odata_complex_value(
        model.find_complex_type(r"AccountInfo"))
    account_firstname = r"cpp"
    account_lastname = r"client"
    account_info.set_value(r"FirstName", account_firstname)
    account_info.set_value(r"LastName", account_lastname)
    entity.set_value(r"AccountInfo", account_info)
    response_code = client.create_entity(entity_set_name, entity).get()
    print response_code == 201
    query_result = client.get_data_from_server(r"Accounts(130)").get()
    print len(query_result) == 1
    new_entity = odata_client_python.to_entity_value(query_result[0])
    property_value = odata_client_python.odata_value()
    print entity.get_property_value(r"AccountID", property_value)
    primitive_value = odata_client_python.to_primitive_value(property_value)
    new_id = eval(primitive_value.to_string())
    print new_id == 130
def action_of_complex_value():
    print r"==action_of_complex_value=="
    client.send_data_to_server(r"ResetDataSource").get()
    home_address = r"People(1)/HomeAddress"
    home_address_value = odata_client_python.to_complex_value(
        client.get_data_from_server(home_address).get()[0])
    property_value = odata_client_python.odata_value()
    home_address_value.get_property_value(r"City", property_value)
    print odata_client_python.to_primitive_value(
        property_value).to_string() == r"Tokyo"
    model = client.get_model().get()
    address_type = model.find_complex_type(r"Address")
    new_address1 = odata_client_python.odata_complex_value(address_type)
    new_address1.set_value(r"City", r"Shanghai")
    new_address1.set_value(r"PostalCode", r"200000")
    new_address1.set_value(r"Street", r"Zixing Road")
    addresses = odata_client_python.odata_collection_value(
        odata_client_python.edm_collection_type(r"AddressCollection",
                                                address_type))
    addresses.add_collection_value(new_address1)
    parameters = odata_client_python.vector_odata_parameter()
    parameters.push_back(
        odata_client_python.odata_parameter(r"addresses", addresses))
    parameters.push_back(
        odata_client_python.odata_parameter(
            r"index",
            odata_client_python.odata_primitive_value.make_primitive_value(0)))
    returned_values = odata_client_python.vector_odata_value()
    client.send_data_to_server(
        r"People(1)/Microsoft.Test.OData.Services.ODataWCFService.ResetAddress",
        parameters, returned_values).get()
    print len(returned_values) == 1
    returned_value = returned_values[0]
    home_address_value = odata_client_python.to_complex_value(
        client.get_data_from_server(home_address).get()[0])
    home_address_value.get_property_value(r"City", property_value)
    print odata_client_python.to_primitive_value(
        property_value).to_string() == r"Shanghai"
    returned_entity_value = odata_client_python.to_entity_value(returned_value)
    returned_entity_value.get_property_value(r"HomeAddress", property_value)
    odata_client_python.to_complex_value(property_value).get_property_value(
        r"City", property_value)
    print odata_client_python.to_primitive_value(
        property_value).to_string() == r"Shanghai"
def create_entity():
    print r"==create_entity=="
    client.send_data_to_server(r"ResetDataSource").get()
    model = client.get_model().get()
    entity_set_name = r"Accounts"
    entity = odata_client_python.odata_entity_value(model.find_container().find_entity_set(entity_set_name).get_entity_type())
    entity.set_value(r"AccountID", 130)
    entity.set_value(r"CountryRegion", "CN")
    account_info = odata_client_python.odata_complex_value(model.find_complex_type(r"AccountInfo"))
    account_firstname = r"cpp"
    account_lastname = r"client"
    account_info.set_value(r"FirstName", account_firstname)
    account_info.set_value(r"LastName", account_lastname)
    entity.set_value(r"AccountInfo", account_info)
    response_code = client.create_entity(entity_set_name, entity).get()
    print response_code == 201
    query_result = client.get_data_from_server(r"Accounts(130)").get()
    print len(query_result) == 1
    new_entity = odata_client_python.to_entity_value(query_result[0])
    property_value = odata_client_python.odata_value()
    print entity.get_property_value(r"AccountID", property_value)
    primitive_value = odata_client_python.to_primitive_value(property_value)
    new_id = eval(primitive_value.to_string())
    print new_id == 130