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.
|
- [ ] Get the correct last-modified date.
|
||||||
- [ ] Improve cache behaviour. User and tags can have much longer cache times.
|
- [ ] 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:
|
while page < num_pages:
|
||||||
# Determine params for get_cards
|
# 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
|
# Run query
|
||||||
logger.warning('Sending request: %s', request.url)
|
logger.warning('Sending request: %s', request.url)
|
||||||
|
@ -133,7 +135,7 @@ class FavroClient:
|
||||||
def _get_cards_request(
|
def _get_cards_request(
|
||||||
self,
|
self,
|
||||||
seq_id: SeqId | None = None,
|
seq_id: SeqId | None = None,
|
||||||
todo_list: bool=False,
|
todo_list: bool = False,
|
||||||
request_id: None | str = None,
|
request_id: None | str = None,
|
||||||
page: None | int = None,
|
page: None | int = None,
|
||||||
) -> requests.PreparedRequest:
|
) -> requests.PreparedRequest:
|
||||||
|
@ -168,7 +170,9 @@ class FavroClient:
|
||||||
return TagInfo.from_json(response.json())
|
return TagInfo.from_json(response.json())
|
||||||
|
|
||||||
def get_custom_field(self, tag_id: CustomFieldId) -> CustomFieldInfo:
|
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())
|
return CustomFieldInfo.from_json(response.json())
|
||||||
|
|
||||||
def _invalidate_cache(self, card_id: CardId) -> None:
|
def _invalidate_cache(self, card_id: CardId) -> None:
|
||||||
|
|
|
@ -33,14 +33,17 @@ class UserId:
|
||||||
class OrganizationId:
|
class OrganizationId:
|
||||||
raw_id: str
|
raw_id: str
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class CustomFieldId:
|
class CustomFieldId:
|
||||||
raw_id: str
|
raw_id: str
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class WidgetCommonId:
|
class WidgetCommonId:
|
||||||
raw_id: str
|
raw_id: str
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class CustomFieldItemId:
|
class CustomFieldItemId:
|
||||||
raw_id: str
|
raw_id: str
|
||||||
|
@ -81,7 +84,6 @@ class TagId:
|
||||||
raw_id: str
|
raw_id: str
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class TagInfo:
|
class TagInfo:
|
||||||
tag_id: TagId
|
tag_id: TagId
|
||||||
|
@ -98,19 +100,22 @@ class TagInfo:
|
||||||
json.get('color'),
|
json.get('color'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class CustomFieldItem:
|
class CustomFieldItem:
|
||||||
""" Custom field item object.
|
"""Custom field item object.
|
||||||
Fields:
|
Fields:
|
||||||
- customFieldItemId: The id of the custom field item.
|
- customFieldItemId: The id of the custom field item.
|
||||||
- name: The name of the custom field item.
|
- name: The name of the custom field item.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
custom_field_item_id: CustomFieldItemId
|
custom_field_item_id: CustomFieldItemId
|
||||||
name: str
|
name: str
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class CustomFieldInfo:
|
class CustomFieldInfo:
|
||||||
""" Custom field object.
|
"""Custom field object.
|
||||||
|
|
||||||
Fields:
|
Fields:
|
||||||
- organizationId: The id of the organization that this custom field exists in.
|
- 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.
|
- 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.
|
- 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
|
organization_id: OrganizationId
|
||||||
widget_common_id : WidgetCommonId
|
custom_field_id: CustomFieldId
|
||||||
|
widget_common_id: WidgetCommonId
|
||||||
type: str
|
type: str
|
||||||
name: str
|
name: str
|
||||||
enabled: bool
|
enabled: bool
|
||||||
|
@ -203,9 +209,11 @@ class Card:
|
||||||
],
|
],
|
||||||
tags=[TagId(tag) for tag in json['tags']],
|
tags=[TagId(tag) for tag in json['tags']],
|
||||||
creator_user_id=UserId(json['createdByUserId']),
|
creator_user_id=UserId(json['createdByUserId']),
|
||||||
creation_date=map_opt(datetime.datetime.fromisoformat,json.get('createdAt')),
|
creation_date=map_opt(
|
||||||
start_date=map_opt(datetime.datetime.fromisoformat,json.get('startDate')),
|
datetime.datetime.fromisoformat, json.get('createdAt')
|
||||||
due_date=map_opt(datetime.datetime.fromisoformat,json.get('dueDate')),
|
),
|
||||||
|
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']],
|
assignments=[CardAssignment.from_json(ass) for ass in json['assignments']],
|
||||||
custom_fields=[
|
custom_fields=[
|
||||||
CustomField.from_json(field) for field in json['customFields']
|
CustomField.from_json(field) for field in json['customFields']
|
||||||
|
@ -214,6 +222,7 @@ class Card:
|
||||||
attachments=json['attachments'], # TODO
|
attachments=json['attachments'], # TODO
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def map_opt(mapper, value):
|
def map_opt(mapper, value):
|
||||||
if value is not None:
|
if value is not None:
|
||||||
return mapper(value)
|
return mapper(value)
|
||||||
|
|
|
@ -200,10 +200,10 @@ class FavroFuse(fuse.Fuse):
|
||||||
org_id=card.organization_id.raw_id,
|
org_id=card.organization_id.raw_id,
|
||||||
seq_id=card.seq_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,
|
archived=card.archived,
|
||||||
start_date= card.start_date,
|
start_date=card.start_date,
|
||||||
due_date= card.due_date,
|
due_date=card.due_date,
|
||||||
)
|
)
|
||||||
return self.formatter.format_card_contents(card_contents)
|
return self.formatter.format_card_contents(card_contents)
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ FM_KEY_START_DATE = 'start-date'
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class CardContents:
|
class CardContents:
|
||||||
identifier: str | None
|
identifier: str | None
|
||||||
|
@ -111,8 +112,9 @@ class CardFileFormatter:
|
||||||
# Card contents
|
# Card contents
|
||||||
if description := card.description:
|
if description := card.description:
|
||||||
if self.obsidian_mode:
|
if self.obsidian_mode:
|
||||||
description = re.sub(r'\-\s*\[\s*\]', '- [ ]', description,
|
description = re.sub(
|
||||||
flags=re.MULTILINE)
|
r'\-\s*\[\s*\]', '- [ ]', description, flags=re.MULTILINE
|
||||||
|
)
|
||||||
ls.append(description)
|
ls.append(description)
|
||||||
del description
|
del description
|
||||||
fm = frontmatter.Post(''.join(ls), **frontmatter_data)
|
fm = frontmatter.Post(''.join(ls), **frontmatter_data)
|
||||||
|
|
|
@ -28,12 +28,14 @@ def test_get_card():
|
||||||
assert len(card.attachments) == 0
|
assert len(card.attachments) == 0
|
||||||
assert len(card.custom_fields) == 2
|
assert len(card.custom_fields) == 2
|
||||||
|
|
||||||
|
|
||||||
@needs_secrets
|
@needs_secrets
|
||||||
def test_get_cards():
|
def test_get_cards():
|
||||||
client = create_client()
|
client = create_client()
|
||||||
for card in client.get_cards(todo_list=True):
|
for card in client.get_cards(todo_list=True):
|
||||||
assert_valid_card(card)
|
assert_valid_card(card)
|
||||||
|
|
||||||
|
|
||||||
def create_client():
|
def create_client():
|
||||||
return FavroClient(
|
return FavroClient(
|
||||||
favro_org_id=OrganizationId(secrets.favro_org_id()),
|
favro_org_id=OrganizationId(secrets.favro_org_id()),
|
||||||
|
@ -42,6 +44,7 @@ def create_client():
|
||||||
read_only=True,
|
read_only=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def assert_valid_card(card):
|
def assert_valid_card(card):
|
||||||
assert card is not None
|
assert card is not None
|
||||||
assert card.name is not None
|
assert card.name is not None
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
def test_import():
|
def test_import():
|
||||||
import favro_sync.favro_data_model # noqa
|
import favro_sync
|
||||||
import favro_sync.favro_client # noqa
|
import favro_sync.favro_client
|
||||||
import favro_sync.favro_fuse # noqa
|
import favro_sync.favro_data_model
|
||||||
import favro_sync.favro_markdown # noqa
|
import favro_sync.favro_fuse
|
||||||
import favro_sync # noqa
|
import favro_sync.favro_markdown # noqa:F401
|
||||||
|
|
Loading…
Reference in New Issue
Block a user