From 14c75b42ec535886cafe5ab8b9a3b54058e073e6 Mon Sep 17 00:00:00 2001 From: Subhash Bhushan Date: Wed, 27 Feb 2019 18:30:41 -0800 Subject: [PATCH] Address tox issues before releasing 0.0.8 --- src/protean/core/entity.py | 7 +++++-- src/protean/core/field/__init__.py | 3 ++- src/protean/core/field/association.py | 12 +++++++----- src/protean/core/field/base.py | 4 ++-- tests/core/test_entity.py | 26 +++++++++++++++++++------- tests/support/dog.py | 6 +++++- tests/support/human.py | 2 +- 7 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/protean/core/entity.py b/src/protean/core/entity.py index 4e443bfb..e961e234 100644 --- a/src/protean/core/entity.py +++ b/src/protean/core/entity.py @@ -1,12 +1,15 @@ """Entity Functionality and Classes""" import copy import logging -from typing import Any, Union +from typing import Any +from typing import Union from protean.core.exceptions import ObjectNotFoundError from protean.core.exceptions import ValidationError from protean.core.field import Auto -from protean.core.field import Field, Reference, ReferenceField +from protean.core.field import Field +from protean.core.field import Reference +from protean.core.field import ReferenceField from protean.utils.generic import classproperty from protean.utils.query import Q diff --git a/src/protean/core/field/__init__.py b/src/protean/core/field/__init__.py index f5839f53..5fa4b23d 100644 --- a/src/protean/core/field/__init__.py +++ b/src/protean/core/field/__init__.py @@ -1,6 +1,7 @@ """Package for defining Field type and its implementations""" -from .association import Reference, ReferenceField +from .association import Reference +from .association import ReferenceField from .base import Field from .basic import Auto from .basic import Boolean diff --git a/src/protean/core/field/association.py b/src/protean/core/field/association.py index ac7939e9..0b0f3f29 100644 --- a/src/protean/core/field/association.py +++ b/src/protean/core/field/association.py @@ -1,10 +1,11 @@ from abc import abstractmethod -from .base import Field -from .mixins import FieldCacheMixin, FieldDescriptorMixin - -from protean.core import exceptions from protean import utils +from protean.core import exceptions + +from .base import Field +from .mixins import FieldCacheMixin +from .mixins import FieldDescriptorMixin class ReferenceField(Field): @@ -24,6 +25,7 @@ def __set__(self, instance, value): if value: instance.__dict__[self.field_name] = value else: + # Important to handle None assignment, and interpret it to mean resetting values self._reset_values(instance) def __delete__(self, instance): @@ -286,4 +288,4 @@ class HasMany(Association): def _fetch_objects(self, key, value): """Fetch Multiple linked objects""" - return self.to_cls.query.filter(**{key: value}) \ No newline at end of file + return self.to_cls.query.filter(**{key: value}) diff --git a/src/protean/core/field/base.py b/src/protean/core/field/base.py index 750e94a6..e96aa2fa 100644 --- a/src/protean/core/field/base.py +++ b/src/protean/core/field/base.py @@ -6,10 +6,10 @@ from typing import Any from typing import Iterable -from .mixins import FieldDescriptorMixin - from protean.core import exceptions +from .mixins import FieldDescriptorMixin + MISSING_ERROR_MESSAGE = ( 'ValidationError raised by `{class_name}`, but error key `{key}` does ' 'not exist in the `error_messages` dictionary.' diff --git a/tests/core/test_entity.py b/tests/core/test_entity.py index a303332e..48fe852a 100644 --- a/tests/core/test_entity.py +++ b/tests/core/test_entity.py @@ -4,15 +4,27 @@ import mock import pytest -from tests.support.dog import (Dog, RelatedDog, RelatedDog2, DogRelatedByEmail, - HasOneDog1, HasOneDog2, HasOneDog3, - HasManyDog1, HasManyDog2, HasManyDog3) -from tests.support.human import (Human, HasOneHuman1, HasOneHuman2, HasOneHuman3, - HasManyHuman1, HasManyHuman2, HasManyHuman3) - +from tests.support.dog import Dog +from tests.support.dog import DogRelatedByEmail +from tests.support.dog import HasManyDog1 +from tests.support.dog import HasManyDog2 +from tests.support.dog import HasManyDog3 +from tests.support.dog import HasOneDog1 +from tests.support.dog import HasOneDog2 +from tests.support.dog import HasOneDog3 +from tests.support.dog import RelatedDog +from tests.support.dog import RelatedDog2 +from tests.support.human import HasManyHuman1 +from tests.support.human import HasManyHuman2 +from tests.support.human import HasManyHuman3 +from tests.support.human import HasOneHuman1 +from tests.support.human import HasOneHuman2 +from tests.support.human import HasOneHuman3 +from tests.support.human import Human from protean.core import field -from protean.core.entity import Entity, QuerySet +from protean.core.entity import Entity +from protean.core.entity import QuerySet from protean.core.exceptions import ObjectNotFoundError from protean.core.exceptions import ValidationError from protean.utils.query import Q diff --git a/tests/support/dog.py b/tests/support/dog.py index 51373b81..2e7f3ad1 100644 --- a/tests/support/dog.py +++ b/tests/support/dog.py @@ -1,6 +1,10 @@ """Support Classes for Test Cases""" -from tests.support.human import Human, HasOneHuman1, HasOneHuman2, HasManyHuman1, HasManyHuman2 +from tests.support.human import HasManyHuman1 +from tests.support.human import HasManyHuman2 +from tests.support.human import HasOneHuman1 +from tests.support.human import HasOneHuman2 +from tests.support.human import Human from protean.core import field from protean.core.entity import Entity diff --git a/tests/support/human.py b/tests/support/human.py index 4fac0481..992928af 100644 --- a/tests/support/human.py +++ b/tests/support/human.py @@ -1,8 +1,8 @@ """Human Support Class for Test Cases""" from protean.core import field -from protean.core.field import association from protean.core.entity import Entity +from protean.core.field import association from protean.impl.repository.dict_repo import DictModel