Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def clean_node(n):
n.save()
if isinstance(n, node.Node):
for c in n.children:
c.save()
assert(not n.dirty)
return n
def test_delete(self):
n = TestElement()
n.delete()
self.assertTrue(n.timestamps.dirty)
self.assertTrue(n.timestamps.deleted > node.NodeTimestamps.int_to_dt(0))
def test_trashed(self):
n = TestElement()
self.assertFalse(n.trashed)
n.timestamps.trashed = None
self.assertFalse(n.trashed)
n.timestamps.trashed = node.NodeTimestamps.int_to_dt(0)
self.assertFalse(n.trashed)
n.timestamps.trashed = node.NodeTimestamps.int_to_dt(1)
self.assertTrue(n.trashed)
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.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.ListItem()
TEXT = 'Text'
CHECKED = False
clean_node(n)
n.text = TEXT
self.assertTrue(n.dirty)
self.assertEqual(TEXT, n.text)
clean_node(n)
n.checked = CHECKED
self.assertTrue(n.dirty)
self.assertEqual(CHECKED, n.checked)
def test_save_load(self):
a, b = generate_save_load(lambda: node.Node(type_=node.NodeType.Note))
self.assertEqual(a, b)
a, b = generate_save_load(lambda: node.TopLevelNode(type_=node.NodeType.Note))
self.assertEqual(a, b)
a, b = generate_save_load(node.Note)
self.assertEqual(a, b)
a, b = generate_save_load(node.List)
self.assertEqual(a, b)
a, b = generate_save_load(node.ListItem)
self.assertEqual(a, b)
clean_node(n)
n.text = TEXT
self.assertTrue(n.dirty)
self.assertEqual(TEXT, n.text)
clean_node(n)
n.settings.new_listitem_placement = ITEMPLACEMENT
self.assertTrue(n.dirty)
self.assertEqual(ITEMPLACEMENT, n.settings.new_listitem_placement)
clean_node(n)
n.annotations.category = None
self.assertTrue(n.dirty)
self.assertEqual(None, n.annotations.category)
sub = node.ListItem()
clean_node(sub)
clean_node(n)
n.append(sub)
self.assertTrue(n.dirty)
clean_node(n)
sub.text = TEXT
self.assertTrue(n.dirty)
clean_node(n)
sub.delete()
self.assertTrue(n.dirty)
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)