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_weblink_fields(self):
n = node.WebLink()
TITLE = 'Title'
URL = 'https://url.url'
IMAGEURL = 'https://img.url'
PROVENANCEURL = 'https://provenance.url'
DESCRIPTION = 'Description'
clean_node(n)
n.title = TITLE
self.assertTrue(n.dirty)
self.assertEqual(TITLE, n.title)
clean_node(n)
n.url = URL
self.assertTrue(n.dirty)
self.assertEqual(URL, n.url)
n.append(sub)
self.assertTrue(n.dirty)
self.assertEqual(CATEGORY, n.category)
clean_node(n)
sub.category = CATEGORY_2
self.assertTrue(n.dirty)
self.assertEqual(CATEGORY_2, n.category)
clean_node(n)
n.remove(sub)
self.assertTrue(n.dirty)
self.assertEqual([], n.links)
sub = node.WebLink()
clean_node(sub)
clean_node(n)
n.append(sub)
self.assertTrue(n.dirty)
self.assertEqual([sub], n.links)
def test_save_load(self):
a, b = generate_save_load(node.Annotation)
self.assertEqual(a, b)
# Test WebLink
a, b = generate_save_load(node.WebLink)
self.assertEqual(a, b)
# Test Category
def Category():
c = node.Category()
c.category = node.CategoryValue.Books
return c
a, b = generate_save_load(Category)
self.assertEqual(a, b)
def test_subannotations(self):
n = node.Context()
sub = node.WebLink()
sub.id = None
n._entries['x'] = sub
data = n.save()
n.load(data)
self.assertEqual(1, len(n._entries))
def from_json(cls, raw):
"""Helper to construct an annotation from a dict.
Args:
raw (dict): Raw annotation representation.
Returns:
Node: An Annotation object or None.
"""
bcls = None
if 'webLink' in raw:
bcls = WebLink
elif 'topicCategory' in raw:
bcls = Category
elif 'taskAssist' in raw:
bcls = TaskAssist
elif 'context' in raw:
bcls = Context
if bcls is None:
logger.warning('Unknown annotation type: %s', raw.keys())
return None
annotation = bcls()
annotation.load(raw)
return annotation
def links(self):
"""Get all links.
Returns:
list[gkeepapi.node.WebLink]: A list of links.
"""
return [annotation for annotation in self._annotations.values()
if isinstance(annotation, WebLink)
]
def save(self, clean=True):
ret = super(WebLink, self).save(clean)
ret['webLink'] = {
'title': self._title,
'url': self._url,
'imageUrl': self._image_url,
'provenanceUrl': self._provenance_url,
'description': self._description,
}
return ret