Skip to content
This repository has been archived by the owner on Sep 10, 2020. It is now read-only.

Commit

Permalink
Add test for checking invalid file format
Browse files Browse the repository at this point in the history
  • Loading branch information
Aviral14 committed Nov 20, 2019
1 parent 0c4baf3 commit 2323465
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions django_freeradius/tests/base/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@
class BaseTestUtils(object):
def test_find_available_username(self):
User = get_user_model()
User.objects.create(username='rohith', password='password')
self.assertEqual(find_available_username('rohith', []), 'rohith1')
User.objects.create(username='rohith1', password='password')
self.assertEqual(find_available_username('rohith', []), 'rohith2')
User.objects.create(username="rohith", password="password")
self.assertEqual(find_available_username("rohith", []), "rohith1")
User.objects.create(username="rohith1", password="password")
self.assertEqual(find_available_username("rohith", []), "rohith2")

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')
invalid_csv_path = self._get_path("static/test_batch_invalid.csv")
improper_csv_path = self._get_path("static/test_batch_improper.csv")
invalid_format_path = self._get_path("static/test_batch_invalid_format.pdf")
with self.assertRaises(ValidationError) as error:
validate_csvfile(open(invalid_csv_path, 'rt'))
self.assertTrue('Enter a valid email address' in error.exception.message)
validate_csvfile(open(invalid_format_path, "rb"))
self.assertTrue(
"Incorrect file format has been uploaded. Please Try Again!"
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)
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)

0 comments on commit 2323465

Please sign in to comment.