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

Commit

Permalink
Merge ebcb86c into 3674216
Browse files Browse the repository at this point in the history
  • Loading branch information
Vivekrajput20 committed Jul 10, 2019
2 parents 3674216 + ebcb86c commit 1a673d7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions django_freeradius/base/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def clean(self):
number_of_users = data.get('number_of_users')
if strategy == 'prefix' and not number_of_users:
self.add_error('number_of_users', 'This field is required')
super().clean()
return data

def __init__(self, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion django_freeradius/tests/base/test_batch_add_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_generate_username_when_repeat(self):
hashed_password = 'pbkdf2_sha256$100000$x3DUBnOFwraV$PU2dZZq1FcuBjagxVLPhhFvpicLn18fFCN5xiLsxATc='
cleartext_password = 'cleartext$password'
reader = [['rohith', cleartext_password, 'rohith@openwisp.com', 'Rohith', 'ASRK'],
['rohith', hashed_password, 'rohith@openwisp.com', '', '']]
['rohith', hashed_password, 'rohith@openwisp.org', '', '']]
batch = self._create_radius_batch(name='test',
strategy='csv',
csvfile=self._get_csvfile(reader))
Expand Down
11 changes: 6 additions & 5 deletions django_freeradius/tests/base/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ def test_batch_add_users_command(self):
radiusbatch = self.radius_batch_model.objects.first()
self.assertEqual(get_user_model().objects.all().count(), 3)
self.assertEqual(radiusbatch.expiration_date.strftime('%d-%m-%y'), '28-01-18')
path = self._get_path('static/test_batch_new.csv')
options = dict(file=path, name='test1')
self._call_command('batch_add_users', **options)
self.assertEqual(self.radius_batch_model.objects.all().count(), 2)
self.assertEqual(get_user_model().objects.all().count(), 6)
invalid_csv_path = self._get_path('static/test_batch_invalid.csv')
with self.assertRaises(CommandError):
options = dict(file='doesnotexist.csv', name='test2')
options = dict(file='doesnotexist.csv', name='test3')
self._call_command('batch_add_users', **options)
with self.assertRaises(SystemExit):
options = dict(file=invalid_csv_path, name='test3')
options = dict(file=invalid_csv_path, name='test4')
self._call_command('batch_add_users', **options)

def test_deactivate_expired_users_command(self):
Expand All @@ -71,9 +72,9 @@ def test_delete_old_users_command(self):
path = self._get_path('static/test_batch.csv')
options = dict(file=path, expiration='28-01-1970', name='test')
self._call_command('batch_add_users', **options)
expiration_date = now() - timedelta(days=30 * 15)
options['expiration'] = expiration_date.strftime('%d-%m-%Y')
options['name'] = 'test1'
expiration_date = (now() - timedelta(days=30 * 15)).strftime('%d-%m-%Y')
path = self._get_path('static/test_batch_new.csv')
options = dict(file=path, expiration=expiration_date, name='test1')
self._call_command('batch_add_users', **options)
self.assertEqual(get_user_model().objects.all().count(), 6)
call_command('delete_old_users')
Expand Down
3 changes: 3 additions & 0 deletions django_freeradius/tests/static/test_batch_new.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vivekchand,cleartext$password,vivek.chand@openwisp.com,Vivek,Chand
vivekchand,pbkdf2_sha256$100000$x3DUBnOFwraV$PU2dZZq1FcuBjagxVLPhhFvpicLn18fFCN5xiLsxATc=,vivek@openwisp.com,,
,,vivek.rajput@openwisp.com,,

0 comments on commit 1a673d7

Please sign in to comment.