def _entity_type_to_schema(entity_type: EntityType) -> str: res = f"CREATE TABLE odata.{to_pg_name(entity_type.name)} (\n " res += ",\n ".join( [_property_to_schema(p) for p in entity_type.proprties()]) + "," res += f"\n {key_to_schema(entity_type.key_proprties)}" res += "\n);" return res
def test_complex_serializer(schema): """Test de/serializer of complex edm types""" # pylint: disable=redefined-outer-name # encode without edm type information with pytest.raises(PyODataException) as e_info: EdmStructTypeSerializer().to_literal(None, 'something') assert str(e_info.value).startswith('Cannot encode value something') # decode without edm type information with pytest.raises(PyODataException) as e_info: EdmStructTypeSerializer().from_json(None, 'something') assert str(e_info.value).startswith('Cannot decode value something') # entity without properties entity_type = EntityType('Box', 'Box', False) srl = EdmStructTypeSerializer() assert srl.to_literal(entity_type, 'something') == {} assert srl.from_json(entity_type, 'something') == {} # entity with properties of ODATA primitive types entity_type = schema.entity_type('TemperatureMeasurement') assert srl.to_literal(entity_type, { 'ignored-key': 'ignored-value', 'Sensor': 'x' }) == { 'Sensor': "'x'" } assert srl.from_json(entity_type, { 'ignored-key': 'ignored-value', 'Sensor': "'x'" }) == { 'Sensor': 'x' }
def get_entity_type_property_names(entity_type: EntityType) -> List[str]: """Name of all properties for a given entity type""" return [p.name for p in entity_type.proprties()]