Skip to content

Commit

Permalink
Linting fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
chsou committed Aug 1, 2024
1 parent 720aa9a commit 5ab0645
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
36 changes: 23 additions & 13 deletions c8y_api/model/tenants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
from typing import Generator, List

from c8y_api._base_api import CumulocityRestApi
from c8y_api.model.applications import Application
from c8y_api.model._base import SimpleObject, CumulocityResource
from c8y_api.model._parser import SimpleObjectParser
from model import Application


class Tenant(SimpleObject):
Expand Down Expand Up @@ -75,8 +75,8 @@ def __init__(self,
self.creation_time = None
self.parent = None
self.status = None
self._applications = None
self._owned_applications = None
self._applications = []
self._owned_applications = []

domain = SimpleObject.UpdatableProperty('_u_domain')
admin_name = SimpleObject.UpdatableProperty('_u_admin_name')
Expand All @@ -102,9 +102,8 @@ def applications(self) -> Generator[Application]:
Returns:
A Generator for Application instances.
"""
if self._applications:
for application_json in self._applications:
yield Application.from_json(application_json)
for application_json in self._applications:
yield Application.from_json(application_json)

@property
def all_applications(self) -> List[Application]:
Expand All @@ -113,7 +112,7 @@ def all_applications(self) -> List[Application]:
Returns:
A list of Application instances.
"""
return [x for x in self.applications]
return list(self.applications)

@property
def owned_applications(self) -> Generator[Application]:
Expand All @@ -122,9 +121,8 @@ def owned_applications(self) -> Generator[Application]:
Returns:
A Generator for Application instances.
"""
if self._owned_applications:
for application_json in self._owned_applications:
yield Application.from_json(application_json)
for application_json in self._owned_applications:
yield Application.from_json(application_json)

@property
def all_owned_applications(self) -> List[Application]:
Expand All @@ -133,7 +131,7 @@ def all_owned_applications(self) -> List[Application]:
Returns:
A list of Application instances.
"""
return [x for x in self.owned_applications]
return list(self.owned_applications)

@classmethod
def from_json(cls, json: dict) -> Tenant:
Expand All @@ -152,6 +150,7 @@ def from_json(cls, json: dict) -> Tenant:
obj = cls._from_json(json, Tenant())
# Extract (but don't parse) referenced application. Parsing is
# done lazily in property implementations
# pylint: disable=protected-access
if 'applications' in json:
obj._applications = [x['application'] for x in json['applications']['references']]
if 'ownedApplications' in json:
Expand Down Expand Up @@ -210,8 +209,19 @@ def get_current(self) -> Tenant:
tenant.c8y = self.c8y
return tenant

def get(self, id: str) -> Tenant:
tenant = Tenant.from_json(self._get_object(id))
def get(self, tenant_id: str) -> Tenant:
"""Read a specific tenant from the database.
Args:
tenant_id (str|int): database ID of a tenant
Returns:
Tenant object
Raises:
KeyError: if the ID cannot be resolved.
"""
tenant = Tenant.from_json(self._get_object(tenant_id))
tenant.c8y = self.c8y # inject c8y connection into instance
return tenant

Expand Down
1 change: 1 addition & 0 deletions tests/model/test_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# and/or its subsidiaries and/or its affiliates and/or their licensors.
# Use, reproduction, transfer, publication or disclosure is prohibited except
# as specifically provided for in your License Agreement with Software AG.

# pylint: disable=protected-access

import json
Expand Down
5 changes: 4 additions & 1 deletion tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Use, reproduction, transfer, publication or disclosure is prohibited except
# as specifically provided for in your License Agreement with Software AG.

# pylint: disable=protected-access

from __future__ import annotations

import os
Expand All @@ -16,6 +18,7 @@
from c8y_api._jwt import JWT
from model._util import _StringUtil


@pytest.mark.parametrize(
'name, expected',
[
Expand All @@ -25,10 +28,10 @@
('_leading_underscore', 'leadingUnderscore'),
])
def test_snake_to_pascal_case(name, expected):
"""Verify that snake case conversion works as expected."""
assert _StringUtil.to_pascal_case(name) == expected



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

0 comments on commit 5ab0645

Please sign in to comment.