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_category_fields(self):
n = node.Category()
n.category = node.CategoryValue.TV
CATEGORY = node.CategoryValue.Books
clean_node(n)
n.category = CATEGORY
self.assertTrue(n.dirty)
self.assertEqual(CATEGORY, n.category)
def test_fields(self):
n = node.NodeAnnotations()
CATEGORY = node.CategoryValue.Books
CATEGORY_2 = node.CategoryValue.TV
clean_node(n)
n.category = None
self.assertTrue(n.dirty)
self.assertEqual(None, n.category)
sub = node.Category()
sub.category = CATEGORY
clean_node(sub)
clean_node(n)
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)
def Category():
c = node.Category()
c.category = node.CategoryValue.Books
return c
a, b = generate_save_load(Category)
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 category(self, value):
node = self._get_category_node()
if value is None:
if node is not None:
del self._annotations[node.id]
else:
if node is None:
node = Category()
self._annotations[node.id] = node
node.category = value
self._dirty = True
def __init__(self):
super(Category, self).__init__()
self._category = None
def _get_category_node(self):
for annotation in self._annotations.values():
if isinstance(annotation, Category):
return annotation
return None