Ejemplo n.º 1
0
 def test_validate_and_adapt_item(self):
     bce = BaseContainerExtractor(basic_extractors, template)
     data = {'price': ['10']}
     self.assertEqual(bce._validate_and_adapt_item(data, template), {})
     data['_type'] = 'skip_checks'
     result = bce._validate_and_adapt_item(data, template).dump()
     self.assertEqual(result, {'price': ['10'], '_type': 'skip_checks'})
     data = {
         'price': ['10'],
         u'description': [u'It can do everything except make calls'],
         u'name': ['Smartphone 6']
     }
     result = data.copy()
     result['_type'] = 'default'
     extracted = bce._validate_and_adapt_item(data, template).dump()
     self.assertEqual(extracted, result)
     bce.extra_requires = ['pid']
     self.assertEqual(bce._validate_and_adapt_item(data, template), {})
     data['pid'] = ['13532']
     result = data.copy()
     result['_type'] = 'default'
     extracted = bce._validate_and_adapt_item(data, template).dump()
     self.assertEqual(extracted, result)
     bce.extra_requires = ['pid', '_sticky1']
     data['_sticky1'] = True
     extracted = bce._validate_and_adapt_item(data, template).dump()
     self.assertEqual(extracted, result)
 def test_get_container_info(self):
     containers, annotations, remaining_annotations = \
         BaseContainerExtractor._get_container_data(basic_extractors)
     self.assertEqual(remaining_annotations, [uncontained_annotation])
     self.assertEqual(containers, {'root': root_container,
                                   'child': child_container})
     self.assertEqual(annotations, {'child': child_annotations,
                                    'root': [child_container]})
 def test_get_container_info(self):
     containers, annotations, remaining_annotations = \
         BaseContainerExtractor._get_container_data(basic_extractors)
     self.assertEqual(remaining_annotations, [uncontained_annotation])
     self.assertEqual(containers, {'root': root_container,
                                   'child': child_container})
     self.assertEqual(annotations, {'child': child_annotations,
                                    'root': [child_container]})
 def test_validate_and_adapt_item(self):
     bce = BaseContainerExtractor(basic_extractors, template)
     data = {'price': ['10']}
     data['_type'] = 'skip_checks'
     result = bce._validate_and_adapt_item(data, template).dump()
     self.assertEqual(result,
                      {'price': ['10'], '_type': 'skip_checks'})
     data = {
         'price': ['10'],
         u'description': [u'It can do everything except make calls'],
         u'name': ['Smartphone 6']
     }
     result = data.copy()
     result['_type'] = 'default'
     extracted = bce._validate_and_adapt_item(data, template).dump()
     self.assertEqual(extracted,
                      result)
     data['pid'] = ['13532']
     result = data.copy()
     result['_type'] = 'default'
     extracted = bce._validate_and_adapt_item(data, template).dump()
     self.assertEqual(extracted, result)
     bce.extra_requires = ['pid', '_sticky1']
     data['_sticky1'] = True
     extracted = bce._validate_and_adapt_item(data, template).dump()
     self.assertEqual(extracted, result)
 def test_find_annotation(self):
     bce = BaseContainerExtractor(basic_extractors, template)
     a2d = _annotation_tag_to_dict
     self.assertEqual(a2d(bce._find_annotation(template, 'child')),
                      a2d(child_container.annotation))
     self.assertIsNone(bce._find_annotation(template, 'non_existant'))
 def test_build_extraction_tree(self):
     containers = {'root': root_container, 'child': child_container}
     tree = BaseContainerExtractor._build_extraction_tree(containers)
     self.assertEqual([['root'], ['root', 'child']], tree)
 def test_find_annotation(self):
     bce = BaseContainerExtractor(basic_extractors, template)
     a2d = _annotation_tag_to_dict
     self.assertEqual(a2d(bce._find_annotation(template, 'child')),
                      a2d(child_container.annotation))
     self.assertIsNone(bce._find_annotation(template, 'non_existant'))
 def test_build_extraction_tree(self):
     containers = {'root': root_container, 'child': child_container}
     tree = BaseContainerExtractor._build_extraction_tree(containers)
     self.assertEqual([['root'], ['root', 'child']], tree)