Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Commit

Permalink
Add support for label_update_orders and renamed label add/register call.
Browse files Browse the repository at this point in the history
  • Loading branch information
lefcha committed Apr 22, 2015
1 parent 4737bbc commit d333542
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def read(fname):

setup(
name='todoist-python',
version='0.2.7',
version='0.2.8',
packages=['todoist', 'todoist.managers'],
author='Doist Team',
author_email='info@todoist.com',
Expand Down
18 changes: 17 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def test_label(api_token):
api = todoist.api.TodoistAPI(api_token)
api.api_endpoint = 'https://local.todoist.com'

label1 = api.labels.register('Label1')
label1 = api.labels.add('Label1')
api.commit()
response = api.labels.sync()
assert response['Labels'][0]['name'] == 'Label1'
Expand All @@ -348,13 +348,29 @@ def test_label(api_token):
assert 'UpdatedLabel1' in [p['name'] for p in api.state['Labels']]
assert api.labels.get_by_id(label1['id']) == label1

label2 = api.labels.add('Label2')
api.commit()
api.labels.sync()

api.labels.update_orders({label1['id']: 1, label2['id']: 2})
api.commit()
response = api.labels.sync()
for label in response['Labels']:
if label['id'] == label1['id']:
assert label['item_order'] == 1
if label['id'] == label2['id']:
assert label['item_order'] == 2

label1.delete()
api.commit()
response = api.labels.sync()
assert response['Labels'][0]['name'] == 'UpdatedLabel1'
assert response['Labels'][0]['is_deleted'] == 1
assert 'UpdatedLabel1' not in [p['name'] for p in api.state['Labels']]

label2.delete()
api.commit()


def test_note(api_token):
cleanup(api_token)
Expand Down
22 changes: 20 additions & 2 deletions todoist/managers/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class LabelsManager(Manager, AllMixin, GetByIdMixin, SyncMixin):
object_type = 'label'
resource_type = 'labels'

def register(self, name, **kwargs):
def add(self, name, **kwargs):
"""
Registers a label in the local state, and appends the equivalent
request to the queue.
Expand All @@ -19,10 +19,28 @@ def register(self, name, **kwargs):
obj.data.update(kwargs)
self.state[self.state_name].append(obj)
item = {
'type': 'label_register',
'type': 'label_add',
'temp_id': obj.temp_id,
'uuid': self.api.generate_uuid(),
'args': obj.data,
}
self.queue.append(item)
return obj

def update_orders(self, id_order_mapping):
"""
Updates in the local state the orders of multiple labels, and appends
the equivalent request to the queue.
"""
for filter_id in id_order_mapping.keys():
obj = self.get_by_id(filter_id)
if obj:
obj['item_order'] = id_order_mapping[filter_id]
item = {
'type': 'label_update_orders',
'uuid': self.api.generate_uuid(),
'args': {
'id_order_mapping': id_order_mapping,
},
}
self.queue.append(item)

0 comments on commit d333542

Please sign in to comment.