def update_reference():
    print r"==update_reference=="
    client.send_data_to_server(r"ResetDataSource").get()
    parent = r"People(1)/Parent"
    person_id_property = r"PersonID"
    parentEntity = odata_client_python.to_entity_value(
        client.get_data_from_server(parent).get()[0])
    property_value = odata_client_python.odata_value()
    parentEntity.get_property_value(person_id_property, property_value)
    person_id = eval(
        odata_client_python.to_primitive_value(property_value).to_string())
    print person_id == 2
    newParentEntity = odata_client_python.to_entity_value(
        client.get_data_from_server(r"People(3)").get()[0])
    newParentEntity.get_property_value(
        odata_client_python.odata_json_constants.PAYLOAD_ANNOTATION_ID,
        property_value)
    newParentId = odata_client_python.to_primitive_value(
        property_value).to_string()
    client.update_reference(parent, newParentId).get()
    parentEntity = odata_client_python.to_entity_value(
        client.get_data_from_server(parent).get()[0])
    parentEntity.get_property_value(person_id_property, property_value)
    person_id = eval(
        odata_client_python.to_primitive_value(property_value).to_string())
    print person_id == 3
def action_of_primitive_value():
    print r"==action_of_primitive_value=="
    client.send_data_to_server(r"ResetDataSource").get()
    company_revenue_path = r"Company/Revenue"
    revenue_odata_value = client.get_data_from_server(
        company_revenue_path).get()[0]
    revenue_primitive_value = odata_client_python.to_primitive_value(
        revenue_odata_value)
    revenue = eval(revenue_primitive_value.to_string())
    print revenue == 100000
    parameters = odata_client_python.vector_odata_parameter()
    parameters.push_back(
        odata_client_python.odata_parameter(
            r"IncreaseValue",
            odata_client_python.odata_primitive_value.make_primitive_value(
                100000)))
    returned_values = odata_client_python.vector_odata_value()
    client.send_data_to_server(
        r"Company/Microsoft.Test.OData.Services.ODataWCFService.IncreaseRevenue",
        parameters, returned_values).get()
    print len(returned_values) == 1
    returned_value = returned_values[0]
    revenue_odata_value = client.get_data_from_server(
        company_revenue_path).get()[0]
    revenue_primitive_value = odata_client_python.to_primitive_value(
        revenue_odata_value)
    revenue = eval(revenue_primitive_value.to_string())
    print revenue == 200000
    returned_primitive_value = odata_client_python.to_primitive_value(
        returned_value)
    print eval(returned_primitive_value.to_string()) == 200000
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
Example #4
0
 def query_primitive(self, query_ex, ret_type):
     if self._client is None:
         return []
     values = self._client.get_data_from_server(query_ex).get()
     ret = []
     for value in values:
         if value is None:
             continue
         primitive_value = odata_client_python.to_primitive_value(value)
         if primitive_value is None:
             continue
         try:
             if ret_type is int:
                 val = int(primitive_value.to_string())
             elif ret_type is float:
                 val = float(primitive_value.to_string())
             elif ret_type is bool:
                 val = primitive_value.to_string() == "true"
             elif ret_type is str or ret_type is unicode:
                 val = primitive_value.to_string()
             else:
                 val = eval(primitive_value.to_string())
         except:
             val = primitive_value.to_string()
         ret.append(val)
     return ret
Example #5
0
 def operation_query_primitive(self, query_ex, parameters, is_function, ret_type):
     if self._client is None:
         return None
     ret_values = odata_client_python.vector_odata_value()
     self._client.send_data_to_server(query_ex, parameters, ret_values, odata_client_python.HTTP_GET if is_function else odata_client_python.HTTP_POST).get()
     ret = []
     for value in ret_values:
         if value is None:
             continue
         primitive_value = odata_client_python.to_primitive_value(value)
         if primitive_value is None:
             continue
         try:
             if ret_type in ("uint8_t", "int8_t", "int16_t", "int32_t", "int64_t") or ret_type is int:
                 val = int(primitive_value.to_string())
             elif ret_type in ("float", "double", "long double") or ret_type is float:
                 val = float(primitive_value.to_string())
             elif ret_type == "bool" or ret_type is bool:
                 val = primitive_value.to_string() == "true"
             elif ret_type == "::utility::string_t" or ret_type is str or ret_type is unicode:
                 val = primitive_value.to_string()
             else:
                 val = eval(primitive_value.to_string())
         except:
             val = primitive_value.to_string()
         ret.append(val)
     return ret
