Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_fields(self):
n = node.TopLevelNode(type_=node.NodeType.Note)
collab = "user@google.com"
clean_node(n)
n.collaborators.add(collab)
self.assertTrue(n.dirty)
clean_node(n)
n.collaborators.remove(collab)
self.assertTrue(n.dirty)
a, b = generate_save_load(lambda: node.TopLevelNode(type_=node.NodeType.Note))
self.assertEqual(a, b)
def test_fields(self):
n = node.TopLevelNode(type_=node.NodeType.Note)
COLOR = node.ColorValue.White
ARCHIVED = True
PINNED = True
TITLE = 'Title'
LABEL = 'x'
clean_node(n)
n.color = COLOR
self.assertTrue(n.dirty)
self.assertEqual(COLOR, n.color)
clean_node(n)
n.archived = ARCHIVED
self.assertTrue(n.dirty)
self.assertEqual(ARCHIVED, n.archived)
return self._text
return node.text
@text.setter
def text(self, value):
node = self._get_text_node()
if node is None:
node = ListItem(parent_id=self.id)
self.append(node, True)
node.text = value
self.touch(True)
def __str__(self):
return '\n'.join([self.title, self.text])
class List(TopLevelNode):
"""Represents a Google Keep list."""
_TYPE = NodeType.List
SORT_DELTA = 10000 # Arbitrary constant
def __init__(self, **kwargs):
super(List, self).__init__(type_=self._TYPE, **kwargs)
def add(self, text, checked=False, sort=None):
"""Add a new item to the list.
Args:
text (str): The text.
checked (bool): Whether this item is checked.
sort (Union[gkeepapi.node.NewListItemPlacementValue, int]): Item id for sorting or a placement policy.
"""
node = ListItem(parent_id=self.id, parent_server_id=self.server_id)
node.checked = checked
return 'https://keep.google.com/u/0/#' + self._TYPE.value + '/' + self.id
@property
def dirty(self):
return super(TopLevelNode, self).dirty or self.labels.dirty or self.collaborators.dirty
@property
def blobs(self):
"""Get all media blobs.
Returns:
list[gkeepapi.node.Blob]: Media blobs.
"""
return [node for node in self.children if isinstance(node, Blob)]
class Note(TopLevelNode):
"""Represents a Google Keep note."""
_TYPE = NodeType.Note
def __init__(self, **kwargs):
super(Note, self).__init__(type_=self._TYPE, **kwargs)
def _get_text_node(self):
node = None
for child_node in self.children:
if isinstance(child_node, ListItem):
node = child_node
break
return node
@property
def text(self):
def save(self, clean=True):
ret = super(TopLevelNode, self).save(clean)
ret['color'] = self._color.value
ret['isArchived'] = self._archived
ret['isPinned'] = self._pinned
ret['title'] = self._title
labels = self.labels.save(clean)
collaborators, requests = self.collaborators.save(clean)
if labels:
ret['labelIds'] = labels
ret['collaborators'] = collaborators
if requests:
ret['shareRequests'] = requests
return ret