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.Node(type_=node.NodeType.Note)
TZ = node.NodeTimestamps.int_to_dt(0)
SORT = 1
TEXT = 'Text'
ITEMPLACEMENT = node.NewListItemPlacementValue.Bottom
clean_node(n)
n.timestamps.created = TZ
self.assertTrue(n.dirty)
self.assertEqual(TZ, n.timestamps.created)
clean_node(n)
n.sort = SORT
self.assertTrue(n.dirty)
self.assertEqual(SORT, n.sort)
clean_node(n)
n.text = TEXT
def test_deleted(self):
n = TestElement()
self.assertFalse(n.deleted)
n.timestamps.deleted = None
self.assertFalse(n.deleted)
n.timestamps.deleted = node.NodeTimestamps.int_to_dt(0)
self.assertFalse(n.deleted)
n.timestamps.deleted = node.NodeTimestamps.int_to_dt(1)
self.assertTrue(n.deleted)
def test_fields(self):
n = node.NodeTimestamps(0)
TZ = node.NodeTimestamps.int_to_dt(0)
clean_node(n)
n.created = TZ
self.assertTrue(n.dirty)
self.assertEqual(TZ, n.created)
clean_node(n)
n.deleted = TZ
self.assertTrue(n.dirty)
self.assertEqual(TZ, n.deleted)
clean_node(n)
n.trashed = TZ
self.assertTrue(n.dirty)
def __init__(self):
super(TestElement, self).__init__()
self.timestamps = node.NodeTimestamps(0)
def __init__(self):
super(Label, self).__init__()
create_time = time.time()
self.id = self._generateId(create_time)
self._name = ''
self.timestamps = NodeTimestamps(create_time)
self._merged = NodeTimestamps.int_to_dt(0)
def __init__(self, id_=None, type_=None, parent_id=None):
super(Node, self).__init__()
create_time = time.time()
self.parent = None
self.id = self._generateId(create_time) if id_ is None else id_
self.server_id = None
self.parent_id = parent_id
self.type = type_
self._sort = random.randint(1000000000, 9999999999)
self._version = None
self._text = ''
self._children = {}
self.timestamps = NodeTimestamps(create_time)
self.settings = NodeSettings()
self.annotations = NodeAnnotations()
# Set if there is no baseVersion in the raw data
self.moved = False
Raises:
APIException: If the server returns an error.
"""
# Handle defaults.
if nodes is None:
nodes = []
if labels is None:
labels = []
current_time = time.time()
# Initialize request parameters.
params = {
'nodes': nodes,
'clientTimestamp': _node.NodeTimestamps.int_to_str(current_time),
'requestHeader': {
'clientSessionId': self._session_id,
'clientPlatform': 'ANDROID',
'clientVersion': {
'major': '9',
'minor': '9',
'build': '9',
'revision': '9'
},
'capabilities': [
{'type': 'NC'}, # Color support (Send note color)
{'type': 'PI'}, # Pinned support (Send note pinned)
{'type': 'LB'}, # Labels support (Send note labels)
{'type': 'AN'}, # Annotations support (Send annotations)
{'type': 'SH'}, # Sharing support
{'type': 'DR'}, # Drawing support
continue
if key not in s_raw:
logger.info('Missing key for %s key %s', type(self), key)
continue
if isinstance(val, (list, dict)):
continue
val_a = raw[key]
val_b = s_raw[key]
# Python strftime's 'z' format specifier includes microseconds, but the response from GKeep
# only has milliseconds. This causes a string mismatch, so we construct datetime objects
# to properly compare
if isinstance(val_a, six.string_types) and isinstance(val_b, six.string_types):
try:
tval_a = NodeTimestamps.str_to_dt(val_a)
tval_b = NodeTimestamps.str_to_dt(val_b)
val_a, val_b = tval_a, tval_b
except (KeyError, ValueError):
pass
if val_a != val_b:
logger.info('Different value for %s key %s: %s != %s', type(self), key, raw[key], s_raw[key])
elif isinstance(raw, list):
if len(raw) != len(s_raw):
logger.info('Different length for %s: %d != %d', type(self), len(raw), len(s_raw))
def save(self, clean=True):
# Parent method not called.
ret = [
{'labelId': label_id, 'deleted': NodeTimestamps.dt_to_str(datetime.datetime.utcnow()) if label is None else NodeTimestamps.int_to_str(0)}
for label_id, label in self._labels.items()]
if not clean:
ret.append(self._dirty)
else:
self._dirty = False
return ret