def invoke_unbound_function():
    print r"==invoke_unbound_function=="
    client.send_data_to_server(r"ResetDataSource").get()
    function_ret = client.get_data_from_server(r"Company/Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount()").get()
    print len(function_ret) == 1
    print function_ret[0].get_value_type().get_type_kind() == odata_client_python.Primitive
    primitive_value = odata_client_python.to_primitive_value(function_ret[0])
    print eval(primitive_value.to_string()) == 2
def simple_function():
    print r"==simple_function=="
    client.send_data_to_server(r"ResetDataSource").get()
    employees_count_path = r"Company/Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount"
    parameters = odata_client_python.vector_odata_parameter()
    returned_values = odata_client_python.vector_odata_value()
    client.send_data_to_server(employees_count_path, parameters, returned_values, odata_client_python.HTTP_GET).get()
    print len(returned_values) == 1
    print eval(odata_client_python.to_primitive_value(returned_values[0]).to_string()) == 2
def update_reference():
    print r"==update_reference=="
    client.send_data_to_server(r"ResetDataSource").get()
    parent = r"People(1)/Parent"
    person_id_property = r"PersonID"
    parentEntity = odata_client_python.to_entity_value(client.get_data_from_server(parent).get()[0])
    property_value = odata_client_python.odata_value()
    parentEntity.get_property_value(person_id_property, property_value)
    person_id = eval(odata_client_python.to_primitive_value(property_value).to_string())
    print person_id == 2
    newParentEntity = odata_client_python.to_entity_value(client.get_data_from_server(r"People(3)").get()[0])
    newParentEntity.get_property_value(odata_client_python.odata_json_constants.PAYLOAD_ANNOTATION_ID, property_value)
    newParentId = odata_client_python.to_primitive_value(property_value).to_string()
    client.update_reference(parent, newParentId).get()
    parentEntity = odata_client_python.to_entity_value(client.get_data_from_server(parent).get()[0])
    parentEntity.get_property_value(person_id_property, property_value)
    person_id = eval(odata_client_python.to_primitive_value(property_value).to_string())
    print person_id == 3
def query_collection_property():
    print r"==query_collection_property=="
    client.send_data_to_server(r"ResetDataSource").get()
    query_result = client.get_data_from_server(r"People(4)/Numbers").get()
    print len(query_result) == 3
    print query_result[0].get_value_type().get_type_kind() == odata_client_python.Primitive
    primitive_value = odata_client_python.to_primitive_value(query_result[1])
    number = primitive_value.to_string()
    print number == r"555-555-5555"
def update_entity_with_patch():
    print r"==update_entity_with_patch=="
    client.send_data_to_server(r"ResetDataSource").get()
    model = client.get_model().get()
    query_result = client.get_data_from_server(r"Accounts(101)").get()
    old_entity = odata_client_python.to_entity_value(query_result[0])
    old_value = odata_client_python.odata_value()
    old_entity.get_property_value(r"CountryRegion", old_value)
    old_country = odata_client_python.to_primitive_value(old_value)
    print old_country.to_string() == r"US"
    old_entity.set_value(r"CountryRegion", r"GB")
    response_code = client.patch_entity(r"Accounts", old_entity).get()
    print response_code == 204
    check_query = client.get_data_from_server(r"Accounts(101)").get()
    new_entity = odata_client_python.to_entity_value(check_query[0])
    property_value = odata_client_python.odata_value()
    print new_entity.get_property_value(r"CountryRegion", property_value)
    primitive_value = odata_client_python.to_primitive_value(property_value)
    print primitive_value.to_string() == r"GB"
def update_entity_with_patch():
    print r"==update_entity_with_patch=="
    client.send_data_to_server(r"ResetDataSource").get()
    model = client.get_model().get()
    query_result = client.get_data_from_server(r"Accounts(101)").get()
    old_entity = odata_client_python.to_entity_value(query_result[0])
    old_value = odata_client_python.odata_value()
    old_entity.get_property_value(r"CountryRegion", old_value)
    old_country = odata_client_python.to_primitive_value(old_value)
    print old_country.to_string() == r"US"
    old_entity.set_value(r"CountryRegion", r"GB")
    response_code = client.patch_entity(r"Accounts", old_entity).get()
    print response_code == 204
    check_query = client.get_data_from_server(r"Accounts(101)").get()
    new_entity = odata_client_python.to_entity_value(check_query[0])
    property_value = odata_client_python.odata_value()
    print new_entity.get_property_value(r"CountryRegion", property_value)
    primitive_value = odata_client_python.to_primitive_value(property_value)
    print primitive_value.to_string() == r"GB"
