Ejemplo n.º 1
0
 def test_base_transformer(self):
     dic = {'test1': 'testus', 'test2': 'testus testus'}
     transformer = Transformer(dic)
     self.assertRaises(AttributeError, self.helper, transformer)
     self.assertTrue(transformer.is_valid())
     self.assertEqual(transformer.cleaned_data['test1'], 'testus')
     self.assertEqual(transformer.cleaned_data['test2'], 'testus testus')
Ejemplo n.º 2
0
 def test_init(self):
     dic = {'test': 'test'}
     transformer = Transformer(dic)
     self.assertEqual(transformer.dic, dic)
     self.assertEqual(Transformer.defaults, {})
     transformer = Transformer(dic, defaults={'name': 'fred'})
     self.assertEqual(transformer.defaults, {'name': 'fred'})
Ejemplo n.º 3
0
 def test_remap(self):
     dic = {
         'TEST': 'test', 'another_field': 'content', 'third_field': 'text'}
     transformer = Transformer(dic)
     transformer.mappings = {'test': 'TEST', 'field': 'another_field'}
     self.assertTrue(transformer.is_valid())
     res = transformer.cleaned_data
     self.assertEqual(res['test'], 'test')
     self.assertEqual(res['field'], 'content')
     self.assertEqual(res['third_field'], 'text')
     self.assertNotIn('TEST', res)
     self.assertNotIn('another_field', res)
Ejemplo n.º 4
0
 def test_blacklist(self):
     dic = {'test': 'something', 'another_field': 'rubish and something'}
     transformer = Transformer(dic)
     transformer.blacklist = {'another_field': [r'^rubish']}
     self.assertFalse(transformer.is_valid())