def test_it_should_extract_fields_from_child_nodes(self): parent = self.__add_node(self.root, 'This is the front', {'anki:field' : 'Front'}) child = self.__add_node(parent, 'This is the back', {'anki:field' : 'Back'}) fp_node = Node(self.root, parent) fields = fp_node.get_fields() self.assertEquals('This is the back', fields['Back'])
def test_it_should_extract_fields_from_nested_child_nodes(self): parent = self.__add_node(self.root, 'This is the front', {'anki:field' : 'Front'}) middle = self.__add_node(parent, 'This does not define a field, but it has a child that does') child = self.__add_node(middle, 'This is the back', {'anki:field' : 'Back'}) fp_node = Node(self.root, parent) fields = fp_node.get_fields() self.assertEquals('This is the back', fields['Back'])
def test_it_should_extract_the_field_from_the_anki_field_attribute(self): text = 'This is the node text' node = self.__add_node(self.root, text, {'anki:field' : 'Name'}) fp_node = Node(self.root, node) fields = fp_node.get_fields() self.assertTrue(fields.has_key('Name'), "Expected field list to contain a 'Name' key") self.assertEquals(text, fields['Name'])
def test_it_should_replace_the_wildcard_character_with_the_node_text(self): node = self.__add_node(self.root, {'anki:field:Foo': 'Bar * Baz'}, 'Foo') fp_node = Node(self.root, node) fields = fp_node.get_fields() self.assertTrue('Foo' in fields, "Expected field list to contain a 'Foo' key") self.assertEqual('Bar Foo Baz', fields['Foo'])
def test_it_should_extract_fields_from_the_anki_field_wildcard_attribute( self): node = self.__add_node(self.root, {'anki:field:Bar': 'Baz'}) fp_node = Node(self.root, node) fields = fp_node.get_fields() self.assertTrue('Bar' in fields, "Expected field list to contain a 'Bar' key") self.assertEqual('Baz', fields['Bar'])
def test_it_should_not_extract_fields_from_sub_notes(self): parent = self.__add_node(self.root) sub_note = self.__add_node(parent, {'anki:model': 'Basic'}) self.__add_node(sub_note, {'anki:field:SubNote': 'This should be ignored'}) fp_node = Node(self.root, parent) fields = fp_node.get_fields() self.assertFalse('SubNote' in fields)
def test_it_should_not_extract_fields_from_sub_notes(self): parent = self.__add_node(self.root, 'This is the parent node') sub_note = self.__add_node(parent, 'This is another note', {'anki:model' : 'Basic'}) sub_note_field = self.__add_node(sub_note, 'This is a field in the sub note which should be ignored', {'anki:field' : 'SubNote'}) fp_node = Node(self.root, parent) fields = fp_node.get_fields() self.assertFalse(fields.has_key('SubNote'))
def test_it_should_extract_fields_from_nested_child_nodes(self): parent = self.__add_node(self.root, {'anki:field:Front': 'This is the front'}) middle = self.__add_node(parent) self.__add_node(middle, {'anki:field:Back': 'This is the back'}) fp_node = Node(self.root, parent) fields = fp_node.get_fields() self.assertEqual('This is the back', fields['Back'])