def query_collection_property():
    print r"==query_collection_property=="
    client.send_data_to_server(r"ResetDataSource").get()
    query_result = client.get_data_from_server(r"People(4)/Numbers").get()
    print len(query_result) == 3
    print query_result[0].get_value_type().get_type_kind(
    ) == odata_client_python.Primitive
    primitive_value = odata_client_python.to_primitive_value(query_result[1])
    number = primitive_value.to_string()
    print number == r"555-555-5555"
def query_primitive_property():
    print r"==query_primitive_property=="
    client.send_data_to_server(r"ResetDataSource").get()
    query_result = client.get_data_from_server(r"Products(7)/QuantityInStock").get()
    print len(query_result) == 1
    property_value = query_result[0]
    print property_value.get_value_type().get_type_kind() == odata_client_python.Primitive
    primitive_value = odata_client_python.to_primitive_value(property_value)
    quantity = eval(primitive_value.to_string())
    print quantity == 20
def query_single_entity():
    print r"==query_single_entity=="
    client.send_data_to_server(r"ResetDataSource").get()
    entities = client.get_data_from_server(r"People(3)/Microsoft.Test.OData.Services.ODataWCFService.Employee").get()
    print len(entities) == 1
    first_entity = odata_client_python.to_entity_value(entities[0])
    property_value = odata_client_python.odata_value()
    print first_entity.get_property_value(r"DateHired", property_value)
    print property_value.get_value_type().get_type_kind() == odata_client_python.Primitive
    primitive_value = odata_client_python.to_primitive_value(property_value)
    print primitive_value.to_string() == r"2010-12-13T00:00:00Z"
def action_of_primitive_value():
    print r"==action_of_primitive_value=="
    client.send_data_to_server(r"ResetDataSource").get()
    company_revenue_path = r"Company/Revenue"
    revenue_odata_value = client.get_data_from_server(company_revenue_path).get()[0]
    revenue_primitive_value = odata_client_python.to_primitive_value(revenue_odata_value)
    revenue = eval(revenue_primitive_value.to_string())
    print revenue == 100000
    parameters = odata_client_python.vector_odata_parameter()
    parameters.push_back(odata_client_python.odata_parameter(r"IncreaseValue", odata_client_python.odata_primitive_value.make_primitive_value(100000)))
    returned_values = odata_client_python.vector_odata_value()
    client.send_data_to_server(r"Company/Microsoft.Test.OData.Services.ODataWCFService.IncreaseRevenue", parameters, returned_values).get()
    print len(returned_values) == 1
    returned_value = returned_values[0]
    revenue_odata_value = client.get_data_from_server(company_revenue_path).get()[0]
    revenue_primitive_value = odata_client_python.to_primitive_value(revenue_odata_value)
    revenue = eval(revenue_primitive_value.to_string())
    print revenue == 200000
    returned_primitive_value = odata_client_python.to_primitive_value(returned_value)
    print eval(returned_primitive_value.to_string()) == 200000
def invoke_unbound_function():
    print r"==invoke_unbound_function=="
    client.send_data_to_server(r"ResetDataSource").get()
    function_ret = client.get_data_from_server(
        r"Company/Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount()"
    ).get()
    print len(function_ret) == 1
    print function_ret[0].get_value_type().get_type_kind(
    ) == odata_client_python.Primitive
    primitive_value = odata_client_python.to_primitive_value(function_ret[0])
    print eval(primitive_value.to_string()) == 2
def query_contained_entityset():
    print r"==query_contained_entityset=="
    client.send_data_to_server(r"ResetDataSource").get()
    entity_set = client.get_data_from_server(r"Accounts(101)/MyPaymentInstruments").get()
    print len(entity_set) == 3
    print entity_set[0].get_value_type().get_type_kind() == odata_client_python.Entity
    first_entity = odata_client_python.to_entity_value(entity_set[0])
    property_value = odata_client_python.odata_value()
    print first_entity.get_property_value(r"PaymentInstrumentID", property_value)
    primitive_value = odata_client_python.to_primitive_value(property_value)
    print eval(primitive_value.to_string()) == 101901
