コード例 #1
0
 def test_validate_file_format(self):
     invalid_format_path = self._get_path(
         "static/test_batch_invalid_format.pdf")
     with self.assertRaises(ValidationError) as error:
         validate_csvfile(open(invalid_format_path, "rb"))
     self.assertTrue(
         "Unrecognized file format, the supplied file does not look like a CSV file."
         in error.exception.message)
コード例 #2
0
 def test_validate_csvfile(self):
     invalid_csv_path = self._get_path("static/test_batch_invalid.csv")
     improper_csv_path = self._get_path("static/test_batch_improper.csv")
     with self.assertRaises(ValidationError) as error:
         validate_csvfile(open(invalid_csv_path, "rt"))
     self.assertTrue(
         "Enter a valid email address" in error.exception.message)
     with self.assertRaises(ValidationError) as error:
         validate_csvfile(open(improper_csv_path, "rt"))
     self.assertTrue("Improper CSV format" in error.exception.message)
コード例 #3
0
ファイル: test_utils.py プロジェクト: levinrockx/oxynetz
 def test_validate_csvfile(self):
     invalid_csv_path = self._get_path('static/test_batch_invalid.csv')
     improper_csv_path = self._get_path('static/test_batch_improper.csv')
     with self.assertRaises(ValidationError) as error:
         validate_csvfile(open(invalid_csv_path, 'rt'))
     self.assertTrue(
         'Enter a valid email address' in error.exception.message)
     with self.assertRaises(ValidationError) as error:
         validate_csvfile(open(improper_csv_path, 'rt'))
     self.assertTrue('Improper CSV format' in error.exception.message)
コード例 #4
0
 def test_validate_csvfile(self):
     with self.assertRaises(ValidationError) as error:
         validate_csvfile(
             open('django_freeradius/tests/static/test_batch_invalid.csv',
                  'rt'))
     self.assertTrue(
         'Enter a valid email address' in error.exception.message)
     with self.assertRaises(ValidationError) as error:
         validate_csvfile(
             open('django_freeradius/tests/static/test_batch_improper.csv',
                  'rt'))
     self.assertTrue('Improper CSV format' in error.exception.message)
コード例 #5
0
 def clean(self):
     if self.csvfile and self.prefix or not self.csvfile and not self.prefix:
         raise ValidationError(
             _('Only one of the fields csvfile/prefix needs to be non empty'),
             code='invalid',
         )
     if self.strategy == 'csv' and self.prefix or self.strategy == 'prefix' and self.csvfile:
         raise ValidationError(
             _('Check your strategy and the respective values provided'),
             code='invalid',
         )
     if self.strategy == 'csv' and self.csvfile:
         validate_csvfile(self.csvfile.file)
     super(AbstractRadiusBatch, self).clean()
コード例 #6
0
 def clean(self):
     if self.strategy == 'csv' and not self.csvfile:
         raise ValidationError(
             {'csvfile': _('This field cannot be blank.')}, code='invalid')
     if self.strategy == 'prefix' and not self.prefix:
         raise ValidationError({'prefix': _('This field cannot be blank.')},
                               code='invalid')
     if self.strategy == 'csv' and self.prefix or self.strategy == 'prefix' and self.csvfile:
         # this case would happen only when using the internal API
         raise ValidationError(
             _('Mixing fields of different strategies'),
             code='invalid',
         )
     if self.strategy == 'csv':
         validate_csvfile(self.csvfile.file)
     super(AbstractRadiusBatch, self).clean()