1
0

Codequality

This commit is contained in:
Jon Michael Aanes 2024-10-01 16:14:51 +02:00
parent bb61aa810c
commit af65179f2d
7 changed files with 44 additions and 23 deletions

View File

@ -63,3 +63,6 @@ Following features are work in progress:
- [ ] Get the correct last-modified date.
- [ ] Improve cache behaviour. User and tags can have much longer cache times.
"""
__all__ = ['__version__']
from _version import __version__

View File

@ -111,7 +111,9 @@ class FavroClient:
while page < num_pages:
# Determine params for get_cards
request = self._get_cards_request(seq_id, todo_list, page=page, request_id=request_id)
request = self._get_cards_request(
seq_id, todo_list, page=page, request_id=request_id
)
# Run query
logger.warning('Sending request: %s', request.url)
@ -168,7 +170,9 @@ class FavroClient:
return TagInfo.from_json(response.json())
def get_custom_field(self, tag_id: CustomFieldId) -> CustomFieldInfo:
response = self.session.get(URL_GET_CUSTOM_FIELD.format(custom_field_id=custom_field_id.raw_id))
response = self.session.get(
URL_GET_CUSTOM_FIELD.format(custom_field_id=custom_field_id.raw_id)
)
return CustomFieldInfo.from_json(response.json())
def _invalidate_cache(self, card_id: CardId) -> None:

View File

@ -33,14 +33,17 @@ class UserId:
class OrganizationId:
raw_id: str
@dataclasses.dataclass(frozen=True)
class CustomFieldId:
raw_id: str
@dataclasses.dataclass(frozen=True)
class WidgetCommonId:
raw_id: str
@dataclasses.dataclass(frozen=True)
class CustomFieldItemId:
raw_id: str
@ -81,7 +84,6 @@ class TagId:
raw_id: str
@dataclasses.dataclass(frozen=True)
class TagInfo:
tag_id: TagId
@ -98,6 +100,7 @@ class TagInfo:
json.get('color'),
)
@dataclasses.dataclass(frozen=True)
class CustomFieldItem:
"""Custom field item object.
@ -105,9 +108,11 @@ class CustomFieldItem:
- customFieldItemId: The id of the custom field item.
- name: The name of the custom field item.
"""
custom_field_item_id: CustomFieldItemId
name: str
@dataclasses.dataclass(frozen=True)
class CustomFieldInfo:
"""Custom field object.
@ -121,6 +126,7 @@ class CustomFieldInfo:
- enabled: True if the custom field is currently enabled for the organization.
- customFieldItems: The list of items that this custom field can have in case it is a selectable one.
"""
organization_id: OrganizationId
custom_field_id: CustomFieldId
widget_common_id: WidgetCommonId
@ -203,7 +209,9 @@ class Card:
],
tags=[TagId(tag) for tag in json['tags']],
creator_user_id=UserId(json['createdByUserId']),
creation_date=map_opt(datetime.datetime.fromisoformat,json.get('createdAt')),
creation_date=map_opt(
datetime.datetime.fromisoformat, json.get('createdAt')
),
start_date=map_opt(datetime.datetime.fromisoformat, json.get('startDate')),
due_date=map_opt(datetime.datetime.fromisoformat, json.get('dueDate')),
assignments=[CardAssignment.from_json(ass) for ass in json['assignments']],
@ -214,6 +222,7 @@ class Card:
attachments=json['attachments'], # TODO
)
def map_opt(mapper, value):
if value is not None:
return mapper(value)

View File

@ -21,6 +21,7 @@ FM_KEY_START_DATE = 'start-date'
################################################################################
@dataclasses.dataclass(frozen=True)
class CardContents:
identifier: str | None
@ -111,8 +112,9 @@ class CardFileFormatter:
# Card contents
if description := card.description:
if self.obsidian_mode:
description = re.sub(r'\-\s*\[\s*\]', '- [ ]', description,
flags=re.MULTILINE)
description = re.sub(
r'\-\s*\[\s*\]', '- [ ]', description, flags=re.MULTILINE
)
ls.append(description)
del description
fm = frontmatter.Post(''.join(ls), **frontmatter_data)

View File

@ -28,12 +28,14 @@ def test_get_card():
assert len(card.attachments) == 0
assert len(card.custom_fields) == 2
@needs_secrets
def test_get_cards():
client = create_client()
for card in client.get_cards(todo_list=True):
assert_valid_card(card)
def create_client():
return FavroClient(
favro_org_id=OrganizationId(secrets.favro_org_id()),
@ -42,6 +44,7 @@ def create_client():
read_only=True,
)
def assert_valid_card(card):
assert card is not None
assert card.name is not None

View File

@ -1,6 +1,6 @@
def test_import():
import favro_sync.favro_data_model # noqa
import favro_sync.favro_client # noqa
import favro_sync.favro_fuse # noqa
import favro_sync.favro_markdown # noqa
import favro_sync # noqa
import favro_sync
import favro_sync.favro_client
import favro_sync.favro_data_model
import favro_sync.favro_fuse
import favro_sync.favro_markdown # noqa:F401