def query_entity_collection():
    print r"==query_entity_collection=="
    client.send_data_to_server(r"ResetDataSource").get()
    entities = client.get_data_from_server(r"People/Microsoft.Test.OData.Services.ODataWCFService.Customer").get()
    print len(entities) == 2
    first_entity = odata_client_python.to_entity_value(entities[0])
    property_value = odata_client_python.odata_value()
    print first_entity.get_property_value(r"City", property_value)
    print property_value.get_value_type().get_type_kind() == odata_client_python.Primitive
    primitive_value = odata_client_python.to_primitive_value(property_value)
    print primitive_value.to_string() == r"London"
def query_contained_single_valued_entity():
    print r"==query_contained_single_valued_entity=="
    client.send_data_to_server(r"ResetDataSource").get()
    entity_set = client.get_data_from_server(r"Accounts(101)/MyGiftCard").get()
    print len(entity_set) == 1
    print entity_set[0].get_value_type().get_type_kind() == odata_client_python.Entity
    first_entity = odata_client_python.to_entity_value(entity_set[0]);
    property_value = odata_client_python.odata_value()
    print first_entity.get_property_value(r"Amount", property_value);
    print property_value.get_value_type().get_type_kind() == odata_client_python.Primitive
    primitive_value = odata_client_python.to_primitive_value(property_value)
    print eval(primitive_value.to_string()) == 19.9
def query_primitive_property():
    print r"==query_primitive_property=="
    client.send_data_to_server(r"ResetDataSource").get()
    query_result = client.get_data_from_server(
        r"Products(7)/QuantityInStock").get()
    print len(query_result) == 1
    property_value = query_result[0]
    print property_value.get_value_type().get_type_kind(
    ) == odata_client_python.Primitive
    primitive_value = odata_client_python.to_primitive_value(property_value)
    quantity = eval(primitive_value.to_string())
    print quantity == 20
def query_navigaton_collection():
    print r"==query_navigaton_collection=="
    client.send_data_to_server(r"ResetDataSource").get()
    entities = client.get_data_from_server(r"Products(5)/Details").get()
    print len(entities) == 5
    first_entity = odata_client_python.to_entity_value(entities[1])
    property_value = odata_client_python.odata_value()
    print first_entity.get_property_value(r"@odata.editLink", property_value)
    print property_value.get_value_type().get_type_kind() == odata_client_python.PayloadAnnotation
    primitive_value = odata_client_python.to_primitive_value(property_value)
    edit_link = primitive_value.to_string()
    print edit_link == r"http://odatae2etest.azurewebsites.net/cpptest/DefaultService/ProductDetails(ProductID=5,ProductDetailID=3)"
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 query_navigaton_collection():
    print r"==query_navigaton_collection=="
    client.send_data_to_server(r"ResetDataSource").get()
    entities = client.get_data_from_server(r"Products(5)/Details").get()
    print len(entities) == 5
    first_entity = odata_client_python.to_entity_value(entities[1])
    property_value = odata_client_python.odata_value()
    print first_entity.get_property_value(r"@odata.editLink", property_value)
    print property_value.get_value_type().get_type_kind(
    ) == odata_client_python.PayloadAnnotation
    primitive_value = odata_client_python.to_primitive_value(property_value)
    edit_link = primitive_value.to_string()
    print edit_link == r"http://odatae2etest.azurewebsites.net/cpptest/DefaultService/ProductDetails(ProductID=5,ProductDetailID=3)"
def simple_function():
    print r"==simple_function=="
    client.send_data_to_server(r"ResetDataSource").get()
    employees_count_path = r"Company/Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount"
    parameters = odata_client_python.vector_odata_parameter()
    returned_values = odata_client_python.vector_odata_value()
    client.send_data_to_server(employees_count_path, parameters,
                               returned_values,
                               odata_client_python.HTTP_GET).get()
    print len(returned_values) == 1
    print eval(
        odata_client_python.to_primitive_value(
            returned_values[0]).to_string()) == 2
