예제 #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'
     self.assertEqual(bce._validate_and_adapt_item(data, template),
                      {'price': ['10'], '_type': 'skip_checks'})
     data = {
         'price': ['10'],
         'description': ['It can do everything except make calls'],
         'name': ['Smartphone 6']
     }
     result = data.copy()
     result['_type'] = 'default'
     self.assertEqual(bce._validate_and_adapt_item(data, template), result)
     bce.extra_requires = ['pid']
     self.assertEqual(bce._validate_and_adapt_item(data, template), {})
     data['pid'] = ['13532']
     result = data.copy()
     result['_type'] = 'default'
     self.assertEqual(bce._validate_and_adapt_item(data, template), result)
     bce.extra_requires = ['pid', '_sticky1']
     self.assertEqual(bce._validate_and_adapt_item(data, template), {})
     data['_sticky1'] = True
     self.assertEqual(bce._validate_and_adapt_item(data, template), result)
예제 #2
0
 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'))