Skip to content

Commit 5ab0645

Browse files
committed
Linting fixes.
1 parent 720aa9a commit 5ab0645

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

c8y_api/model/tenants.py

+23-13
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from typing import Generator, List
1111

1212
from c8y_api._base_api import CumulocityRestApi
13+
from c8y_api.model.applications import Application
1314
from c8y_api.model._base import SimpleObject, CumulocityResource
1415
from c8y_api.model._parser import SimpleObjectParser
15-
from model import Application
1616

1717

1818
class Tenant(SimpleObject):
@@ -75,8 +75,8 @@ def __init__(self,
7575
self.creation_time = None
7676
self.parent = None
7777
self.status = None
78-
self._applications = None
79-
self._owned_applications = None
78+
self._applications = []
79+
self._owned_applications = []
8080

8181
domain = SimpleObject.UpdatableProperty('_u_domain')
8282
admin_name = SimpleObject.UpdatableProperty('_u_admin_name')
@@ -102,9 +102,8 @@ def applications(self) -> Generator[Application]:
102102
Returns:
103103
A Generator for Application instances.
104104
"""
105-
if self._applications:
106-
for application_json in self._applications:
107-
yield Application.from_json(application_json)
105+
for application_json in self._applications:
106+
yield Application.from_json(application_json)
108107

109108
@property
110109
def all_applications(self) -> List[Application]:
@@ -113,7 +112,7 @@ def all_applications(self) -> List[Application]:
113112
Returns:
114113
A list of Application instances.
115114
"""
116-
return [x for x in self.applications]
115+
return list(self.applications)
117116

118117
@property
119118
def owned_applications(self) -> Generator[Application]:
@@ -122,9 +121,8 @@ def owned_applications(self) -> Generator[Application]:
122121
Returns:
123122
A Generator for Application instances.
124123
"""
125-
if self._owned_applications:
126-
for application_json in self._owned_applications:
127-
yield Application.from_json(application_json)
124+
for application_json in self._owned_applications:
125+
yield Application.from_json(application_json)
128126

129127
@property
130128
def all_owned_applications(self) -> List[Application]:
@@ -133,7 +131,7 @@ def all_owned_applications(self) -> List[Application]:
133131
Returns:
134132
A list of Application instances.
135133
"""
136-
return [x for x in self.owned_applications]
134+
return list(self.owned_applications)
137135

138136
@classmethod
139137
def from_json(cls, json: dict) -> Tenant:
@@ -152,6 +150,7 @@ def from_json(cls, json: dict) -> Tenant:
152150
obj = cls._from_json(json, Tenant())
153151
# Extract (but don't parse) referenced application. Parsing is
154152
# done lazily in property implementations
153+
# pylint: disable=protected-access
155154
if 'applications' in json:
156155
obj._applications = [x['application'] for x in json['applications']['references']]
157156
if 'ownedApplications' in json:
@@ -210,8 +209,19 @@ def get_current(self) -> Tenant:
210209
tenant.c8y = self.c8y
211210
return tenant
212211

213-
def get(self, id: str) -> Tenant:
214-
tenant = Tenant.from_json(self._get_object(id))
212+
def get(self, tenant_id: str) -> Tenant:
213+
"""Read a specific tenant from the database.
214+
215+
Args:
216+
tenant_id (str|int): database ID of a tenant
217+
218+
Returns:
219+
Tenant object
220+
221+
Raises:
222+
KeyError: if the ID cannot be resolved.
223+
"""
224+
tenant = Tenant.from_json(self._get_object(tenant_id))
215225
tenant.c8y = self.c8y # inject c8y connection into instance
216226
return tenant
217227

tests/model/test_audit.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# and/or its subsidiaries and/or its affiliates and/or their licensors.
44
# Use, reproduction, transfer, publication or disclosure is prohibited except
55
# as specifically provided for in your License Agreement with Software AG.
6+
67
# pylint: disable=protected-access
78

89
import json

tests/test_util.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# Use, reproduction, transfer, publication or disclosure is prohibited except
55
# as specifically provided for in your License Agreement with Software AG.
66

7+
# pylint: disable=protected-access
8+
79
from __future__ import annotations
810

911
import os
@@ -16,6 +18,7 @@
1618
from c8y_api._jwt import JWT
1719
from model._util import _StringUtil
1820

21+
1922
@pytest.mark.parametrize(
2023
'name, expected',
2124
[
@@ -25,10 +28,10 @@
2528
('_leading_underscore', 'leadingUnderscore'),
2629
])
2730
def test_snake_to_pascal_case(name, expected):
31+
"""Verify that snake case conversion works as expected."""
2832
assert _StringUtil.to_pascal_case(name) == expected
2933

3034

31-
3235
@patch.dict(os.environ, {'C8Y_SOME': 'some', 'C8Y_THING': 'thing', 'C8YNOT': 'not'}, clear=True)
3336
def test_c8y_keys():
3437
"""Verify that the C8Y_* keys can be filtered from environment."""

0 commit comments

Comments
 (0)