def query_complex_property():
    print r"==query_complex_property=="
    client.send_data_to_server(r"ResetDataSource").get()
    query_result = client.get_data_from_server(r"People(1)/HomeAddress").get()
    print len(query_result) == 1
    print query_result[0].get_value_type().get_type_kind() == odata_client_python.Complex
    property_value = odata_client_python.to_complex_value(query_result[0])
    street_field = odata_client_python.odata_value()
    print property_value.get_property_value(r"Street", street_field)
    print street_field.get_value_type().get_type_kind() == odata_client_python.Primitive
    primitive_value = odata_client_python.to_primitive_value(street_field)
    street = primitive_value.to_string()
    print street == r"1 Microsoft Way"
def add_reference():
    print r"==add_reference=="
    client.send_data_to_server(r"ResetDataSource").get()
    orders_of_customer1 = r"Customers(1)/Orders"
    orders = client.get_data_from_server(orders_of_customer1).get()
    print len(orders) == 1
    orderEntity = odata_client_python.to_entity_value(client.get_data_from_server(r"Orders(7)").get()[0])
    property_value = odata_client_python.odata_value()
    orderEntity.get_property_value(odata_client_python.odata_json_constants.PAYLOAD_ANNOTATION_ID, property_value)
    orderId = odata_client_python.to_primitive_value(property_value).to_string()
    client.add_reference(orders_of_customer1, orderId).get()
    orders = client.get_data_from_server(orders_of_customer1).get()
    print len(orders) == 2
def query_entity():
    print r"==query_entity=="
    client.send_data_to_server(r"ResetDataSource").get()
    query_result = client.get_data_from_server(r"Products(6)").get()
    print len(query_result) == 1
    print query_result[0].get_value_type().get_type_kind() == odata_client_python.Entity
    entity = odata_client_python.to_entity_value(query_result[0])
    property_value = odata_client_python.odata_value()
    print entity.get_property_value(r"UnitPrice", property_value)
    print property_value.get_value_type().get_type_kind() == odata_client_python.Primitive
    primitive_value = odata_client_python.to_primitive_value(property_value)
    unit_price = eval(primitive_value.to_string())
    print unit_price == 3.24
def delete_reference_in_collection_valued_navigation_property():
    print r"==delete_reference_in_collection_valued_navigation_property=="
    client.send_data_to_server(r"ResetDataSource").get()
    orders_of_customer1 = r"Customers(1)/Orders"
    orders = client.get_data_from_server(orders_of_customer1).get()
    print len(orders) == 1
    orderEntity = odata_client_python.to_entity_value(orders[0])
    property_value = odata_client_python.odata_value()
    orderEntity.get_property_value(odata_client_python.odata_json_constants.PAYLOAD_ANNOTATION_ID, property_value)
    orderId = odata_client_python.to_primitive_value(property_value).to_string()
    client.remove_reference(orders_of_customer1, orderId).get()
    orders = client.get_data_from_server(orders_of_customer1).get()
    print len(orders) == 0
def function_return_collection_of_complex_value():
    print r"==function_return_collection_of_complex_value=="
    client.send_data_to_server(r"ResetDataSource").get()
    product_details_path = r"Products(5)/Microsoft.Test.OData.Services.ODataWCFService.GetProductDetails"
    parameters = odata_client_python.vector_odata_parameter()
    parameters.push_back(odata_client_python.odata_parameter(r"count", odata_client_python.odata_primitive_value.make_primitive_value(3)))
    returned_values = odata_client_python.vector_odata_value()
    client.send_data_to_server(product_details_path, parameters, returned_values, odata_client_python.HTTP_GET).get()
    print len(returned_values) == 3
    detail1 = odata_client_python.to_entity_value(returned_values[0])
    property_value = odata_client_python.odata_value()
    detail1.get_property_value(r"ProductID", property_value)
    primitive_value = odata_client_python.to_primitive_value(property_value)
    print eval(primitive_value.to_string()) == 5
def query_entity_collection():
    print r"==query_entity_collection=="
    client.send_data_to_server(r"ResetDataSource").get()
    entities = client.get_data_from_server(
        r"People/Microsoft.Test.OData.Services.ODataWCFService.Customer").get(
        )
    print len(entities) == 2
    first_entity = odata_client_python.to_entity_value(entities[0])
    property_value = odata_client_python.odata_value()
    print first_entity.get_property_value(r"City", property_value)
    print property_value.get_value_type().get_type_kind(
    ) == odata_client_python.Primitive
    primitive_value = odata_client_python.to_primitive_value(property_value)
    print primitive_value.to_string() == r"London"
