예제 #1
0
 def test_clean(self):
     f = FilePathField(path=self.path)
     msg = "'Select a valid choice. a.py is not one of the available choices.'"
     with self.assertRaisesMessage(ValidationError, msg):
         f.clean("a.py")
     self.assertEqual(fix_os_paths(f.clean(self.path + "a.py")),
                      "/filepathfield_test_dir/a.py")
예제 #2
0
 def test_filepathfield_2(self):
     path = os.path.dirname(os.path.abspath(forms.__file__)) + '/'
     f = FilePathField(path=path)
     f.choices = [p for p in f.choices if p[0].endswith('.py')]
     f.choices.sort()
     expected = [('/django/forms/__init__.py', '__init__.py'),
                 ('/django/forms/boundfield.py', 'boundfield.py'),
                 ('/django/forms/fields.py', 'fields.py'),
                 ('/django/forms/forms.py', 'forms.py'),
                 ('/django/forms/formsets.py', 'formsets.py'),
                 ('/django/forms/models.py', 'models.py'),
                 ('/django/forms/renderers.py', 'renderers.py'),
                 ('/django/forms/utils.py', 'utils.py'),
                 ('/django/forms/widgets.py', 'widgets.py')]
     for exp, got in zip(expected, fix_os_paths(f.choices)):
         with self.subTest(expected=exp):
             self.assertEqual(exp[1], got[1])
             self.assertTrue(got[0].endswith(exp[0]))
     msg = "'Select a valid choice. fields.py is not one of the available choices.'"
     with self.assertRaisesMessage(ValidationError, msg):
         f.clean('fields.py')
     self.assertTrue(
         fix_os_paths(
             f.clean(path +
                     'fields.py')).endswith('/django/forms/fields.py'))
예제 #3
0
 def test_filepathfield_2(self):
     path = os.path.dirname(os.path.abspath(forms.__file__)) + '/'
     f = FilePathField(path=path)
     f.choices = [p for p in f.choices if p[0].endswith('.py')]
     f.choices.sort()
     expected = [
         ('/django/forms/__init__.py', '__init__.py'),
         ('/django/forms/boundfield.py', 'boundfield.py'),
         ('/django/forms/fields.py', 'fields.py'),
         ('/django/forms/forms.py', 'forms.py'),
         ('/django/forms/formsets.py', 'formsets.py'),
         ('/django/forms/models.py', 'models.py'),
         ('/django/forms/renderers.py', 'renderers.py'),
         ('/django/forms/utils.py', 'utils.py'),
         ('/django/forms/widgets.py', 'widgets.py')
     ]
     for exp, got in zip(expected, fix_os_paths(f.choices)):
         self.assertEqual(exp[1], got[1])
         self.assertTrue(got[0].endswith(exp[0]))
     msg = "'Select a valid choice. fields.py is not one of the available choices.'"
     with self.assertRaisesMessage(ValidationError, msg):
         f.clean('fields.py')
     self.assertTrue(fix_os_paths(f.clean(path + 'fields.py')).endswith('/django/forms/fields.py'))
예제 #4
0
 def test_clean(self):
     f = FilePathField(path=self.path)
     msg = "'Select a valid choice. a.py is not one of the available choices.'"
     with self.assertRaisesMessage(ValidationError, msg):
         f.clean('a.py')
     self.assertEqual(fix_os_paths(f.clean(self.path + 'a.py')), '/filepathfield_test_dir/a.py')