Codequality
This commit is contained in:
parent
bb61aa810c
commit
af65179f2d
|
@ -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__
|
||||
|
|
|
@ -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)
|
||||
|
@ -133,7 +135,7 @@ class FavroClient:
|
|||
def _get_cards_request(
|
||||
self,
|
||||
seq_id: SeqId | None = None,
|
||||
todo_list: bool=False,
|
||||
todo_list: bool = False,
|
||||
request_id: None | str = None,
|
||||
page: None | int = None,
|
||||
) -> requests.PreparedRequest:
|
||||
|
@ -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:
|
||||
|
|
|
@ -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,19 +100,22 @@ class TagInfo:
|
|||
json.get('color'),
|
||||
)
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class CustomFieldItem:
|
||||
""" Custom field item object.
|
||||
"""Custom field item object.
|
||||
Fields:
|
||||
- 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.
|
||||
"""Custom field object.
|
||||
|
||||
Fields:
|
||||
- organizationId: The id of the organization that this custom field exists in.
|
||||
|
@ -121,9 +126,10 @@ 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
|
||||
|
||||
organization_id: OrganizationId
|
||||
custom_field_id: CustomFieldId
|
||||
widget_common_id: WidgetCommonId
|
||||
type: str
|
||||
name: str
|
||||
enabled: bool
|
||||
|
@ -203,9 +209,11 @@ 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')),
|
||||
start_date=map_opt(datetime.datetime.fromisoformat,json.get('startDate')),
|
||||
due_date=map_opt(datetime.datetime.fromisoformat,json.get('dueDate')),
|
||||
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']],
|
||||
custom_fields=[
|
||||
CustomField.from_json(field) for field in json['customFields']
|
||||
|
@ -214,6 +222,7 @@ class Card:
|
|||
attachments=json['attachments'], # TODO
|
||||
)
|
||||
|
||||
|
||||
def map_opt(mapper, value):
|
||||
if value is not None:
|
||||
return mapper(value)
|
||||
|
|
|
@ -200,10 +200,10 @@ class FavroFuse(fuse.Fuse):
|
|||
org_id=card.organization_id.raw_id,
|
||||
seq_id=card.seq_id.raw_id,
|
||||
),
|
||||
todo_list_completed = card.todo_list_completed,
|
||||
todo_list_completed=card.todo_list_completed,
|
||||
archived=card.archived,
|
||||
start_date= card.start_date,
|
||||
due_date= card.due_date,
|
||||
start_date=card.start_date,
|
||||
due_date=card.due_date,
|
||||
)
|
||||
return self.formatter.format_card_contents(card_contents)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user