def query_entityset():
    print r"==query_entityset=="
    client.send_data_to_server(r"ResetDataSource").get()
    entity_set_name = r"Products"
    entity_set = client.get_entities(entity_set_name).get()
    print len(entity_set) == 5
    print entity_set[0].get_value_type().get_type_kind() == odata_client_python.Entity
    first_entity = entity_set[0]
    property_value = odata_client_python.odata_value()
    print first_entity.get_property_value(r"Name", property_value)
    print property_value.get_value_type().get_type_kind() == odata_client_python.Primitive
    primitive_value = odata_client_python.to_primitive_value(property_value)
    name = primitive_value.to_string()
    print name == r"Cheetos"
def query_contained_single_valued_entity():
    print r"==query_contained_single_valued_entity=="
    client.send_data_to_server(r"ResetDataSource").get()
    entity_set = client.get_data_from_server(r"Accounts(101)/MyGiftCard").get()
    print len(entity_set) == 1
    print entity_set[0].get_value_type().get_type_kind(
    ) == odata_client_python.Entity
    first_entity = odata_client_python.to_entity_value(entity_set[0])
    property_value = odata_client_python.odata_value()
    print first_entity.get_property_value(r"Amount", property_value)
    print property_value.get_value_type().get_type_kind(
    ) == odata_client_python.Primitive
    primitive_value = odata_client_python.to_primitive_value(property_value)
    print eval(primitive_value.to_string()) == 19.9
def query_contained_entityset():
    print r"==query_contained_entityset=="
    client.send_data_to_server(r"ResetDataSource").get()
    entity_set = client.get_data_from_server(
        r"Accounts(101)/MyPaymentInstruments").get()
    print len(entity_set) == 3
    print entity_set[0].get_value_type().get_type_kind(
    ) == odata_client_python.Entity
    first_entity = odata_client_python.to_entity_value(entity_set[0])
    property_value = odata_client_python.odata_value()
    print first_entity.get_property_value(r"PaymentInstrumentID",
                                          property_value)
    primitive_value = odata_client_python.to_primitive_value(property_value)
    print eval(primitive_value.to_string()) == 101901
def query_single_entity():
    print r"==query_single_entity=="
    client.send_data_to_server(r"ResetDataSource").get()
    entities = client.get_data_from_server(
        r"People(3)/Microsoft.Test.OData.Services.ODataWCFService.Employee"
    ).get()
    print len(entities) == 1
    first_entity = odata_client_python.to_entity_value(entities[0])
    property_value = odata_client_python.odata_value()
    print first_entity.get_property_value(r"DateHired", property_value)
    print property_value.get_value_type().get_type_kind(
    ) == odata_client_python.Primitive
    primitive_value = odata_client_python.to_primitive_value(property_value)
    print primitive_value.to_string() == r"2010-12-13T00:00:00Z"
def query_entity():
    print r"==query_entity=="
    client.send_data_to_server(r"ResetDataSource").get()
    query_result = client.get_data_from_server(r"Products(6)").get()
    print len(query_result) == 1
    print query_result[0].get_value_type().get_type_kind(
    ) == odata_client_python.Entity
    entity = odata_client_python.to_entity_value(query_result[0])
    property_value = odata_client_python.odata_value()
    print entity.get_property_value(r"UnitPrice", property_value)
    print property_value.get_value_type().get_type_kind(
    ) == odata_client_python.Primitive
    primitive_value = odata_client_python.to_primitive_value(property_value)
    unit_price = eval(primitive_value.to_string())
    print unit_price == 3.24
def query_basic_properties_in_entity():
    print r"==query_basic_properties_in_entity=="
    client.send_data_to_server(r"ResetDataSource").get()
    query_result = client.get_data_from_server(r"People(4)").get()
    print len(query_result) == 1
    print query_result[0].get_value_type().get_type_kind() == odata_client_python.Entity
    entity = odata_client_python.to_entity_value(query_result[0])
    collection_property = odata_client_python.odata_value()
    print entity.get_property_value(r"Numbers", collection_property)
    print collection_property.get_value_type().get_type_kind() == odata_client_python.Collection
    collection_value = odata_client_python.to_collection_value(collection_property)
    collection_vector = collection_value.get_collection_values()
    print len(collection_vector) == 3
    collection_member = odata_client_python.to_primitive_value(collection_vector[1])
    print collection_member.to_string() == r"555-555-5555"
