Skip to content

Commit

Permalink
used placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
UnDarkle committed Sep 20, 2018
1 parent f991c40 commit 1f90134
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Setup file for handling packaging and distribution."""
from setuptools import setup, find_packages

__version__ = "4.1.0"
__version__ = "4.2.0"

result_handlers = [
"db = rotest.core.result.handlers.db_handler:DBHandler",
Expand Down
6 changes: 3 additions & 3 deletions src/rotest/management/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from models import ResourceData
from base_resource import BaseResource
from client.manager import ClientResourceManager
from models import ResourceData
from client.manager import ClientResourceManager
from base_resource import BaseResource, DataPointer
18 changes: 11 additions & 7 deletions src/rotest/management/base_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def __call__(cls, *args, **kwargs):
"positional arguments")

resource = type.__call__(cls, *args, **kwargs)
kwargs.pop('data', None)
resource.kwargs = kwargs
for field_name, field_value in kwargs.iteritems():
setattr(resource, field_name, field_value)
Expand All @@ -40,6 +39,12 @@ def __call__(cls, *args, **kwargs):
return resource


class DataPointer(object):
"""Pointer to a field in the resource's data."""
def __init__(self, field_name):
self.field_name = field_name


class BaseResource(object):
"""Represent the common interface of all the resources.
Expand Down Expand Up @@ -113,13 +118,12 @@ class fields, where the 'data' attribute in the declaration points
BaseResource):

sub_class = sub_placeholder.__class__
if sub_class.DATA_CLASS is None:
sub_data = None

else:
sub_data = getattr(self.data, sub_placeholder.data)
actual_kwargs = sub_placeholder.kwargs.copy()
for key, value in sub_placeholder.kwargs.iteritems():
if isinstance(value, DataPointer):
actual_kwargs[key] = getattr(self.data, value.field_name)

sub_resource = sub_class(data=sub_data, **sub_placeholder.kwargs)
sub_resource = sub_class(**actual_kwargs)

setattr(self, sub_name, sub_resource)
sub_resources.append(sub_resource)
Expand Down
6 changes: 3 additions & 3 deletions tests/management/test_resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from django.contrib.auth.models import User
from swaggapi.api.builder.client import requester

from rotest.management import BaseResource
from rotest.management.common.utils import LOCALHOST
from rotest.management import BaseResource, DataPointer
from rotest.management.client.manager import (ClientResourceManager,
ResourceRequest)
from rotest.management.common.resource_descriptor import \
Expand Down Expand Up @@ -1278,8 +1278,8 @@ def test_lock_alter_complex_resource(self):
class AlterDemoComplexResource(BaseResource):
"""Fake complex resource class, used in resource manager tests."""
DATA_CLASS = DemoComplexResourceData
demo1 = DemoResource(data='demo1')
demo2 = DemoResource(data='demo2')
demo1 = DemoResource(data=DataPointer('demo1'))
demo2 = DemoResource(data=DataPointer('demo2'))

def initialize(self):
"""Turns on the initialization flag."""
Expand Down

0 comments on commit 1f90134

Please sign in to comment.