def test_entity_key_simple_valid(service): """Test valid single value for simple key""" # pylint: disable=redefined-outer-name key = EntityKey(service.schema.entity_type('MasterEntity'), '1') assert key.to_key_string() == "('1')"
def test_entity_key_complex_valid(service): """Test valid creationg of complex key""" key = EntityKey( service.schema.entity_type('TemperatureMeasurement'), Sensor='sensor1', Date=datetime.datetime(2017, 12, 24, 18, 0)) assert key.to_key_string() == "(Sensor='sensor1',Date=datetime'2017-12-24T18:00:00')"
def test_entity_key_simple_named_valid(service): """Test valid single named value for simple key""" key = EntityKey( service.schema.entity_type('MasterEntity'), Key='1') assert key.to_key_string() == "(Key='1')"
def test_entity_key_complex_single_value(service): """Test rejection of single value for complex key""" with pytest.raises(PyODataException) as e_info: EntityKey(service.schema.entity_type('TemperatureMeasurement'), 1) assert str(e_info.value).startswith('Key of entity type')
def test_entity_key_simple_named_invalid(service): """Test invalid single named value for simple key""" with pytest.raises(PyODataException) as e_info: EntityKey(service.schema.entity_type('MasterEntity'), XXX='1') assert str(e_info.value).startswith('Missing value for key property Key')
def test_delete_entity_with_key(service): """Check deleting of entity with key""" responses.add(responses.DELETE, f"{service.url}/Employees(ID=23)", status=204) key = EntityKey(service.schema.entity_type('Employee'), ID=23) request = service.entity_sets.Employees.delete_entity(key=key) assert isinstance(request, pyodata.v2.service.EntityDeleteRequest) assert request.execute() is None
def test_update_entity_with_entity_key(service): """Make sure the method update_entity handles correctly the parameter key which is EntityKey""" # pylint: disable=redefined-outer-name key = EntityKey(service.schema.entity_type('TemperatureMeasurement'), Sensor='sensor1', Date=datetime.datetime(2017, 12, 24, 18, 0)) query = service.entity_sets.TemperatureMeasurements.update_entity(key) assert query.get_path( ) == "TemperatureMeasurements(Sensor='sensor1',Date=datetime'2017-12-24T18:00:00')"
def test_delete_entity_http_error(service): """Check if error is raisen when deleting unknown entity""" responses.add(responses.DELETE, f"{service.url}/Employees(ID=23)", status=404) key = EntityKey(service.schema.entity_type('Employee'), ID=23) request = service.entity_sets.Employees.delete_entity(key=key) assert isinstance(request, pyodata.v2.service.EntityDeleteRequest) with pytest.raises(HttpError) as caught_ex: request.execute() assert str(caught_ex.value).startswith('HTTP POST for Entity delete') assert caught_ex.value.response.status_code == 404