def query_complex_property():
    print r"==query_complex_property=="
    client.send_data_to_server(r"ResetDataSource").get()
    query_result = client.get_data_from_server(r"People(1)/HomeAddress").get()
    print len(query_result) == 1
    print query_result[0].get_value_type().get_type_kind(
    ) == odata_client_python.Complex
    property_value = odata_client_python.to_complex_value(query_result[0])
    street_field = odata_client_python.odata_value()
    print property_value.get_property_value(r"Street", street_field)
    print street_field.get_value_type().get_type_kind(
    ) == odata_client_python.Primitive
    primitive_value = odata_client_python.to_primitive_value(street_field)
    street = primitive_value.to_string()
    print street == r"1 Microsoft Way"
def delete_reference_in_collection_valued_navigation_property():
    print r"==delete_reference_in_collection_valued_navigation_property=="
    client.send_data_to_server(r"ResetDataSource").get()
    orders_of_customer1 = r"Customers(1)/Orders"
    orders = client.get_data_from_server(orders_of_customer1).get()
    print len(orders) == 1
    orderEntity = odata_client_python.to_entity_value(orders[0])
    property_value = odata_client_python.odata_value()
    orderEntity.get_property_value(
        odata_client_python.odata_json_constants.PAYLOAD_ANNOTATION_ID,
        property_value)
    orderId = odata_client_python.to_primitive_value(
        property_value).to_string()
    client.remove_reference(orders_of_customer1, orderId).get()
    orders = client.get_data_from_server(orders_of_customer1).get()
    print len(orders) == 0
def query_entityset():
    print r"==query_entityset=="
    client.send_data_to_server(r"ResetDataSource").get()
    entity_set_name = r"Products"
    entity_set = client.get_entities(entity_set_name).get()
    print len(entity_set) == 5
    print entity_set[0].get_value_type().get_type_kind(
    ) == odata_client_python.Entity
    first_entity = entity_set[0]
    property_value = odata_client_python.odata_value()
    print first_entity.get_property_value(r"Name", property_value)
    print property_value.get_value_type().get_type_kind(
    ) == odata_client_python.Primitive
    primitive_value = odata_client_python.to_primitive_value(property_value)
    name = primitive_value.to_string()
    print name == r"Cheetos"
def add_reference():
    print r"==add_reference=="
    client.send_data_to_server(r"ResetDataSource").get()
    orders_of_customer1 = r"Customers(1)/Orders"
    orders = client.get_data_from_server(orders_of_customer1).get()
    print len(orders) == 1
    orderEntity = odata_client_python.to_entity_value(
        client.get_data_from_server(r"Orders(7)").get()[0])
    property_value = odata_client_python.odata_value()
    orderEntity.get_property_value(
        odata_client_python.odata_json_constants.PAYLOAD_ANNOTATION_ID,
        property_value)
    orderId = odata_client_python.to_primitive_value(
        property_value).to_string()
    client.add_reference(orders_of_customer1, orderId).get()
    orders = client.get_data_from_server(orders_of_customer1).get()
    print len(orders) == 2
def query_basic_properties_in_entity():
    print r"==query_basic_properties_in_entity=="
    client.send_data_to_server(r"ResetDataSource").get()
    query_result = client.get_data_from_server(r"People(4)").get()
    print len(query_result) == 1
    print query_result[0].get_value_type().get_type_kind(
    ) == odata_client_python.Entity
    entity = odata_client_python.to_entity_value(query_result[0])
    collection_property = odata_client_python.odata_value()
    print entity.get_property_value(r"Numbers", collection_property)
    print collection_property.get_value_type().get_type_kind(
    ) == odata_client_python.Collection
    collection_value = odata_client_python.to_collection_value(
        collection_property)
    collection_vector = collection_value.get_collection_values()
    print len(collection_vector) == 3
    collection_member = odata_client_python.to_primitive_value(
        collection_vector[1])
    print collection_member.to_string() == r"555-555-5555"
