Skip to content

Commit

Permalink
V4 service test implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mamiksik committed Apr 17, 2020
1 parent 7fba358 commit 06320bf
Show file tree
Hide file tree
Showing 23 changed files with 1,626 additions and 1,477 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ build_olingo:
$(DOCKER_BIN) build -t $(DOCKER_NAME) $(TESTS_OLINGO_SERVER)

run_olingo:
$(DOCKER_BIN) run -it -p 8888:8080 --name $(DOCKER_NAME) $(DOCKER_NAME):latest
$(DOCKER_BIN) run -d -it -p 8888:8080 --name $(DOCKER_NAME) $(DOCKER_NAME):latest

stop_olingo:
$(DOCKER_BIN) stop $(DOCKER_NAME)
Expand Down
10 changes: 8 additions & 2 deletions pyodata/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from pyodata.exceptions import PyODataException, HttpError
from pyodata.v2.service import Service
from pyodata.v2 import ODataV2
from pyodata.v4 import ODataV4

import pyodata.v4 as v4


def _fetch_metadata(connection, url, logger):
Expand Down Expand Up @@ -62,11 +65,14 @@ def __new__(cls, url, connection, namespaces=None,
config.namespaces = namespaces

# create model instance from received metadata
logger.info('Creating OData Schema (version: %d)', config.odata_version)
logger.info('Creating OData Schema (version: %s)', str(config.odata_version))
schema = MetadataBuilder(metadata, config=config).build()

# create service instance based on model we have
logger.info('Creating OData Service (version: %d)', config.odata_version)
logger.info('Creating OData Service (version: %s)', str(config.odata_version))

service = Service(url, schema, connection)
if config.odata_version == ODataV4:
return v4.Service(url, schema, connection)

return service
6 changes: 6 additions & 0 deletions pyodata/model/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,19 @@ def to_literal(self, value):

return [self._item_type.traits.to_literal(v) for v in value]

def to_json(self, value):
return self.to_literal(value)

# pylint: disable=no-self-use
def from_json(self, value):
if not isinstance(value, list):
raise PyODataException('Bad format: invalid list value {}'.format(value))

return [self._item_type.traits.from_json(v) for v in value]

def from_literal(self, value):
return self.from_json(value)


class VariableDeclaration(Identifier):
MAXIMUM_LENGTH = -1
Expand Down
10 changes: 5 additions & 5 deletions pyodata/v2/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def _build_values(entity_type: EntityType, entity: Any) -> Any:
val = entity_type.proprty(key).typ.traits.to_json(val) # type: ignore
except PyODataModelError:
try:
nav_prop = entity_type.nav_proprty(key) # type: ignore
nav_prop = entity_type.nav_proprty(key) # type: ignore
val = EntityCreateRequest._build_values(nav_prop.typ, val)
except PyODataModelError:
raise PyODataException('Property {} is not declared in {} entity type'.format(
Expand Down Expand Up @@ -691,7 +691,7 @@ def parameter(self, name: str, value: int) -> 'FunctionRequest':

# check if param is valid (is declared in metadata)
try:
param = self._function_import.get_parameter(name) # type: ignore
param = self._function_import.get_parameter(name) # type: ignore

# add parameter as custom query argument
self.custom(param.name, param.typ.traits.to_literal(value))
Expand Down Expand Up @@ -734,7 +734,7 @@ def __init__(self, service: 'Service', entity_set: Union[EntitySet, 'EntitySetPr
if proprties is not None:

# first, cache values of direct properties
for type_proprty in self._entity_type.proprties(): # type: ignore
for type_proprty in self._entity_type.proprties(): # type: ignore
if type_proprty.name in proprties:
if proprties[type_proprty.name] is not None:
self._cache[type_proprty.name] = type_proprty.typ.traits.from_json(proprties[type_proprty.name])
Expand Down Expand Up @@ -812,7 +812,7 @@ def nav(self, nav_property: str) -> Union['NavEntityProxy', 'EntitySetProxy']:

# for now duplicated with simillar method in entity set proxy class
try:
navigation_property = self._entity_type.nav_proprty(nav_property) # type: ignore
navigation_property = self._entity_type.nav_proprty(nav_property) # type: ignore
except KeyError:
raise PyODataException('Navigation property {} is not declared in {} entity type'.format(
nav_property, self._entity_type))
Expand Down Expand Up @@ -1283,7 +1283,7 @@ def function_import_handler(fimport: FunctionImport,

# 1. if return types is "entity type", return instance of appropriate entity proxy
if isinstance(fimport.return_type, elements.EntityType):
entity_set = self._service.schema.entity_set(fimport.entity_set_name) # type: ignore
entity_set = self._service.schema.entity_set(fimport.entity_set_name) # type: ignore
return EntityProxy(self._service, entity_set, fimport.return_type, response_data)

# 2. return raw data for all other return types (primitives, complex types encoded in dicts, etc.)
Expand Down
1 change: 1 addition & 0 deletions pyodata/v4/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
build_navigation_type_property, build_navigation_property_binding, build_entity_set_with_v4_builder, build_enum_type
from .type_traits import EdmDateTypTraits, GeoTypeTraits, EdmDoubleQuotesEncapsulatedTypTraits, \
EdmTimeOfDay, EdmDateTimeOffsetTypTraits, EdmDuration
from .service import Service # noqa


class ODataV4(ODATAVersion):
Expand Down
5 changes: 4 additions & 1 deletion pyodata/v4/build_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ def build_schema(config: Config, schema_nodes):
for ref_con in nav_prop.referential_constraints:
try:
proprty = stype.proprty(ref_con.proprty_name)
referenced_proprty = nav_prop.typ.proprty(ref_con.referenced_proprty_name)
if nav_prop.typ.is_collection:
referenced_proprty = nav_prop.typ.item_type.proprty(ref_con.referenced_proprty_name)
else:
referenced_proprty = nav_prop.typ.proprty(ref_con.referenced_proprty_name)
except PyODataModelError as ex:
config.err_policy(ParserError.REFERENTIAL_CONSTRAINT).resolve(ex)
proprty = NullProperty(ref_con.proprty_name)
Expand Down
Loading

0 comments on commit 06320bf

Please sign in to comment.