def function_return_collection_of_complex_value():
    print r"==function_return_collection_of_complex_value=="
    client.send_data_to_server(r"ResetDataSource").get()
    product_details_path = r"Products(5)/Microsoft.Test.OData.Services.ODataWCFService.GetProductDetails"
    parameters = odata_client_python.vector_odata_parameter()
    parameters.push_back(
        odata_client_python.odata_parameter(
            r"count",
            odata_client_python.odata_primitive_value.make_primitive_value(3)))
    returned_values = odata_client_python.vector_odata_value()
    client.send_data_to_server(product_details_path, parameters,
                               returned_values,
                               odata_client_python.HTTP_GET).get()
    print len(returned_values) == 3
    detail1 = odata_client_python.to_entity_value(returned_values[0])
    property_value = odata_client_python.odata_value()
    detail1.get_property_value(r"ProductID", property_value)
    primitive_value = odata_client_python.to_primitive_value(property_value)
    print eval(primitive_value.to_string()) == 5
def create_contained_entity():
    print r"==create_contained_entity=="
    client.send_data_to_server(r"ResetDataSource").get()
    model = client.get_model().get()
    entity_type_name = r"PaymentInstrument"
    entity = odata_client_python.odata_entity_value(model.find_entity_type(entity_type_name))
    entity.set_value(r"PaymentInstrumentID", 101920)
    entity.set_value(r"FriendlyName", r"created by cpp test")
    now = odata_client_python.datetime.utc_now()
    entity.set_value(r"CreatedDate", now)
    response_code = client.create_entity(r"Accounts(101)/MyPaymentInstruments", entity).get()
    print response_code == 201
    query_result = client.get_data_from_server(r"Accounts(101)/MyPaymentInstruments(101920)").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"FriendlyName", property_value)
    primitive_value = odata_client_python.to_primitive_value(property_value)
    print primitive_value.to_string() == r"created by cpp test"
def create_contained_single_valued_entity():
    print r"==create_contained_single_valued_entity=="
    client.send_data_to_server(r"ResetDataSource").get()
    model = client.get_model().get()
    entity_type_name = r"GiftCard"
    entity = odata_client_python.odata_entity_value(model.find_entity_type(entity_type_name))
    entity.set_value(r"GiftCardID", 304)
    card_number = r"AAASSSDD30"
    entity.set_value(r"GiftCardNO", card_number)
    entity.set_value(r"Amount", 132.0)
    now = odata_client_python.datetime.utc_now()
    entity.set_value(r"ExperationDate", now)
    response_code = client.send_data_to_server(r"Accounts(104)/MyGiftCard", entity, r"PATCH").get()
    print response_code == 204
    query_result = client.get_data_from_server(r"Accounts(104)/MyGiftCard").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"Amount", property_value)
    primitive_value = odata_client_python.to_primitive_value(property_value)
    print eval(primitive_value.to_string()) == 132.0
def create_contained_entity():
    print r"==create_contained_entity=="
    client.send_data_to_server(r"ResetDataSource").get()
    model = client.get_model().get()
    entity_type_name = r"PaymentInstrument"
    entity = odata_client_python.odata_entity_value(
        model.find_entity_type(entity_type_name))
    entity.set_value(r"PaymentInstrumentID", 101920)
    entity.set_value(r"FriendlyName", r"created by cpp test")
    now = odata_client_python.datetime.utc_now()
    entity.set_value(r"CreatedDate", now)
    response_code = client.create_entity(r"Accounts(101)/MyPaymentInstruments",
                                         entity).get()
    print response_code == 201
    query_result = client.get_data_from_server(
        r"Accounts(101)/MyPaymentInstruments(101920)").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"FriendlyName", property_value)
    primitive_value = odata_client_python.to_primitive_value(property_value)
    print primitive_value.to_string() == r"created by cpp test"
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_contained_single_valued_entity():
    print r"==create_contained_single_valued_entity=="
    client.send_data_to_server(r"ResetDataSource").get()
    model = client.get_model().get()
    entity_type_name = r"GiftCard"
    entity = odata_client_python.odata_entity_value(
        model.find_entity_type(entity_type_name))
    entity.set_value(r"GiftCardID", 304)
    card_number = r"AAASSSDD30"
    entity.set_value(r"GiftCardNO", card_number)
    entity.set_value(r"Amount", 132.0)
    now = odata_client_python.datetime.utc_now()
    entity.set_value(r"ExperationDate", now)
    response_code = client.send_data_to_server(r"Accounts(104)/MyGiftCard",
                                               entity, r"PATCH").get()
    print response_code == 204
    query_result = client.get_data_from_server(
        r"Accounts(104)/MyGiftCard").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"Amount", property_value)
    primitive_value = odata_client_python.to_primitive_value(property_value)
    print eval(primitive_value.to_string()) == 132.0
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