From 1e42ae1ba3d0792c6e3430099f04e378f29a6010 Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Fri, 16 Jun 2017 18:03:36 +0200 Subject: [PATCH 01/31] [general] added abstract models --- django_freeradius/admin.py | 68 ++++--- django_freeradius/base/__init__.py | 0 django_freeradius/base/admin.py | 50 +++++ django_freeradius/base/base.py | 15 ++ django_freeradius/base/models.py | 252 +++++++++++++++++++++++++ django_freeradius/models.py | 292 +++++------------------------ 6 files changed, 400 insertions(+), 277 deletions(-) create mode 100644 django_freeradius/base/__init__.py create mode 100644 django_freeradius/base/admin.py create mode 100644 django_freeradius/base/base.py create mode 100644 django_freeradius/base/models.py diff --git a/django_freeradius/admin.py b/django_freeradius/admin.py index aea9306..e69afc7 100644 --- a/django_freeradius/admin.py +++ b/django_freeradius/admin.py @@ -4,52 +4,60 @@ RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, RadiusPostAuthentication, RadiusReply, RadiusUserGroup) +from .base.admin import (AbstractRadiusGroupAdmin, AbstractRadiusGroupUsersAdmin, + AbstractRadiusCheckAdmin, AbstractRadiusAccountingAdmin, + AbstractRadiusReplyAdmin, AbstractNasAdmin, + AbstractRadiusGroupCheckAdmin, AbstractRadiusGroupReplyAdmin, + AbstractRadiusPostAuthenticationAdmin, AbstractRadiusUserGroupAdmin) -@admin.register(RadiusGroup) -class RadiusGroupAdmin(admin.ModelAdmin): - pass +class RadiusGroupAdmin(AbstractRadiusGroupAdmin): + model = RadiusGroup -@admin.register(RadiusGroupUsers) -class RadiusGroupUsers(admin.ModelAdmin): - pass +class RadiusGroupUsersAdmin(AbstractRadiusGroupUsersAdmin): + model = RadiusGroupUsers -@admin.register(RadiusCheck) -class RadiusCheck(admin.ModelAdmin): - pass +class RadiusCheckAdmin(AbstractRadiusCheckAdmin): + model = RadiusCheck -@admin.register(RadiusReply) -class RadiusReply(admin.ModelAdmin): - pass +class RadiusReplyAdmin(AbstractRadiusReplyAdmin): + model = RadiusReply -@admin.register(RadiusAccounting) -class RadiusAccounting(admin.ModelAdmin): - pass +class RadiusAccountingAdmin(AbstractRadiusAccountingAdmin): + model = RadiusAccounting -@admin.register(Nas) -class Nas(admin.ModelAdmin): - pass +class NasAdmin(AbstractNasAdmin): + model = Nas -@admin.register(RadiusUserGroup) -class RadiusUserGroup(admin.ModelAdmin): - pass +class RadiusUserGroupAdmin(AbstractRadiusUserGroupAdmin): + model = RadiusUserGroup -@admin.register(RadiusGroupReply) -class RadiusGroupReply(admin.ModelAdmin): - pass +class RadiusGroupReplyAdmin(AbstractRadiusGroupReplyAdmin): + model = RadiusGroupReply -@admin.register(RadiusGroupCheck) -class RadiusGroupCheck(admin.ModelAdmin): - pass +class RadiusGroupCheckAdmin(AbstractRadiusGroupCheckAdmin): + model = RadiusGroupCheck -@admin.register(RadiusPostAuthentication) -class RadiusPostAuthentication(admin.ModelAdmin): - pass + +class RadiusPostAuthenticationAdmin(AbstractRadiusPostAuthenticationAdmin): + model = RadiusPostAuthentication + + +admin.site.register(RadiusPostAuthentication, RadiusPostAuthenticationAdmin) +admin.site.register(RadiusGroupCheck, RadiusGroupCheckAdmin) +admin.site.register(RadiusGroupReply, RadiusGroupReplyAdmin) +admin.site.register(RadiusUserGroup, RadiusUserGroupAdmin) +admin.site.register(Nas, NasAdmin) +admin.site.register(RadiusAccounting, RadiusAccountingAdmin) +admin.site.register(RadiusReply, RadiusReplyAdmin) +admin.site.register(RadiusCheck, RadiusCheckAdmin) +admin.site.register(RadiusGroupUsers, RadiusGroupUsersAdmin) +admin.site.register(RadiusGroup, RadiusGroupAdmin) diff --git a/django_freeradius/base/__init__.py b/django_freeradius/base/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_freeradius/base/admin.py b/django_freeradius/base/admin.py new file mode 100644 index 0000000..abbe4bc --- /dev/null +++ b/django_freeradius/base/admin.py @@ -0,0 +1,50 @@ +from django.contrib.admin import ModelAdmin + + +class TimeStampedEditableAdmin(ModelAdmin): + """ + ModelAdmin for TimeStampedEditableModel + """ + def __init__(self, *args, **kwargs): + self.readonly_fields += ('modified') + super(TimeStampedEditableAdmin, self).__init__(*args, **kwargs) + + +class AbstractRadiusGroupAdmin(ModelAdmin): + pass + + +class AbstractRadiusGroupUsersAdmin(ModelAdmin): + pass + + +class AbstractRadiusCheckAdmin(ModelAdmin): + pass + + +class AbstractRadiusReplyAdmin(ModelAdmin): + pass + + +class AbstractRadiusAccountingAdmin(ModelAdmin): + pass + + +class AbstractNasAdmin(ModelAdmin): + pass + + +class AbstractRadiusUserGroupAdmin(ModelAdmin): + pass + + +class AbstractRadiusGroupReplyAdmin(ModelAdmin): + pass + + +class AbstractRadiusGroupCheckAdmin(ModelAdmin): + pass + + +class AbstractRadiusPostAuthenticationAdmin(ModelAdmin): + pass diff --git a/django_freeradius/base/base.py b/django_freeradius/base/base.py new file mode 100644 index 0000000..f8a2701 --- /dev/null +++ b/django_freeradius/base/base.py @@ -0,0 +1,15 @@ +from django.db import models +from django.utils.translation import ugettext_lazy as _ +from model_utils.fields import AutoLastModifiedField + + +class TimeStampedEditableAdmin(models.Model): + + # An abstract base class model that provides self-updating + # modified fields. + + id = models.UUIDField(primary_key=True, editable=False) + modified = AutoLastModifiedField(_('modified'), editable=True) + + class Meta: + abstract = True diff --git a/django_freeradius/base/models.py b/django_freeradius/base/models.py new file mode 100644 index 0000000..662ecfd --- /dev/null +++ b/django_freeradius/base/models.py @@ -0,0 +1,252 @@ +from django.utils.translation import ugettext_lazy as _ +from .base import TimeStampedEditableAdmin +from django.db import models + +RADOP_CHECK_TYPES = ( + ('=', '='), + (':=', ':='), + ('==', '=='), + ('+=', '+='), + ('!=', '!='), + ('>', '>'), + ('>=', '>='), + ('<', '<'), + ('<=', '<='), + ('=~', '=~'), + ('!~', '!~'), + ('=*', '=*'), + ('!*', '!*'), +) + +RADOP_REPLY_TYPES = ( + ('=', '='), + (':=', ':='), + ('+=', '+='), +) + + +class AbstractRadiusGroup(TimeStampedEditableAdmin): + group_name = models.CharField( + verbose_name=_('groupname'), max_length=255, unique=True, db_column='groupname', db_index=True) + priority = models.IntegerField(verbose_name=_('priority'), default=1) + creation_date = models.DateField(verbose_name=_('creation date'), null=True, db_column='created_at') + modification_date = models.DateField( + verbose_name=_('modification date'), null=True, db_column='updated_at') + notes = models.CharField( + verbose_name=_('notes'), max_length=64, blank=True, null=True) + + class Meta: + db_table = 'radiusgroup' + verbose_name = _('radiusgroup') + verbose_name_plural = _('radiusgroups') + abstract = True + + def __str__(self): + return self.group_name + + +class AbstractRadiusGroupUsers(TimeStampedEditableAdmin): + user_name = models.CharField( + verbose_name=_('username'), max_length=64, unique=True, db_column='username') + group_name = models.CharField( + verbose_name=_('groupname'), max_length=255, unique=True, db_column='groupname') + radius_reply = models.ManyToManyField( + 'RadiusReply', verbose_name=_('radius reply'), blank=True, db_column='radiusreply') + radius_check = models.ManyToManyField( + 'RadiusCheck', verbose_name=_('radius check'), blank=True, db_column='radiuscheck') + + class Meta: + db_table = 'radiusgroupusers' + verbose_name = _('radiusgroupusers') + verbose_name_plural = _('radiusgroupusers') + abstract = True + + def __str__(self): + return self.user_name + + +class AbstractRadiusReply(TimeStampedEditableAdmin): + user_name = models.CharField( + verbose_name=_('username'), max_length=64, db_column='username', db_index=True) + value = models.CharField(verbose_name=_('value'), max_length=253) + op = models.CharField( + verbose_name=_('operator'), max_length=2, choices=RADOP_REPLY_TYPES, default='=') + attribute = models.CharField(verbose_name=_('attribute'), max_length=64) + + class Meta: + db_table = 'radreply' + verbose_name = _('radiusreply') + verbose_name_plural = _('radiusreplies') + abstract = True + + def __str__(self): + return self.user_name + + +class AbstractRadiusCheck(TimeStampedEditableAdmin): + user_name = models.CharField( + verbose_name=_('username'), max_length=64, db_column='username', db_index=True) + value = models.CharField(verbose_name=_('radiusvalue'), max_length=253) + op = models.CharField( + verbose_name=_('operator'), max_length=2, choices=RADOP_CHECK_TYPES, default=':=') + attribute = models.CharField( + verbose_name=_('attribute'), max_length=64) + + class Meta: + db_table = 'radcheck' + verbose_name = _('radiuscheck') + verbose_name_plural = _('radiuschecks') + abstract = True + + def __str__(self): + return self.user_name + + +class AbstractRadiusAccounting(TimeStampedEditableAdmin): + rad_acct_id = models.BigIntegerField(primary_key=True, db_column='radacctid') + acct_session_id = models.CharField(max_length=64, db_column='acctsessionid', db_index=True) + acct_unique_id = models.CharField(max_length=32, db_column='acctuniqueid', unique=True) + user_name = models.CharField( + verbose_name=_('username'), max_length=64, db_column='username', db_index=True) + group_name = models.CharField( + verbose_name=_('groupname'), max_length=64, db_column='groupname') + realm = models.CharField(verbose_name=_('realm'), max_length=64, null=True) + nas_ip_address = models.CharField(max_length=15, db_column='nasipaddress', db_index=True) + nas_port_id = models.CharField(max_length=15, null=True, db_column='nasportid') + nas_port_type = models.CharField( + verbose_name=_('nas port type'), max_length=32, db_column='nasporttype') + acct_start_time = models.DateTimeField( + verbose_name=_('acct start time'), db_column='acctstarttime', db_index=True) + acct_stop_time = models.DateTimeField( + verbose_name=_('acct stop time'), null=True, db_column='acctstoptime', db_index=True) + acct_session_time = models.IntegerField( + verbose_name=_('acct session time'), null=True, db_column='acctsessiontime', db_index=True) + acct_authentic = models.CharField( + verbose_name=_('acct authentic'), max_length=32, null=True, db_column='acctauthentic') + connection_info_start = models.CharField( + verbose_name=_('connection info start'), max_length=50, null=True, db_column='connectinfo_start') + connection_info_stop = models.CharField( + verbose_name=_('connection info stop'), max_length=50, null=True, db_column='connectinfo_stop') + acct_input_octets = models.BigIntegerField( + verbose_name=_('acct input octets'), null=True, db_column='acctinputoctets') + acct_output_octets = models.BigIntegerField( + verbose_name=_('acct output octets'), null=True, db_column='acctoutputoctets') + callingStationId = models.CharField(max_length=50, db_column='calledstationid') + calledStationId = models.CharField(max_length=50, db_column='callingstationid') + acct_terminate_cause = models.CharField( + verbose_name=_('acct terminate cause'), max_length=32, db_column='acctterminatecause') + service_type = models.CharField( + verbose_name=_('service type'), max_length=32, null=True, db_column='servicetype') + framed_protocol = models.CharField( + verbose_name=_('framed protocol'), max_length=32, null=True, db_column='framedprotocol') + framed_ip_address = models.CharField(max_length=15, db_column='framedipaddress', db_index=True) + acct_start_delay = models.IntegerField( + verbose_name=_('acct start delay'), null=True, db_column='acctstartdelay') + acct_stop_delay = models.IntegerField( + verbose_name=_('acct stop delay'), null=True, db_column='acctstopdelay') + xascend_session_svrkey = models.CharField( + verbose_name=_( + 'xascend session svrkey'), max_length=10, null=True, db_column='xascendsessionsvrkey') + + class Meta: + db_table = 'radacct' + verbose_name = _('accounting') + verbose_name_plural = _('accounting') + abstract = True + + def __str__(self): + return self.acct_unique_id + + +class AbstractNas(TimeStampedEditableAdmin): + nas_name = models.CharField( + verbose_name=_('nas name'), max_length=128, unique=True, help_text=_('NAS Name (or IP address)'), + db_index=True, db_column='nasname') + short_name = models.CharField(verbose_name=_('short name'), max_length=32, db_column='shortname') + type = models.CharField(verbose_name=_('type'), max_length=30) + secret = models.CharField( + verbose_name=_('secret'), max_length=60, help_text=_('Shared Secret')) + ports = models.IntegerField(verbose_name=_('ports'), blank=True, null=True) + community = models.CharField( + verbose_name=_('community'), max_length=50, blank=True, null=True) + description = models.CharField( + verbose_name=_('description'), max_length=200, null=True) + server = models.CharField( + verbose_name=_('server'), max_length=64, null=True) + + class Meta: + db_table = 'nas' + verbose_name = _('nas') + verbose_name_plural = _('nas') + abstract = True + + def __str__(self): + return self.nas_name + + +class AbstractRadiusUserGroup(TimeStampedEditableAdmin): + user_name = models.CharField( + verbose_name=_('username'), max_length=64, db_column='username', db_index=True) + group_name = models.CharField(verbose_name=_('groupname'), max_length=64, db_column='groupname') + priority = models.IntegerField(verbose_name=_('priority'), default=1) + + class Meta: + db_table = 'radusergroup' + verbose_name = _('radiususergroup') + verbose_name_plural = _('radiususergroup') + abstract = True + + def __str__(self): + return str(self.user_name) + + +class AbstractRadiusGroupReply(TimeStampedEditableAdmin): + group_name = models.CharField( + verbose_name=_('groupname'), max_length=64, db_column='groupname', db_index=True) + attribute = models.CharField(verbose_name=_('attribute'), max_length=64) + op = models.CharField( + verbose_name=_('operator'), max_length=2, choices=RADOP_REPLY_TYPES, default='=') + value = models.CharField(verbose_name=_('value'), max_length=253) + + class Meta: + db_table = 'radgroupreply' + verbose_name = _('radiusgroupreply') + verbose_name_plural = _('radiusgroupreplies') + abstract = True + + def __str__(self): + return str(self.group_name) + + +class AbstractRadiusGroupCheck(TimeStampedEditableAdmin): + group_name = models.CharField( + verbose_name=_('groupname'), max_length=64, db_column='groupname', db_index=True) + attribute = models.CharField(verbose_name=_('attribute'), max_length=64) + op = models.CharField( + verbose_name=_('operator'), max_length=2, choices=RADOP_CHECK_TYPES, default=':=') + value = models.CharField(verbose_name=_('value'), max_length=253) + + class Meta: + db_table = 'radgroupcheck' + verbose_name = _('radiusgroupcheck') + verbose_name_plural = _('radiusgroupcheck') + abstract = True + + def __str__(self): + return str(self.group_name) + + +class AbstractRadiusPostAuthentication(TimeStampedEditableAdmin): + user_name = models.CharField(verbose_name=_('username'), max_length=64, db_column='username') + password = models.CharField(verbose_name=_('password'), max_length=64, db_column='pass') + reply = models.CharField(verbose_name=_('reply'), max_length=32) + auth_date = models.DateTimeField(verbose_name=_('authdate'), db_column='authdate', auto_now=True) + + class Meta: + db_table = 'radpostauth' + verbose_name = _('radiuspostauthentication') + verbose_name_plural = _('radiuspostauthentication') + abstract = True + + def __str__(self): + return str(self.user_name) diff --git a/django_freeradius/models.py b/django_freeradius/models.py index fb704be..f0878ef 100644 --- a/django_freeradius/models.py +++ b/django_freeradius/models.py @@ -1,247 +1,45 @@ -from django.db import models -from django.utils.translation import ugettext_lazy as _ - -# Create your models here. - -RADOP_CHECK_TYPES = ( - ('=', '='), - (':=', ':='), - ('==', '=='), - ('+=', '+='), - ('!=', '!='), - ('>', '>'), - ('>=', '>='), - ('<', '<'), - ('<=', '<='), - ('=~', '=~'), - ('!~', '!~'), - ('=*', '=*'), - ('!*', '!*'), -) - -RADOP_REPLY_TYPES = ( - ('=', '='), - (':=', ':='), - ('+=', '+='), -) - -# these models comes from OWUSM data model, need check if we need them" - - -class RadiusGroup(models.Model): - id = models.UUIDField(primary_key=True, db_column='id') - group_name = models.CharField( - verbose_name=_('groupname'), max_length=255, unique=True, db_column='groupname', db_index=True) - priority = models.IntegerField(verbose_name=_('priority'), default=1, db_column='priority') - creation_date = models.DateField(verbose_name=_('creation date'), null=True, db_column='created_at') - modification_date = models.DateField( - verbose_name=_('modification date'), null=True, db_column='updated_at') - notes = models.CharField( - verbose_name=_('notes'), max_length=64, blank=True, null=True, db_column='notes') - - def __str__(self): - return self.group_name - - class Meta: - db_table = 'radiusgroup' - verbose_name = _('radiusgroup') - verbose_name_plural = _('radiusgroups') - - -class RadiusGroupUsers(models.Model): - user_name = models.CharField( - verbose_name=_('username'), max_length=64, unique=True, db_column='username') - id = models.UUIDField(primary_key=True, db_column='id') - group_name = models.CharField( - verbose_name=_('groupname'), max_length=255, unique=True, db_column='groupname') - radius_reply = models.ManyToManyField( - 'RadiusReply', verbose_name=_('radius reply'), blank=True, db_column='radiusreply') - radius_check = models.ManyToManyField( - 'RadiusCheck', verbose_name=_('radius check'), blank=True, db_column='radiuscheck') - - class Meta: - db_table = 'radiusgroupusers' - verbose_name = _('radiusgroupusers') - verbose_name_plural = _('radiusgroupusers') - - def __str__(self): - return self.user_name - - -class RadiusReply(models.Model): - user_name = models.CharField( - verbose_name=_('username'), max_length=64, db_column='username', db_index=True) - value = models.CharField(verbose_name=_('value'), max_length=253, db_column='value') - op = models.CharField( - verbose_name=_('operator'), max_length=2, choices=RADOP_REPLY_TYPES, db_column='op', default='=') - attribute = models.CharField(verbose_name=_('attribute'), max_length=64, db_column='attribute') - - class Meta: - db_table = 'radreply' - verbose_name = _('radiusreply') - verbose_name_plural = _('radiusreplies') - - def __str__(self): - return self.user_name - - -class RadiusCheck(models.Model): - user_name = models.CharField( - verbose_name=_('username'), max_length=64, db_column='username', db_index=True) - value = models.CharField(verbose_name=_('radiusvalue'), max_length=253, db_column='value') - op = models.CharField( - verbose_name=_('operator'), max_length=2, choices=RADOP_CHECK_TYPES, db_column='op', default=':=') - attribute = models.CharField( - verbose_name=_('attribute'), max_length=64, db_column='attribute') - - class Meta: - db_table = 'radcheck' - verbose_name = _('radiuscheck') - verbose_name_plural = _('radiuschecks') - - def __str__(self): - return self.user_name - - -class RadiusAccounting(models.Model): - rad_acct_id = models.BigIntegerField(primary_key=True, db_column='radacctid') - acct_session_id = models.CharField(max_length=64, db_column='acctsessionid', db_index=True) - acct_unique_id = models.CharField(max_length=32, db_column='acctuniqueid', unique=True) - user_name = models.CharField( - verbose_name=_('username'), max_length=64, db_column='username', db_index=True) - group_name = models.CharField( - verbose_name=_('groupname'), max_length=64, db_column='groupname') - realm = models.CharField(verbose_name=_('realm'), max_length=64, null=True, db_column='realm') - nas_ip_address = models.CharField(max_length=15, db_column='nasipaddress', db_index=True) - nas_port_id = models.CharField(max_length=15, null=True, db_column='nasportid') - nas_port_type = models.CharField( - verbose_name=_('nas port type'), max_length=32, db_column='nasporttype') - acct_start_time = models.DateTimeField( - verbose_name=_('acct start time'), db_column='acctstarttime', db_index=True) - acct_stop_time = models.DateTimeField( - verbose_name=_('acct stop time'), null=True, db_column='acctstoptime', db_index=True) - acct_session_time = models.IntegerField( - verbose_name=_('acct session time'), null=True, db_column='acctsessiontime', db_index=True) - acct_authentic = models.CharField( - verbose_name=_('acct authentic'), max_length=32, null=True, db_column='acctauthentic') - connection_info_start = models.CharField( - verbose_name=_('connection info start'), max_length=50, null=True, db_column='connectinfo_start') - connection_info_stop = models.CharField( - verbose_name=_('connection info stop'), max_length=50, null=True, db_column='connectinfo_stop') - acct_input_octets = models.BigIntegerField( - verbose_name=_('acct input octets'), null=True, db_column='acctinputoctets') - acct_output_octets = models.BigIntegerField( - verbose_name=_('acct output octets'), null=True, db_column='acctoutputoctets') - callingStationId = models.CharField(max_length=50, db_column='calledstationid') - calledStationId = models.CharField(max_length=50, db_column='callingstationid') - acct_terminate_cause = models.CharField( - verbose_name=_('acct terminate cause'), max_length=32, db_column='acctterminatecause') - service_type = models.CharField( - verbose_name=_('service type'), max_length=32, null=True, db_column='servicetype') - framed_protocol = models.CharField( - verbose_name=_('framed protocol'), max_length=32, null=True, db_column='framedprotocol') - framed_ip_address = models.CharField(max_length=15, db_column='framedipaddress', db_index=True) - acct_start_delay = models.IntegerField( - verbose_name=_('acct start delay'), null=True, db_column='acctstartdelay') - acct_stop_delay = models.IntegerField( - verbose_name=_('acct stop delay'), null=True, db_column='acctstopdelay') - xascend_session_svrkey = models.CharField( - verbose_name=_( - 'xascend session svrkey'), max_length=10, null=True, db_column='xascendsessionsvrkey') - - class Meta: - db_table = 'radacct' - verbose_name = _('accounting') - verbose_name_plural = _('accounting') - - def __str__(self): - return self.acct_unique_id - - -class Nas(models.Model): - nas_name = models.CharField( - verbose_name=_('nas name'), max_length=128, unique=True, help_text=_('NAS Name (or IP address)'), - db_index=True, db_column='nasname') - short_name = models.CharField(verbose_name=_('short name'), max_length=32, db_column='shortname') - type = models.CharField(verbose_name=_('type'), max_length=30, db_column='type') - secret = models.CharField( - verbose_name=_('secret'), max_length=60, help_text=_('Shared Secret'), db_column='secret') - ports = models.IntegerField(verbose_name=_('ports'), blank=True, null=True, db_column='ports') - community = models.CharField( - verbose_name=_('community'), max_length=50, blank=True, null=True, db_column='community') - description = models.CharField( - verbose_name=_('description'), max_length=200, null=True, db_column='description') - server = models.CharField( - verbose_name=_('server'), max_length=64, null=True, db_column='server') - - class Meta: - db_table = 'nas' - verbose_name = _('nas') - verbose_name_plural = _('nas') - - def __str__(self): - return self.nas_name - - -class RadiusUserGroup(models.Model): - user_name = models.CharField( - verbose_name=_('username'), max_length=64, db_column='username', db_index=True) - group_name = models.CharField(verbose_name=_('groupname'), max_length=64, db_column='groupname') - priority = models.IntegerField(verbose_name=_('priority'), default=1, db_column='priority') - - class Meta: - db_table = 'radusergroup' - verbose_name = _('radiususergroup') - verbose_name_plural = _('radiususergroup') - - def __str__(self): - return str(self.user_name) - - -class RadiusGroupReply(models.Model): - group_name = models.CharField( - verbose_name=_('groupname'), max_length=64, db_column='groupname', db_index=True) - attribute = models.CharField(verbose_name=_('attribute'), max_length=64, db_column='attribute') - op = models.CharField( - verbose_name=_('operator'), max_length=2, choices=RADOP_REPLY_TYPES, db_column='op', default='=') - value = models.CharField(verbose_name=_('value'), max_length=253, db_column='value') - - class Meta: - db_table = 'radgroupreply' - verbose_name = _('radiusgroupreply') - verbose_name_plural = _('radiusgroupreplies') - - def __str__(self): - return str(self.group_name) - - -class RadiusGroupCheck(models.Model): - group_name = models.CharField( - verbose_name=_('groupname'), max_length=64, db_column='groupname', db_index=True) - attribute = models.CharField(verbose_name=_('attribute'), max_length=64, db_column='attribute') - op = models.CharField( - verbose_name=_('operator'), max_length=2, choices=RADOP_CHECK_TYPES, db_column='op', default=':=') - value = models.CharField(verbose_name=_('value'), max_length=253, db_column='value') - - class Meta: - db_table = 'radgroupcheck' - verbose_name = _('radiusgroupcheck') - verbose_name_plural = _('radiusgroupcheck') - - def __str__(self): - return str(self.group_name) - - -class RadiusPostAuthentication(models.Model): - user_name = models.CharField(verbose_name=_('username'), max_length=64, db_column='username') - password = models.CharField(verbose_name=_('password'), max_length=64, db_column='pass') - reply = models.CharField(verbose_name=_('reply'), max_length=32, db_column='reply') - auth_date = models.DateTimeField(verbose_name=_('authdate'), db_column='authdate', auto_now=True) - - class Meta: - db_table = 'radpostauth' - verbose_name = _('radiuspostauthentication') - verbose_name_plural = _('radiuspostauthentication') - - def __str__(self): - return str(self.user_name) +from .base.models import (AbstractRadiusGroup, AbstractRadiusGroupUsers, + AbstractRadiusCheck, AbstractRadiusAccounting, + AbstractRadiusReply, AbstractNas, + AbstractRadiusGroupCheck, AbstractRadiusGroupReply, + AbstractRadiusPostAuthentication, AbstractRadiusUserGroup) + + +class RadiusGroup(AbstractRadiusGroup): + pass + + +class RadiusGroupUsers(AbstractRadiusGroupUsers): + pass + + +class RadiusCheck(AbstractRadiusCheck): + pass + + +class RadiusAccounting(AbstractRadiusAccounting): + pass + + +class RadiusReply(AbstractRadiusReply): + pass + + +class Nas(AbstractNas): + pass + + +class RadiusGroupCheck(AbstractRadiusGroupCheck): + pass + + +class RadiusGroupReply(AbstractRadiusGroupReply): + pass + + +class RadiusPostAuthentication(AbstractRadiusPostAuthentication): + pass + + +class RadiusUserGroup(AbstractRadiusUserGroup): + pass From 429b3ff2137caa9e3c0ba94d4e93fdaeee7438bf Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Fri, 16 Jun 2017 18:23:20 +0200 Subject: [PATCH 02/31] [clean] clean code --- django_freeradius/admin.py | 14 ++++++++------ django_freeradius/base/base.py | 1 + django_freeradius/base/models.py | 3 ++- django_freeradius/models.py | 9 +++++---- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/django_freeradius/admin.py b/django_freeradius/admin.py index e69afc7..4840710 100644 --- a/django_freeradius/admin.py +++ b/django_freeradius/admin.py @@ -1,15 +1,17 @@ from django.contrib import admin +from .base.admin import (AbstractNasAdmin, AbstractRadiusAccountingAdmin, + AbstractRadiusCheckAdmin, AbstractRadiusGroupAdmin, + AbstractRadiusGroupCheckAdmin, + AbstractRadiusGroupReplyAdmin, + AbstractRadiusGroupUsersAdmin, + AbstractRadiusPostAuthenticationAdmin, + AbstractRadiusReplyAdmin, + AbstractRadiusUserGroupAdmin) from .models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, RadiusPostAuthentication, RadiusReply, RadiusUserGroup) -from .base.admin import (AbstractRadiusGroupAdmin, AbstractRadiusGroupUsersAdmin, - AbstractRadiusCheckAdmin, AbstractRadiusAccountingAdmin, - AbstractRadiusReplyAdmin, AbstractNasAdmin, - AbstractRadiusGroupCheckAdmin, AbstractRadiusGroupReplyAdmin, - AbstractRadiusPostAuthenticationAdmin, AbstractRadiusUserGroupAdmin) - class RadiusGroupAdmin(AbstractRadiusGroupAdmin): model = RadiusGroup diff --git a/django_freeradius/base/base.py b/django_freeradius/base/base.py index f8a2701..8a7cede 100644 --- a/django_freeradius/base/base.py +++ b/django_freeradius/base/base.py @@ -1,5 +1,6 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ + from model_utils.fields import AutoLastModifiedField diff --git a/django_freeradius/base/models.py b/django_freeradius/base/models.py index 662ecfd..935dbf6 100644 --- a/django_freeradius/base/models.py +++ b/django_freeradius/base/models.py @@ -1,6 +1,7 @@ +from django.db import models from django.utils.translation import ugettext_lazy as _ + from .base import TimeStampedEditableAdmin -from django.db import models RADOP_CHECK_TYPES = ( ('=', '='), diff --git a/django_freeradius/models.py b/django_freeradius/models.py index f0878ef..ab9b37f 100644 --- a/django_freeradius/models.py +++ b/django_freeradius/models.py @@ -1,8 +1,9 @@ -from .base.models import (AbstractRadiusGroup, AbstractRadiusGroupUsers, - AbstractRadiusCheck, AbstractRadiusAccounting, - AbstractRadiusReply, AbstractNas, +from .base.models import (AbstractNas, AbstractRadiusAccounting, + AbstractRadiusCheck, AbstractRadiusGroup, AbstractRadiusGroupCheck, AbstractRadiusGroupReply, - AbstractRadiusPostAuthentication, AbstractRadiusUserGroup) + AbstractRadiusGroupUsers, + AbstractRadiusPostAuthentication, + AbstractRadiusReply, AbstractRadiusUserGroup) class RadiusGroup(AbstractRadiusGroup): From da630dcf7348fc0d0de2f37f264107d164f1d5fc Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Fri, 16 Jun 2017 19:45:42 +0200 Subject: [PATCH 03/31] Added requested changes --- django_freeradius/admin.py | 22 ++++++++++------------ django_freeradius/base/admin.py | 22 +++++++++++----------- django_freeradius/base/base.py | 14 +++++++------- django_freeradius/base/models.py | 2 ++ 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/django_freeradius/admin.py b/django_freeradius/admin.py index 4840710..e718f80 100644 --- a/django_freeradius/admin.py +++ b/django_freeradius/admin.py @@ -13,53 +13,51 @@ RadiusPostAuthentication, RadiusReply, RadiusUserGroup) +@admin.register(RadiusGroup) class RadiusGroupAdmin(AbstractRadiusGroupAdmin): model = RadiusGroup +@admin.register(RadiusGroupUsers) class RadiusGroupUsersAdmin(AbstractRadiusGroupUsersAdmin): model = RadiusGroupUsers +@admin.register(RadiusCheck) class RadiusCheckAdmin(AbstractRadiusCheckAdmin): model = RadiusCheck +@admin.register(RadiusReply) class RadiusReplyAdmin(AbstractRadiusReplyAdmin): model = RadiusReply +@admin.register(RadiusAccounting) class RadiusAccountingAdmin(AbstractRadiusAccountingAdmin): model = RadiusAccounting +@admin.register(Nas) class NasAdmin(AbstractNasAdmin): model = Nas +@admin.register(RadiusUserGroup) class RadiusUserGroupAdmin(AbstractRadiusUserGroupAdmin): model = RadiusUserGroup +@admin.register(RadiusGroupReply) class RadiusGroupReplyAdmin(AbstractRadiusGroupReplyAdmin): model = RadiusGroupReply +@admin.register(RadiusGroupCheck) class RadiusGroupCheckAdmin(AbstractRadiusGroupCheckAdmin): model = RadiusGroupCheck +@admin.register(RadiusPostAuthentication) class RadiusPostAuthenticationAdmin(AbstractRadiusPostAuthenticationAdmin): model = RadiusPostAuthentication - - -admin.site.register(RadiusPostAuthentication, RadiusPostAuthenticationAdmin) -admin.site.register(RadiusGroupCheck, RadiusGroupCheckAdmin) -admin.site.register(RadiusGroupReply, RadiusGroupReplyAdmin) -admin.site.register(RadiusUserGroup, RadiusUserGroupAdmin) -admin.site.register(Nas, NasAdmin) -admin.site.register(RadiusAccounting, RadiusAccountingAdmin) -admin.site.register(RadiusReply, RadiusReplyAdmin) -admin.site.register(RadiusCheck, RadiusCheckAdmin) -admin.site.register(RadiusGroupUsers, RadiusGroupUsersAdmin) -admin.site.register(RadiusGroup, RadiusGroupAdmin) diff --git a/django_freeradius/base/admin.py b/django_freeradius/base/admin.py index abbe4bc..71c926b 100644 --- a/django_freeradius/base/admin.py +++ b/django_freeradius/base/admin.py @@ -6,45 +6,45 @@ class TimeStampedEditableAdmin(ModelAdmin): ModelAdmin for TimeStampedEditableModel """ def __init__(self, *args, **kwargs): - self.readonly_fields += ('modified') + self.readonly_fields += ('created', 'modified',) super(TimeStampedEditableAdmin, self).__init__(*args, **kwargs) -class AbstractRadiusGroupAdmin(ModelAdmin): +class AbstractRadiusGroupAdmin(TimeStampedEditableAdmin): pass -class AbstractRadiusGroupUsersAdmin(ModelAdmin): +class AbstractRadiusGroupUsersAdmin(TimeStampedEditableAdmin): pass -class AbstractRadiusCheckAdmin(ModelAdmin): +class AbstractRadiusCheckAdmin(TimeStampedEditableAdmin): pass -class AbstractRadiusReplyAdmin(ModelAdmin): +class AbstractRadiusReplyAdmin(TimeStampedEditableAdmin): pass -class AbstractRadiusAccountingAdmin(ModelAdmin): +class AbstractRadiusAccountingAdmin(TimeStampedEditableAdmin): pass -class AbstractNasAdmin(ModelAdmin): +class AbstractNasAdmin(TimeStampedEditableAdmin): pass -class AbstractRadiusUserGroupAdmin(ModelAdmin): +class AbstractRadiusUserGroupAdmin(TimeStampedEditableAdmin): pass -class AbstractRadiusGroupReplyAdmin(ModelAdmin): +class AbstractRadiusGroupReplyAdmin(TimeStampedEditableAdmin): pass -class AbstractRadiusGroupCheckAdmin(ModelAdmin): +class AbstractRadiusGroupCheckAdmin(TimeStampedEditableAdmin): pass -class AbstractRadiusPostAuthenticationAdmin(ModelAdmin): +class AbstractRadiusPostAuthenticationAdmin(TimeStampedEditableAdmin): pass diff --git a/django_freeradius/base/base.py b/django_freeradius/base/base.py index 8a7cede..a68531b 100644 --- a/django_freeradius/base/base.py +++ b/django_freeradius/base/base.py @@ -1,15 +1,15 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ -from model_utils.fields import AutoLastModifiedField +from model_utils.fields import AutoCreatedField, AutoLastModifiedField -class TimeStampedEditableAdmin(models.Model): - - # An abstract base class model that provides self-updating - # modified fields. - - id = models.UUIDField(primary_key=True, editable=False) +class TimeStampedEditableModel(models.Model): + """ + An abstract base class model that provides self-updating + ``created`` and ``modified`` fields. + """ + created = AutoCreatedField(_('created'), editable=True) modified = AutoLastModifiedField(_('modified'), editable=True) class Meta: diff --git a/django_freeradius/base/models.py b/django_freeradius/base/models.py index 935dbf6..b264465 100644 --- a/django_freeradius/base/models.py +++ b/django_freeradius/base/models.py @@ -27,6 +27,7 @@ class AbstractRadiusGroup(TimeStampedEditableAdmin): + id = models.UUIDField(primary_key=True, db_column='id') group_name = models.CharField( verbose_name=_('groupname'), max_length=255, unique=True, db_column='groupname', db_index=True) priority = models.IntegerField(verbose_name=_('priority'), default=1) @@ -47,6 +48,7 @@ def __str__(self): class AbstractRadiusGroupUsers(TimeStampedEditableAdmin): + id = models.UUIDField(primary_key=True, db_column='id') user_name = models.CharField( verbose_name=_('username'), max_length=64, unique=True, db_column='username') group_name = models.CharField( From d1aa9e396a66ba7869e7c43f9299c7676b99d2fa Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 17 Jun 2017 18:24:20 +0200 Subject: [PATCH 04/31] [admin] added get_readonly_fields method --- django_freeradius/base/admin.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/django_freeradius/base/admin.py b/django_freeradius/base/admin.py index 71c926b..0e86307 100644 --- a/django_freeradius/base/admin.py +++ b/django_freeradius/base/admin.py @@ -5,9 +5,10 @@ class TimeStampedEditableAdmin(ModelAdmin): """ ModelAdmin for TimeStampedEditableModel """ - def __init__(self, *args, **kwargs): - self.readonly_fields += ('created', 'modified',) - super(TimeStampedEditableAdmin, self).__init__(*args, **kwargs) + + def get_readonly_fields(self, request, obj=None): + readonly_fields = super(TimeStampedEditableAdmin, self).get_readonly_fields(request, obj) + return readonly_fields + ('created', 'modified') class AbstractRadiusGroupAdmin(TimeStampedEditableAdmin): From 8e34e856f7488f6300b2171b454e86d55bfcbd82 Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 17 Jun 2017 18:25:47 +0200 Subject: [PATCH 05/31] [models] delete base.py and added model --- django_freeradius/base/base.py | 16 --------------- django_freeradius/base/models.py | 35 +++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 28 deletions(-) delete mode 100644 django_freeradius/base/base.py diff --git a/django_freeradius/base/base.py b/django_freeradius/base/base.py deleted file mode 100644 index a68531b..0000000 --- a/django_freeradius/base/base.py +++ /dev/null @@ -1,16 +0,0 @@ -from django.db import models -from django.utils.translation import ugettext_lazy as _ - -from model_utils.fields import AutoCreatedField, AutoLastModifiedField - - -class TimeStampedEditableModel(models.Model): - """ - An abstract base class model that provides self-updating - ``created`` and ``modified`` fields. - """ - created = AutoCreatedField(_('created'), editable=True) - modified = AutoLastModifiedField(_('modified'), editable=True) - - class Meta: - abstract = True diff --git a/django_freeradius/base/models.py b/django_freeradius/base/models.py index b264465..3dc904d 100644 --- a/django_freeradius/base/models.py +++ b/django_freeradius/base/models.py @@ -1,7 +1,6 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ - -from .base import TimeStampedEditableAdmin +from model_utils.fields import AutoCreatedField, AutoLastModifiedField RADOP_CHECK_TYPES = ( ('=', '='), @@ -26,7 +25,19 @@ ) -class AbstractRadiusGroup(TimeStampedEditableAdmin): +class TimeStampedEditableModel(models.Model): + """ + An abstract base class model that provides self-updating + ``created`` and ``modified`` fields. + """ + created = AutoCreatedField(_('created'), editable=True) + modified = AutoLastModifiedField(_('modified'), editable=True) + + class Meta: + abstract = True + + +class AbstractRadiusGroup(TimeStampedEditableModel): id = models.UUIDField(primary_key=True, db_column='id') group_name = models.CharField( verbose_name=_('groupname'), max_length=255, unique=True, db_column='groupname', db_index=True) @@ -47,7 +58,7 @@ def __str__(self): return self.group_name -class AbstractRadiusGroupUsers(TimeStampedEditableAdmin): +class AbstractRadiusGroupUsers(TimeStampedEditableModel): id = models.UUIDField(primary_key=True, db_column='id') user_name = models.CharField( verbose_name=_('username'), max_length=64, unique=True, db_column='username') @@ -68,7 +79,7 @@ def __str__(self): return self.user_name -class AbstractRadiusReply(TimeStampedEditableAdmin): +class AbstractRadiusReply(TimeStampedEditableModel): user_name = models.CharField( verbose_name=_('username'), max_length=64, db_column='username', db_index=True) value = models.CharField(verbose_name=_('value'), max_length=253) @@ -86,7 +97,7 @@ def __str__(self): return self.user_name -class AbstractRadiusCheck(TimeStampedEditableAdmin): +class AbstractRadiusCheck(TimeStampedEditableModel): user_name = models.CharField( verbose_name=_('username'), max_length=64, db_column='username', db_index=True) value = models.CharField(verbose_name=_('radiusvalue'), max_length=253) @@ -105,7 +116,7 @@ def __str__(self): return self.user_name -class AbstractRadiusAccounting(TimeStampedEditableAdmin): +class AbstractRadiusAccounting(TimeStampedEditableModel): rad_acct_id = models.BigIntegerField(primary_key=True, db_column='radacctid') acct_session_id = models.CharField(max_length=64, db_column='acctsessionid', db_index=True) acct_unique_id = models.CharField(max_length=32, db_column='acctuniqueid', unique=True) @@ -161,7 +172,7 @@ def __str__(self): return self.acct_unique_id -class AbstractNas(TimeStampedEditableAdmin): +class AbstractNas(TimeStampedEditableModel): nas_name = models.CharField( verbose_name=_('nas name'), max_length=128, unique=True, help_text=_('NAS Name (or IP address)'), db_index=True, db_column='nasname') @@ -187,7 +198,7 @@ def __str__(self): return self.nas_name -class AbstractRadiusUserGroup(TimeStampedEditableAdmin): +class AbstractRadiusUserGroup(TimeStampedEditableModel): user_name = models.CharField( verbose_name=_('username'), max_length=64, db_column='username', db_index=True) group_name = models.CharField(verbose_name=_('groupname'), max_length=64, db_column='groupname') @@ -203,7 +214,7 @@ def __str__(self): return str(self.user_name) -class AbstractRadiusGroupReply(TimeStampedEditableAdmin): +class AbstractRadiusGroupReply(TimeStampedEditableModel): group_name = models.CharField( verbose_name=_('groupname'), max_length=64, db_column='groupname', db_index=True) attribute = models.CharField(verbose_name=_('attribute'), max_length=64) @@ -221,7 +232,7 @@ def __str__(self): return str(self.group_name) -class AbstractRadiusGroupCheck(TimeStampedEditableAdmin): +class AbstractRadiusGroupCheck(TimeStampedEditableModel): group_name = models.CharField( verbose_name=_('groupname'), max_length=64, db_column='groupname', db_index=True) attribute = models.CharField(verbose_name=_('attribute'), max_length=64) @@ -239,7 +250,7 @@ def __str__(self): return str(self.group_name) -class AbstractRadiusPostAuthentication(TimeStampedEditableAdmin): +class AbstractRadiusPostAuthentication(TimeStampedEditableModel): user_name = models.CharField(verbose_name=_('username'), max_length=64, db_column='username') password = models.CharField(verbose_name=_('password'), max_length=64, db_column='pass') reply = models.CharField(verbose_name=_('reply'), max_length=32) From e91c461b2940076dff001e7a742bfb966119cebc Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 17 Jun 2017 18:27:00 +0200 Subject: [PATCH 06/31] [requirements] added django-model-utils --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 2f8b58a..13861e2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ django>=1.10,<1.12 +django-model-utils From 9929df93fd247d0220c1b178e666ad30161bae1c Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 17 Jun 2017 18:27:59 +0200 Subject: [PATCH 07/31] [migrations] added new migrations --- .../migrations/0005_auto_20170617_1816.py | 232 ++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 django_freeradius/migrations/0005_auto_20170617_1816.py diff --git a/django_freeradius/migrations/0005_auto_20170617_1816.py b/django_freeradius/migrations/0005_auto_20170617_1816.py new file mode 100644 index 0000000..e34fabc --- /dev/null +++ b/django_freeradius/migrations/0005_auto_20170617_1816.py @@ -0,0 +1,232 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.1 on 2017-06-17 16:16 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone +import model_utils.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('django_freeradius', '0004_auto_20170614_1916'), + ] + + operations = [ + migrations.AddField( + model_name='nas', + name='created', + field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), + ), + migrations.AddField( + model_name='nas', + name='modified', + field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), + ), + migrations.AddField( + model_name='radiusaccounting', + name='created', + field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), + ), + migrations.AddField( + model_name='radiusaccounting', + name='modified', + field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), + ), + migrations.AddField( + model_name='radiuscheck', + name='created', + field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), + ), + migrations.AddField( + model_name='radiuscheck', + name='modified', + field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), + ), + migrations.AddField( + model_name='radiusgroup', + name='created', + field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), + ), + migrations.AddField( + model_name='radiusgroup', + name='modified', + field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), + ), + migrations.AddField( + model_name='radiusgroupcheck', + name='created', + field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), + ), + migrations.AddField( + model_name='radiusgroupcheck', + name='modified', + field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), + ), + migrations.AddField( + model_name='radiusgroupreply', + name='created', + field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), + ), + migrations.AddField( + model_name='radiusgroupreply', + name='modified', + field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), + ), + migrations.AddField( + model_name='radiusgroupusers', + name='created', + field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), + ), + migrations.AddField( + model_name='radiusgroupusers', + name='modified', + field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), + ), + migrations.AddField( + model_name='radiuspostauthentication', + name='created', + field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), + ), + migrations.AddField( + model_name='radiuspostauthentication', + name='modified', + field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), + ), + migrations.AddField( + model_name='radiusreply', + name='created', + field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), + ), + migrations.AddField( + model_name='radiusreply', + name='modified', + field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), + ), + migrations.AddField( + model_name='radiususergroup', + name='created', + field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), + ), + migrations.AddField( + model_name='radiususergroup', + name='modified', + field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), + ), + migrations.AlterField( + model_name='nas', + name='community', + field=models.CharField(blank=True, max_length=50, null=True, verbose_name='community'), + ), + migrations.AlterField( + model_name='nas', + name='description', + field=models.CharField(max_length=200, null=True, verbose_name='description'), + ), + migrations.AlterField( + model_name='nas', + name='ports', + field=models.IntegerField(blank=True, null=True, verbose_name='ports'), + ), + migrations.AlterField( + model_name='nas', + name='secret', + field=models.CharField(help_text='Shared Secret', max_length=60, verbose_name='secret'), + ), + migrations.AlterField( + model_name='nas', + name='server', + field=models.CharField(max_length=64, null=True, verbose_name='server'), + ), + migrations.AlterField( + model_name='nas', + name='type', + field=models.CharField(max_length=30, verbose_name='type'), + ), + migrations.AlterField( + model_name='radiusaccounting', + name='realm', + field=models.CharField(max_length=64, null=True, verbose_name='realm'), + ), + migrations.AlterField( + model_name='radiuscheck', + name='attribute', + field=models.CharField(max_length=64, verbose_name='attribute'), + ), + migrations.AlterField( + model_name='radiuscheck', + name='op', + field=models.CharField(choices=[('=', '='), (':=', ':='), ('==', '=='), ('+=', '+='), ('!=', '!='), ('>', '>'), ('>=', '>='), ('<', '<'), ('<=', '<='), ('=~', '=~'), ('!~', '!~'), ('=*', '=*'), ('!*', '!*')], default=':=', max_length=2, verbose_name='operator'), + ), + migrations.AlterField( + model_name='radiuscheck', + name='value', + field=models.CharField(max_length=253, verbose_name='radiusvalue'), + ), + migrations.AlterField( + model_name='radiusgroup', + name='notes', + field=models.CharField(blank=True, max_length=64, null=True, verbose_name='notes'), + ), + migrations.AlterField( + model_name='radiusgroup', + name='priority', + field=models.IntegerField(default=1, verbose_name='priority'), + ), + migrations.AlterField( + model_name='radiusgroupcheck', + name='attribute', + field=models.CharField(max_length=64, verbose_name='attribute'), + ), + migrations.AlterField( + model_name='radiusgroupcheck', + name='op', + field=models.CharField(choices=[('=', '='), (':=', ':='), ('==', '=='), ('+=', '+='), ('!=', '!='), ('>', '>'), ('>=', '>='), ('<', '<'), ('<=', '<='), ('=~', '=~'), ('!~', '!~'), ('=*', '=*'), ('!*', '!*')], default=':=', max_length=2, verbose_name='operator'), + ), + migrations.AlterField( + model_name='radiusgroupcheck', + name='value', + field=models.CharField(max_length=253, verbose_name='value'), + ), + migrations.AlterField( + model_name='radiusgroupreply', + name='attribute', + field=models.CharField(max_length=64, verbose_name='attribute'), + ), + migrations.AlterField( + model_name='radiusgroupreply', + name='op', + field=models.CharField(choices=[('=', '='), (':=', ':='), ('+=', '+=')], default='=', max_length=2, verbose_name='operator'), + ), + migrations.AlterField( + model_name='radiusgroupreply', + name='value', + field=models.CharField(max_length=253, verbose_name='value'), + ), + migrations.AlterField( + model_name='radiuspostauthentication', + name='reply', + field=models.CharField(max_length=32, verbose_name='reply'), + ), + migrations.AlterField( + model_name='radiusreply', + name='attribute', + field=models.CharField(max_length=64, verbose_name='attribute'), + ), + migrations.AlterField( + model_name='radiusreply', + name='op', + field=models.CharField(choices=[('=', '='), (':=', ':='), ('+=', '+=')], default='=', max_length=2, verbose_name='operator'), + ), + migrations.AlterField( + model_name='radiusreply', + name='value', + field=models.CharField(max_length=253, verbose_name='value'), + ), + migrations.AlterField( + model_name='radiususergroup', + name='priority', + field=models.IntegerField(default=1, verbose_name='priority'), + ), + ] From 62b5e4d57a2071fdd9eae55c9e05922943816dfb Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 17 Jun 2017 18:51:23 +0200 Subject: [PATCH 08/31] [migrations] added a new migrations --- django_freeradius/migrations/0005_auto_20170617_1816.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_freeradius/migrations/0005_auto_20170617_1816.py b/django_freeradius/migrations/0005_auto_20170617_1816.py index e34fabc..a0b1ee6 100644 --- a/django_freeradius/migrations/0005_auto_20170617_1816.py +++ b/django_freeradius/migrations/0005_auto_20170617_1816.py @@ -2,9 +2,9 @@ # Generated by Django 1.11.1 on 2017-06-17 16:16 from __future__ import unicode_literals -from django.db import migrations, models import django.utils.timezone import model_utils.fields +from django.db import migrations, models class Migration(migrations.Migration): From c5acf30eccadcd2732f2797d30c1cbbd856f1c2b Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 17 Jun 2017 19:04:31 +0200 Subject: [PATCH 09/31] [clean] clean models --- django_freeradius/base/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/django_freeradius/base/models.py b/django_freeradius/base/models.py index 3dc904d..e5c80dd 100644 --- a/django_freeradius/base/models.py +++ b/django_freeradius/base/models.py @@ -1,5 +1,6 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ + from model_utils.fields import AutoCreatedField, AutoLastModifiedField RADOP_CHECK_TYPES = ( From b73dd977cdca6bb16236e86f18620321e0b9e086 Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 17 Jun 2017 20:44:10 +0200 Subject: [PATCH 10/31] [general] added swapper --- django_freeradius/admin.py | 16 +++- .../migrations/0006_auto_20170617_2032.py | 95 +++++++++++++++++++ django_freeradius/models.py | 42 +++++--- requirements.txt | 1 + tests/settings.py | 13 +++ 5 files changed, 152 insertions(+), 15 deletions(-) create mode 100644 django_freeradius/migrations/0006_auto_20170617_2032.py diff --git a/django_freeradius/admin.py b/django_freeradius/admin.py index e718f80..0e1d5c5 100644 --- a/django_freeradius/admin.py +++ b/django_freeradius/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin - +import swapper from .base.admin import (AbstractNasAdmin, AbstractRadiusAccountingAdmin, AbstractRadiusCheckAdmin, AbstractRadiusGroupAdmin, AbstractRadiusGroupCheckAdmin, @@ -8,9 +8,17 @@ AbstractRadiusPostAuthenticationAdmin, AbstractRadiusReplyAdmin, AbstractRadiusUserGroupAdmin) -from .models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, - RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, - RadiusPostAuthentication, RadiusReply, RadiusUserGroup) + +RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") +RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") +RadiusGroupUsers = swapper.load_model("django_freeradius", "RadiusGroupUsers") +RadiusUserGroup = swapper.load_model("django_freeradius", "RadiusUserGroup") +RadiusReply = swapper.load_model("django_freeradius", "RadiusReply") +RadiusCheck = swapper.load_model("django_freeradius", "RadiusCheck") +RadiusPostAuthentication = swapper.load_model("django_freeradius", "RadiusPostAuthentication") +Nas = swapper.load_model("django_freeradius", "Nas") +RadiusAccounting = swapper.load_model("django_freeradius", "RadiusAccounting") +RadiusGroup = swapper.load_model("django_freeradius", "RadiusGroup") @admin.register(RadiusGroup) diff --git a/django_freeradius/migrations/0006_auto_20170617_2032.py b/django_freeradius/migrations/0006_auto_20170617_2032.py new file mode 100644 index 0000000..a9fc438 --- /dev/null +++ b/django_freeradius/migrations/0006_auto_20170617_2032.py @@ -0,0 +1,95 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.1 on 2017-06-17 18:32 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('django_freeradius', '0005_auto_20170617_1816'), + ] + + operations = [ + migrations.AlterModelOptions( + name='nas', + options={}, + ), + migrations.AlterModelOptions( + name='radiusaccounting', + options={}, + ), + migrations.AlterModelOptions( + name='radiuscheck', + options={}, + ), + migrations.AlterModelOptions( + name='radiusgroup', + options={}, + ), + migrations.AlterModelOptions( + name='radiusgroupcheck', + options={}, + ), + migrations.AlterModelOptions( + name='radiusgroupreply', + options={}, + ), + migrations.AlterModelOptions( + name='radiusgroupusers', + options={}, + ), + migrations.AlterModelOptions( + name='radiuspostauthentication', + options={}, + ), + migrations.AlterModelOptions( + name='radiusreply', + options={}, + ), + migrations.AlterModelOptions( + name='radiususergroup', + options={}, + ), + migrations.AlterModelTable( + name='nas', + table=None, + ), + migrations.AlterModelTable( + name='radiusaccounting', + table=None, + ), + migrations.AlterModelTable( + name='radiuscheck', + table=None, + ), + migrations.AlterModelTable( + name='radiusgroup', + table=None, + ), + migrations.AlterModelTable( + name='radiusgroupcheck', + table=None, + ), + migrations.AlterModelTable( + name='radiusgroupreply', + table=None, + ), + migrations.AlterModelTable( + name='radiusgroupusers', + table=None, + ), + migrations.AlterModelTable( + name='radiuspostauthentication', + table=None, + ), + migrations.AlterModelTable( + name='radiusreply', + table=None, + ), + migrations.AlterModelTable( + name='radiususergroup', + table=None, + ), + ] diff --git a/django_freeradius/models.py b/django_freeradius/models.py index ab9b37f..7f410f0 100644 --- a/django_freeradius/models.py +++ b/django_freeradius/models.py @@ -4,43 +4,63 @@ AbstractRadiusGroupUsers, AbstractRadiusPostAuthentication, AbstractRadiusReply, AbstractRadiusUserGroup) - +import swapper class RadiusGroup(AbstractRadiusGroup): - pass + + class Meta: + swappable = swapper.swappable_setting('reusableapp', 'RadiusGroup') class RadiusGroupUsers(AbstractRadiusGroupUsers): - pass + + class Meta: + swappable = swapper.swappable_setting('reusableapp', 'RadiusGroupUsers') class RadiusCheck(AbstractRadiusCheck): - pass + + class Meta: + swappable = swapper.swappable_setting('reusableapp', 'RadiusCheck') class RadiusAccounting(AbstractRadiusAccounting): - pass + + class Meta: + swappable = swapper.swappable_setting('reusableapp', 'RadiusAccounting') class RadiusReply(AbstractRadiusReply): - pass + + class Meta: + swappable = swapper.swappable_setting('reusableapp', 'RadiusReply') class Nas(AbstractNas): - pass + + class Meta: + swappable = swapper.swappable_setting('reusableapp', 'Nas') class RadiusGroupCheck(AbstractRadiusGroupCheck): - pass + + class Meta: + swappable = swapper.swappable_setting('reusableapp', 'RadiusGroupCheck') class RadiusGroupReply(AbstractRadiusGroupReply): - pass + + class Meta: + swappable = swapper.swappable_setting('reusableapp', 'RadiusGroupReply') class RadiusPostAuthentication(AbstractRadiusPostAuthentication): - pass + + class Meta: + swappable = swapper.swappable_setting('reusableapp', 'RadiusPostAuthentication') class RadiusUserGroup(AbstractRadiusUserGroup): - pass + + class Meta: + swappable = swapper.swappable_setting('reusableapp', 'RadiusUserGroup') diff --git a/requirements.txt b/requirements.txt index 13861e2..c74cd10 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ django>=1.10,<1.12 django-model-utils +swapper diff --git a/tests/settings.py b/tests/settings.py index cec0e6d..424dba2 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -2,6 +2,19 @@ import environ +import swapper + +DJANGO_FREERADIUS_RADIUSREPLY_MODEL = "django_freeradius.RadiusReply" +DJANGO_FREERADIUS_RADIUSCHECK_MODEL = "django_freeradius.RadiusCheck" +DJANGO_FREERADIUS_RADIUSUSERGROUP_MODEL = "django_freeradius.RadiusUserGroup" +DJANGO_FREERADIUS_RADIUSGROUP_MODEL = "django_freeradius.RadiusGroup" +DJANGO_FREERADIUS_RADIUSACCOUNTING_MODEL = "django_freeradius.RadiusAccounting" +DJANGO_FREERADIUS_RADIUSPOSTAUTHENTICATION_MODEL = "django_freeradius.RadiusPostAuthentication" +DJANGO_FREERADIUS_RADIUSGROUPREPLY_MODEL = "django_freeradius.RadiusGroupReply" +DJANGO_FREERADIUS_RADIUSGROUPCHECK_MODEL = "django_freeradius.RadiusGroupCheck" +DJANGO_FREERADIUS_RADIUSGROUPUSER_MODEL = "django_freeradius.RadiusGroupUser" +DJANGO_FREERADIUS_NAS_MODEL = "django_freeradius.RadiusReply" + BASE_DIR = os.path.dirname(os.path.abspath(__file__)) root = environ.Path(__file__) - 2 From c6c4f16d11633accfdae820770036889c5e4e658 Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 17 Jun 2017 21:02:43 +0200 Subject: [PATCH 11/31] swapper --- django_freeradius/models.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/django_freeradius/models.py b/django_freeradius/models.py index 7f410f0..d9b3879 100644 --- a/django_freeradius/models.py +++ b/django_freeradius/models.py @@ -9,58 +9,58 @@ class RadiusGroup(AbstractRadiusGroup): class Meta: - swappable = swapper.swappable_setting('reusableapp', 'RadiusGroup') + swappable = swapper.swappable_setting('django_freeradius', 'RadiusGroup') class RadiusGroupUsers(AbstractRadiusGroupUsers): class Meta: - swappable = swapper.swappable_setting('reusableapp', 'RadiusGroupUsers') + swappable = swapper.swappable_setting('django_freeradius', 'RadiusGroupUsers') class RadiusCheck(AbstractRadiusCheck): class Meta: - swappable = swapper.swappable_setting('reusableapp', 'RadiusCheck') + swappable = swapper.swappable_setting('django_freeradius', 'RadiusCheck') class RadiusAccounting(AbstractRadiusAccounting): class Meta: - swappable = swapper.swappable_setting('reusableapp', 'RadiusAccounting') + swappable = swapper.swappable_setting('django_freeradius', 'RadiusAccounting') class RadiusReply(AbstractRadiusReply): class Meta: - swappable = swapper.swappable_setting('reusableapp', 'RadiusReply') + swappable = swapper.swappable_setting('django_freeradius', 'RadiusReply') class Nas(AbstractNas): class Meta: - swappable = swapper.swappable_setting('reusableapp', 'Nas') + swappable = swapper.swappable_setting('django_freeradius', 'Nas') class RadiusGroupCheck(AbstractRadiusGroupCheck): class Meta: - swappable = swapper.swappable_setting('reusableapp', 'RadiusGroupCheck') + swappable = swapper.swappable_setting('django_freeradius', 'RadiusGroupCheck') class RadiusGroupReply(AbstractRadiusGroupReply): class Meta: - swappable = swapper.swappable_setting('reusableapp', 'RadiusGroupReply') + swappable = swapper.swappable_setting('django_freeradius', 'RadiusGroupReply') class RadiusPostAuthentication(AbstractRadiusPostAuthentication): class Meta: - swappable = swapper.swappable_setting('reusableapp', 'RadiusPostAuthentication') + swappable = swapper.swappable_setting('django_freeradius', 'RadiusPostAuthentication') class RadiusUserGroup(AbstractRadiusUserGroup): class Meta: - swappable = swapper.swappable_setting('reusableapp', 'RadiusUserGroup') + swappable = swapper.swappable_setting('django_freeradius', 'RadiusUserGroup') From bd2319bbc24407d8317f1b1f76121db7a0828435 Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 17 Jun 2017 22:02:39 +0200 Subject: [PATCH 12/31] [general] clean code --- django_freeradius/admin.py | 5 +- django_freeradius/base/models.py | 1 - .../migrations/0007_auto_20170617_2140.py | 95 +++++++++++++++++++ django_freeradius/models.py | 54 +++++++---- tests/settings.py | 13 --- 5 files changed, 131 insertions(+), 37 deletions(-) create mode 100644 django_freeradius/migrations/0007_auto_20170617_2140.py diff --git a/django_freeradius/admin.py b/django_freeradius/admin.py index 0e1d5c5..63f268c 100644 --- a/django_freeradius/admin.py +++ b/django_freeradius/admin.py @@ -1,5 +1,6 @@ -from django.contrib import admin import swapper +from django.contrib import admin + from .base.admin import (AbstractNasAdmin, AbstractRadiusAccountingAdmin, AbstractRadiusCheckAdmin, AbstractRadiusGroupAdmin, AbstractRadiusGroupCheckAdmin, @@ -16,7 +17,7 @@ RadiusReply = swapper.load_model("django_freeradius", "RadiusReply") RadiusCheck = swapper.load_model("django_freeradius", "RadiusCheck") RadiusPostAuthentication = swapper.load_model("django_freeradius", "RadiusPostAuthentication") -Nas = swapper.load_model("django_freeradius", "Nas") +Nas = swapper.load_model("django_freeradius", "Nas") RadiusAccounting = swapper.load_model("django_freeradius", "RadiusAccounting") RadiusGroup = swapper.load_model("django_freeradius", "RadiusGroup") diff --git a/django_freeradius/base/models.py b/django_freeradius/base/models.py index e5c80dd..3dc904d 100644 --- a/django_freeradius/base/models.py +++ b/django_freeradius/base/models.py @@ -1,6 +1,5 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ - from model_utils.fields import AutoCreatedField, AutoLastModifiedField RADOP_CHECK_TYPES = ( diff --git a/django_freeradius/migrations/0007_auto_20170617_2140.py b/django_freeradius/migrations/0007_auto_20170617_2140.py new file mode 100644 index 0000000..e704669 --- /dev/null +++ b/django_freeradius/migrations/0007_auto_20170617_2140.py @@ -0,0 +1,95 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.1 on 2017-06-17 19:40 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('django_freeradius', '0006_auto_20170617_2032'), + ] + + operations = [ + migrations.AlterModelOptions( + name='nas', + options={'verbose_name': 'nas', 'verbose_name_plural': 'nas'}, + ), + migrations.AlterModelOptions( + name='radiusaccounting', + options={'verbose_name': 'accounting', 'verbose_name_plural': 'accounting'}, + ), + migrations.AlterModelOptions( + name='radiuscheck', + options={'verbose_name': 'radiuscheck', 'verbose_name_plural': 'radiuschecks'}, + ), + migrations.AlterModelOptions( + name='radiusgroup', + options={'verbose_name': 'radiusgroup', 'verbose_name_plural': 'radiusgroups'}, + ), + migrations.AlterModelOptions( + name='radiusgroupcheck', + options={'verbose_name': 'radiusgroupcheck', 'verbose_name_plural': 'radiusgroupcheck'}, + ), + migrations.AlterModelOptions( + name='radiusgroupreply', + options={'verbose_name': 'radiusgroupreply', 'verbose_name_plural': 'radiusgroupreplies'}, + ), + migrations.AlterModelOptions( + name='radiusgroupusers', + options={'verbose_name': 'radiusgroupusers', 'verbose_name_plural': 'radiusgroupusers'}, + ), + migrations.AlterModelOptions( + name='radiuspostauthentication', + options={'verbose_name': 'radiuspostauthentication', 'verbose_name_plural': 'radiuspostauthentication'}, + ), + migrations.AlterModelOptions( + name='radiusreply', + options={'verbose_name': 'radiusreply', 'verbose_name_plural': 'radiusreplies'}, + ), + migrations.AlterModelOptions( + name='radiususergroup', + options={'verbose_name': 'radiususergroup', 'verbose_name_plural': 'radiususergroup'}, + ), + migrations.AlterModelTable( + name='nas', + table='nas', + ), + migrations.AlterModelTable( + name='radiusaccounting', + table='radacct', + ), + migrations.AlterModelTable( + name='radiuscheck', + table='radcheck', + ), + migrations.AlterModelTable( + name='radiusgroup', + table='radiusgroup', + ), + migrations.AlterModelTable( + name='radiusgroupcheck', + table='radgroupcheck', + ), + migrations.AlterModelTable( + name='radiusgroupreply', + table='radgroupreply', + ), + migrations.AlterModelTable( + name='radiusgroupusers', + table='radiusgroupusers', + ), + migrations.AlterModelTable( + name='radiuspostauthentication', + table='radpostauth', + ), + migrations.AlterModelTable( + name='radiusreply', + table='radreply', + ), + migrations.AlterModelTable( + name='radiususergroup', + table='radusergroup', + ), + ] diff --git a/django_freeradius/models.py b/django_freeradius/models.py index d9b3879..ce54b5f 100644 --- a/django_freeradius/models.py +++ b/django_freeradius/models.py @@ -1,66 +1,78 @@ +import swapper + from .base.models import (AbstractNas, AbstractRadiusAccounting, AbstractRadiusCheck, AbstractRadiusGroup, AbstractRadiusGroupCheck, AbstractRadiusGroupReply, AbstractRadiusGroupUsers, AbstractRadiusPostAuthentication, AbstractRadiusReply, AbstractRadiusUserGroup) -import swapper + class RadiusGroup(AbstractRadiusGroup): - class Meta: - swappable = swapper.swappable_setting('django_freeradius', 'RadiusGroup') + class Meta(AbstractRadiusGroup.Meta): + abstract = False + swappable = swapper.swappable_setting('django_freeradius', 'RadiusGroup') class RadiusGroupUsers(AbstractRadiusGroupUsers): - class Meta: - swappable = swapper.swappable_setting('django_freeradius', 'RadiusGroupUsers') + class Meta(AbstractRadiusGroupUsers.Meta): + abstract = False + swappable = swapper.swappable_setting('django_freeradius', 'RadiusGroupUsers') class RadiusCheck(AbstractRadiusCheck): - class Meta: - swappable = swapper.swappable_setting('django_freeradius', 'RadiusCheck') + class Meta(AbstractRadiusCheck.Meta): + abstract = False + swappable = swapper.swappable_setting('django_freeradius', 'RadiusCheck') class RadiusAccounting(AbstractRadiusAccounting): - class Meta: - swappable = swapper.swappable_setting('django_freeradius', 'RadiusAccounting') + class Meta(AbstractRadiusAccounting.Meta): + abstract = False + swappable = swapper.swappable_setting('django_freeradius', 'RadiusAccounting') class RadiusReply(AbstractRadiusReply): - class Meta: - swappable = swapper.swappable_setting('django_freeradius', 'RadiusReply') + class Meta(AbstractRadiusReply.Meta): + abstract = False + swappable = swapper.swappable_setting('django_freeradius', 'RadiusReply') class Nas(AbstractNas): - class Meta: - swappable = swapper.swappable_setting('django_freeradius', 'Nas') + class Meta(AbstractNas.Meta): + abstract = False + swappable = swapper.swappable_setting('django_freeradius', 'Nas') class RadiusGroupCheck(AbstractRadiusGroupCheck): - class Meta: - swappable = swapper.swappable_setting('django_freeradius', 'RadiusGroupCheck') + class Meta(AbstractRadiusGroupCheck.Meta): + abstract = False + swappable = swapper.swappable_setting('django_freeradius', 'RadiusGroupCheck') class RadiusGroupReply(AbstractRadiusGroupReply): - class Meta: - swappable = swapper.swappable_setting('django_freeradius', 'RadiusGroupReply') + class Meta(AbstractRadiusGroupReply.Meta): + abstract = False + swappable = swapper.swappable_setting('django_freeradius', 'RadiusGroupReply') class RadiusPostAuthentication(AbstractRadiusPostAuthentication): - class Meta: - swappable = swapper.swappable_setting('django_freeradius', 'RadiusPostAuthentication') + class Meta(AbstractRadiusPostAuthentication.Meta): + abstract = False + swappable = swapper.swappable_setting('django_freeradius', 'RadiusPostAuthentication') class RadiusUserGroup(AbstractRadiusUserGroup): - class Meta: - swappable = swapper.swappable_setting('django_freeradius', 'RadiusUserGroup') + class Meta(AbstractRadiusUserGroup.Meta): + abstract = False + swappable = swapper.swappable_setting('django_freeradius', 'RadiusUserGroup') diff --git a/tests/settings.py b/tests/settings.py index 424dba2..cec0e6d 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -2,19 +2,6 @@ import environ -import swapper - -DJANGO_FREERADIUS_RADIUSREPLY_MODEL = "django_freeradius.RadiusReply" -DJANGO_FREERADIUS_RADIUSCHECK_MODEL = "django_freeradius.RadiusCheck" -DJANGO_FREERADIUS_RADIUSUSERGROUP_MODEL = "django_freeradius.RadiusUserGroup" -DJANGO_FREERADIUS_RADIUSGROUP_MODEL = "django_freeradius.RadiusGroup" -DJANGO_FREERADIUS_RADIUSACCOUNTING_MODEL = "django_freeradius.RadiusAccounting" -DJANGO_FREERADIUS_RADIUSPOSTAUTHENTICATION_MODEL = "django_freeradius.RadiusPostAuthentication" -DJANGO_FREERADIUS_RADIUSGROUPREPLY_MODEL = "django_freeradius.RadiusGroupReply" -DJANGO_FREERADIUS_RADIUSGROUPCHECK_MODEL = "django_freeradius.RadiusGroupCheck" -DJANGO_FREERADIUS_RADIUSGROUPUSER_MODEL = "django_freeradius.RadiusGroupUser" -DJANGO_FREERADIUS_NAS_MODEL = "django_freeradius.RadiusReply" - BASE_DIR = os.path.dirname(os.path.abspath(__file__)) root = environ.Path(__file__) - 2 From 2fe3bd8232006a498859281c4cff8b2647a36cd5 Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Tue, 20 Jun 2017 17:05:47 +0200 Subject: [PATCH 13/31] [sample_radius] added application test --- tests/sample_radius/__init__.py | 0 tests/sample_radius/admin.py | 14 ++ tests/sample_radius/apps.py | 5 + .../sample_radius/migrations/0001_initial.py | 214 ++++++++++++++++++ tests/sample_radius/migrations/__init__.py | 0 tests/sample_radius/models.py | 54 +++++ tests/sample_radius/tests.py | 185 +++++++++++++++ tests/settings.py | 24 +- 8 files changed, 493 insertions(+), 3 deletions(-) create mode 100644 tests/sample_radius/__init__.py create mode 100644 tests/sample_radius/admin.py create mode 100644 tests/sample_radius/apps.py create mode 100644 tests/sample_radius/migrations/0001_initial.py create mode 100644 tests/sample_radius/migrations/__init__.py create mode 100644 tests/sample_radius/models.py create mode 100644 tests/sample_radius/tests.py diff --git a/tests/sample_radius/__init__.py b/tests/sample_radius/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/sample_radius/admin.py b/tests/sample_radius/admin.py new file mode 100644 index 0000000..cc8b141 --- /dev/null +++ b/tests/sample_radius/admin.py @@ -0,0 +1,14 @@ +from django.contrib import admin + +from django_freeradius.admin import (AbstractNasAdmin, AbstractRadiusAccountingAdmin, + AbstractRadiusCheckAdmin, AbstractRadiusGroupAdmin, + AbstractRadiusGroupCheckAdmin, + AbstractRadiusGroupReplyAdmin, + AbstractRadiusGroupUsersAdmin, + AbstractRadiusPostAuthenticationAdmin, + AbstractRadiusReplyAdmin, + AbstractRadiusUserGroupAdmin) + +from django_freeradius.models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, + RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, + RadiusPostAuthentication, RadiusReply, RadiusUserGroup) diff --git a/tests/sample_radius/apps.py b/tests/sample_radius/apps.py new file mode 100644 index 0000000..8f0eab4 --- /dev/null +++ b/tests/sample_radius/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class SampleRadiusConfig(AppConfig): + name = 'sample_radius' diff --git a/tests/sample_radius/migrations/0001_initial.py b/tests/sample_radius/migrations/0001_initial.py new file mode 100644 index 0000000..29974ef --- /dev/null +++ b/tests/sample_radius/migrations/0001_initial.py @@ -0,0 +1,214 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.1 on 2017-06-20 13:55 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone +import model_utils.fields + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Nas', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('nas_name', models.CharField(db_column='nasname', db_index=True, help_text='NAS Name (or IP address)', max_length=128, unique=True, verbose_name='nas name')), + ('short_name', models.CharField(db_column='shortname', max_length=32, verbose_name='short name')), + ('type', models.CharField(max_length=30, verbose_name='type')), + ('secret', models.CharField(help_text='Shared Secret', max_length=60, verbose_name='secret')), + ('ports', models.IntegerField(blank=True, null=True, verbose_name='ports')), + ('community', models.CharField(blank=True, max_length=50, null=True, verbose_name='community')), + ('description', models.CharField(max_length=200, null=True, verbose_name='description')), + ('server', models.CharField(max_length=64, null=True, verbose_name='server')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ], + options={ + 'abstract': False, + 'verbose_name_plural': 'nas', + 'verbose_name': 'nas', + 'db_table': 'nas', + }, + ), + migrations.CreateModel( + name='RadiusAccounting', + fields=[ + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('rad_acct_id', models.BigIntegerField(db_column='radacctid', primary_key=True, serialize=False)), + ('acct_session_id', models.CharField(db_column='acctsessionid', db_index=True, max_length=64)), + ('acct_unique_id', models.CharField(db_column='acctuniqueid', max_length=32, unique=True)), + ('user_name', models.CharField(db_column='username', db_index=True, max_length=64, verbose_name='username')), + ('group_name', models.CharField(db_column='groupname', max_length=64, verbose_name='groupname')), + ('realm', models.CharField(max_length=64, null=True, verbose_name='realm')), + ('nas_ip_address', models.CharField(db_column='nasipaddress', db_index=True, max_length=15)), + ('nas_port_id', models.CharField(db_column='nasportid', max_length=15, null=True)), + ('nas_port_type', models.CharField(db_column='nasporttype', max_length=32, verbose_name='nas port type')), + ('acct_start_time', models.DateTimeField(db_column='acctstarttime', db_index=True, verbose_name='acct start time')), + ('acct_stop_time', models.DateTimeField(db_column='acctstoptime', db_index=True, null=True, verbose_name='acct stop time')), + ('acct_session_time', models.IntegerField(db_column='acctsessiontime', db_index=True, null=True, verbose_name='acct session time')), + ('acct_authentic', models.CharField(db_column='acctauthentic', max_length=32, null=True, verbose_name='acct authentic')), + ('connection_info_start', models.CharField(db_column='connectinfo_start', max_length=50, null=True, verbose_name='connection info start')), + ('connection_info_stop', models.CharField(db_column='connectinfo_stop', max_length=50, null=True, verbose_name='connection info stop')), + ('acct_input_octets', models.BigIntegerField(db_column='acctinputoctets', null=True, verbose_name='acct input octets')), + ('acct_output_octets', models.BigIntegerField(db_column='acctoutputoctets', null=True, verbose_name='acct output octets')), + ('callingStationId', models.CharField(db_column='calledstationid', max_length=50)), + ('calledStationId', models.CharField(db_column='callingstationid', max_length=50)), + ('acct_terminate_cause', models.CharField(db_column='acctterminatecause', max_length=32, verbose_name='acct terminate cause')), + ('service_type', models.CharField(db_column='servicetype', max_length=32, null=True, verbose_name='service type')), + ('framed_protocol', models.CharField(db_column='framedprotocol', max_length=32, null=True, verbose_name='framed protocol')), + ('framed_ip_address', models.CharField(db_column='framedipaddress', db_index=True, max_length=15)), + ('acct_start_delay', models.IntegerField(db_column='acctstartdelay', null=True, verbose_name='acct start delay')), + ('acct_stop_delay', models.IntegerField(db_column='acctstopdelay', null=True, verbose_name='acct stop delay')), + ('xascend_session_svrkey', models.CharField(db_column='xascendsessionsvrkey', max_length=10, null=True, verbose_name='xascend session svrkey')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ], + options={ + 'abstract': False, + 'verbose_name_plural': 'accounting', + 'verbose_name': 'accounting', + 'db_table': 'radacct', + }, + ), + migrations.CreateModel( + name='RadiusCheck', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('user_name', models.CharField(db_column='username', db_index=True, max_length=64, verbose_name='username')), + ('value', models.CharField(max_length=253, verbose_name='radiusvalue')), + ('op', models.CharField(choices=[('=', '='), (':=', ':='), ('==', '=='), ('+=', '+='), ('!=', '!='), ('>', '>'), ('>=', '>='), ('<', '<'), ('<=', '<='), ('=~', '=~'), ('!~', '!~'), ('=*', '=*'), ('!*', '!*')], default=':=', max_length=2, verbose_name='operator')), + ('attribute', models.CharField(max_length=64, verbose_name='attribute')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ], + options={ + 'abstract': False, + 'verbose_name_plural': 'radiuschecks', + 'verbose_name': 'radiuscheck', + 'db_table': 'radcheck', + }, + ), + migrations.CreateModel( + name='RadiusGroup', + fields=[ + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('id', models.UUIDField(db_column='id', primary_key=True, serialize=False)), + ('group_name', models.CharField(db_column='groupname', db_index=True, max_length=255, unique=True, verbose_name='groupname')), + ('priority', models.IntegerField(default=1, verbose_name='priority')), + ('creation_date', models.DateField(db_column='created_at', null=True, verbose_name='creation date')), + ('modification_date', models.DateField(db_column='updated_at', null=True, verbose_name='modification date')), + ('notes', models.CharField(blank=True, max_length=64, null=True, verbose_name='notes')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ], + options={ + 'abstract': False, + 'verbose_name_plural': 'radiusgroups', + 'verbose_name': 'radiusgroup', + 'db_table': 'radiusgroup', + }, + ), + migrations.CreateModel( + name='RadiusGroupCheck', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('group_name', models.CharField(db_column='groupname', db_index=True, max_length=64, verbose_name='groupname')), + ('attribute', models.CharField(max_length=64, verbose_name='attribute')), + ('op', models.CharField(choices=[('=', '='), (':=', ':='), ('==', '=='), ('+=', '+='), ('!=', '!='), ('>', '>'), ('>=', '>='), ('<', '<'), ('<=', '<='), ('=~', '=~'), ('!~', '!~'), ('=*', '=*'), ('!*', '!*')], default=':=', max_length=2, verbose_name='operator')), + ('value', models.CharField(max_length=253, verbose_name='value')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ], + options={ + 'abstract': False, + 'verbose_name_plural': 'radiusgroupcheck', + 'verbose_name': 'radiusgroupcheck', + 'db_table': 'radgroupcheck', + }, + ), + migrations.CreateModel( + name='RadiusGroupReply', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('group_name', models.CharField(db_column='groupname', db_index=True, max_length=64, verbose_name='groupname')), + ('attribute', models.CharField(max_length=64, verbose_name='attribute')), + ('op', models.CharField(choices=[('=', '='), (':=', ':='), ('+=', '+=')], default='=', max_length=2, verbose_name='operator')), + ('value', models.CharField(max_length=253, verbose_name='value')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ], + options={ + 'abstract': False, + 'verbose_name_plural': 'radiusgroupreplies', + 'verbose_name': 'radiusgroupreply', + 'db_table': 'radgroupreply', + }, + ), + migrations.CreateModel( + name='RadiusPostAuthentication', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('user_name', models.CharField(db_column='username', max_length=64, verbose_name='username')), + ('password', models.CharField(db_column='pass', max_length=64, verbose_name='password')), + ('reply', models.CharField(max_length=32, verbose_name='reply')), + ('auth_date', models.DateTimeField(auto_now=True, db_column='authdate', verbose_name='authdate')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ], + options={ + 'abstract': False, + 'verbose_name_plural': 'radiuspostauthentication', + 'verbose_name': 'radiuspostauthentication', + 'db_table': 'radpostauth', + }, + ), + migrations.CreateModel( + name='RadiusReply', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('user_name', models.CharField(db_column='username', db_index=True, max_length=64, verbose_name='username')), + ('value', models.CharField(max_length=253, verbose_name='value')), + ('op', models.CharField(choices=[('=', '='), (':=', ':='), ('+=', '+=')], default='=', max_length=2, verbose_name='operator')), + ('attribute', models.CharField(max_length=64, verbose_name='attribute')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ], + options={ + 'abstract': False, + 'verbose_name_plural': 'radiusreplies', + 'verbose_name': 'radiusreply', + 'db_table': 'radreply', + }, + ), + migrations.CreateModel( + name='RadiusUserGroup', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('user_name', models.CharField(db_column='username', db_index=True, max_length=64, verbose_name='username')), + ('group_name', models.CharField(db_column='groupname', max_length=64, verbose_name='groupname')), + ('priority', models.IntegerField(default=1, verbose_name='priority')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ], + options={ + 'abstract': False, + 'verbose_name_plural': 'radiususergroup', + 'verbose_name': 'radiususergroup', + 'db_table': 'radusergroup', + }, + ), + ] diff --git a/tests/sample_radius/migrations/__init__.py b/tests/sample_radius/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/sample_radius/models.py b/tests/sample_radius/models.py new file mode 100644 index 0000000..6491b98 --- /dev/null +++ b/tests/sample_radius/models.py @@ -0,0 +1,54 @@ +from django.db import models +from django.utils.translation import ugettext_lazy as _ + +from django_freeradius.models import (AbstractNas, AbstractRadiusAccounting, + AbstractRadiusCheck, AbstractRadiusGroup, + AbstractRadiusGroupCheck, AbstractRadiusGroupReply, + AbstractRadiusGroupUsers, + AbstractRadiusPostAuthentication, + AbstractRadiusReply, AbstractRadiusUserGroup) + + +class RadiusGroup(AbstractRadiusGroup): + details = models.CharField( + verbose_name=_('details'), max_length=64, blank=True, null=True) + + +class RadiusCheck(AbstractRadiusCheck): + details = models.CharField( + verbose_name=_('details'), max_length=64, blank=True, null=True) + + +class RadiusAccounting(AbstractRadiusAccounting): + details = models.CharField( + verbose_name=_('details'), max_length=64, blank=True, null=True) + + +class RadiusReply(AbstractRadiusReply): + details = models.CharField( + verbose_name=_('details'), max_length=64, blank=True, null=True) + + +class RadiusGroupCheck(AbstractRadiusGroupCheck): + details = models.CharField( + verbose_name=_('details'), max_length=64, blank=True, null=True) + + +class RadiusGroupReply(AbstractRadiusGroupReply): + details = models.CharField( + verbose_name=_('details'), max_length=64, blank=True, null=True) + + +class RadiusPostAuthentication(AbstractRadiusPostAuthentication): + details = models.CharField( + verbose_name=_('details'), max_length=64, blank=True, null=True) + + +class RadiusUserGroup(AbstractRadiusUserGroup): + details = models.CharField( + verbose_name=_('details'), max_length=64, blank=True, null=True) + + +class RadiusNas(AbstractNas): + details = models.CharField( + verbose_name=_('details'), max_length=64, blank=True, null=True) diff --git a/tests/sample_radius/tests.py b/tests/sample_radius/tests.py new file mode 100644 index 0000000..10c11d6 --- /dev/null +++ b/tests/sample_radius/tests.py @@ -0,0 +1,185 @@ +from django.test import TestCase +from django.contrib.auth.models import User +from django.test import Client +from django.urls import reverse + +from ..models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, + RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, + RadiusPostAuthentication, RadiusReply, RadiusUserGroup) + + +class NasModelTest(TestCase): + + def test_string_representation(self): + nas = Nas(nas_name='entry nasname') + self.assertEqual(str(nas), nas.nas_name) + + +class RadiusAccountingModelTest(TestCase): + + def test_string_representation(self): + radiusaccounting = RadiusAccounting(acct_unique_id='entry acctuniqueid') + self.assertEqual(str(radiusaccounting), radiusaccounting.acct_unique_id) + + +class RadiusCheckModelTest(TestCase): + + def test_string_representation(self): + radiuscheck = RadiusCheck(user_name='entry username') + self.assertEqual(str(radiuscheck), radiuscheck.user_name) + + +class RadiusReplyModelTest(TestCase): + + def test_string_representation(self): + radiusreply = RadiusReply(user_name='entry username') + self.assertEqual(str(radiusreply), radiusreply.user_name) + + +class RadiusGroupReplyModelTest(TestCase): + + def test_string_representation(self): + radiusgroupreply = RadiusGroupReply(group_name='entry groupname') + self.assertEqual(str(radiusgroupreply), radiusgroupreply.group_name) + + +class RadiusGroupCheckModelTest(TestCase): + + def test_string_representation(self): + radiusgroupcheck = RadiusGroupCheck(group_name='entry groupname') + self.assertEqual(str(radiusgroupcheck), radiusgroupcheck.group_name) + + +class RadiusUserGroupModelTest(TestCase): + + def test_string_representation(self): + radiususergroup = RadiusUserGroup(user_name='entry username') + self.assertEqual(str(radiususergroup), radiususergroup.user_name) + + +class RadiusPostAuthenticationModelTest(TestCase): + + def test_string_representation(self): + radiuspostauthentication = RadiusPostAuthentication(user_name='entry username') + self.assertEqual(str(radiuspostauthentication), radiuspostauthentication.user_name) + + +class RadiusGroupModelTest(TestCase): + + def test_string_representation(self): + radiusgroup = RadiusGroup(group_name='entry groupname') + self.assertEqual(str(radiusgroup), radiusgroup.group_name) + + +class RadiusGroupUsersModelTest(TestCase): + + def test_string_representation(self): + radiusgroupusers = RadiusGroupUsers(user_name='entry groupname') + self.assertEqual(str(radiusgroupusers), radiusgroupusers.user_name) + + +class UserTest(TestCase): + + def setUp(self): + self.client = Client() + + def test_users_not_login(self): + resp = self.client.get('/admin/auth/') + self.assertEqual(resp.status_code, 302) + + def test_users(self): + self.client.login(username='gino', password='ciao') + resp = self.client.get('/admin/login/?next=/admin/') + self.assertEqual(resp.status_code, 200) + + def test_users_nas(self): + User.objects.create_superuser(username='gino', password='cc', email='giggi_vv@gmail.it') + obj = Nas.objects.create( + nas_name='fiore', short_name='ff', type='cisco', secret='d', ports='22', community='vmv', + description='ciao', server='jsjs', details='nb') + self.client.login(username='gino', password='cc') + resp = self.client.get(reverse('admin:django_freeradius_nas_change', args=[obj.pk])) + self.assertContains(resp, 'ok') + + def test_users_check(self): + User.objects.create_superuser(username='gino', password='cic', email='giggi_vv@gmail.it') + obj = RadiusCheck.objects.create( + user_name='bob', attribute='Cleartext-Password', op=':=', value='passbob', details='nb') + self.client.login(username='gino', password='cic') + resp = self.client.get(reverse('admin:django_freeradius_radiuscheck_change', args=[obj.pk])) + self.assertContains(resp, 'ok') + + def test_users_reply(self): + User.objects.create_superuser(username='gino', password='cic', email='giggi_vv@gmail.it') + obj = RadiusReply.objects.create( + user_name='bob', attribute='Cleartext-Password', op=':=', value='passbob', details='nb') + self.client.login(username='gino', password='cic') + resp = self.client.get(reverse('admin:django_freeradius_radiusreply_change', args=[obj.pk])) + self.assertContains(resp, 'ok') + + def test_users_group_reply(self): + User.objects.create_superuser(username='gino', password='cic', email='giggi_vv@gmail.it') + obj = RadiusGroupReply.objects.create( + group_name='students', attribute='Cleartext-Password', op=':=', value='PPP', details='nb') + self.client.login(username='gino', password='cic') + resp = self.client.get(reverse('admin:django_freeradius_radiusgroupreply_change', args=[obj.pk])) + self.assertContains(resp, 'ok') + + def test_users_group_check(self): + User.objects.create_superuser(username='fiorella', password='ciao', email='giggi_fiore@gmail.it') + obj = RadiusGroupCheck.objects.create( + group_name='students', attribute='Cleartext-Password', op=':=', value='PPP', details='nb') + self.client.login(username='fiorella', password='ciao') + resp = self.client.get(reverse('admin:django_freeradius_radiusgroupcheck_change', args=[obj.pk])) + self.assertContains(resp, 'ok') + + def test_users_group(self): + User.objects.create_superuser(username='gino', password='cic', email='giggi_vv@gmail.it') + obj = RadiusGroup.objects.create( + id='870df8e8-3107-4487-8316-81e089b8c2cf', group_name='students', priority='1', + creation_date='2017-09-02', modification_date='2017-08-03', notes='hh', details='nb') + self.client.login(username='gino', password='cic') + resp = self.client.get(reverse('admin:django_freeradius_radiusgroup_change', args=[obj.pk])) + self.assertContains(resp, 'ok') + + def test_users_usersgroup(self): + User.objects.create_superuser(username='gino', password='cic', email='giggi_vv@gmail.it') + obj = RadiusUserGroup.objects.create( + user_name='bob', group_name='students', priority='1', details='nb') + self.client.login(username='gino', password='cic') + resp = self.client.get(reverse('admin:django_freeradius_radiususergroup_change', args=[obj.pk])) + self.assertContains(resp, 'ok') + + def test_users_groupusers(self): + User.objects.create_superuser(username='gino', password='cic', email='giggi_vv@gmail.it') + reply = RadiusReply.objects.create( + user_name='bob', attribute='Cleartext-Password', op=':=', value='passbob') + check = RadiusCheck.objects.create( + user_name='bob', attribute='Cleartext-Password', op=':=', value='passbob') + obj = RadiusGroupUsers.objects.create( + id='870df8e8-3107-4487-8316-81e089b8c2cf', user_name='bob', group_name='students') + obj.radius_reply.add(reply) + obj.radius_check.add(check) + self.client.login(username='gino', password='cic') + resp = self.client.get(reverse('admin:django_freeradius_radiusgroupusers_change', args=[obj.pk])) + self.assertContains(resp, 'ok') + + def test_users_accounting(self): + User.objects.create_superuser(username='gino', password='cic', email='giggi_vv@gmail.it') + ola = RadiusAccounting.objects.create( + acct_unique_id='-2', user_name='bob', nas_ip_address='ff', acct_start_time='2017-06-10 10:50:00', + acct_stop_time='2017-06-10 12:10:00', acct_session_time='5', acct_authentic='kj', + connection_info_start='f', connection_info_stop='hgh', + acct_input_octets='1', acct_output_octets='4', rad_acct_id='123', details='nb') + self.client.login(username='gino', password='cic') + resp = self.client.get(reverse('admin:django_freeradius_radiusaccounting_change', args=[ola.pk])) + self.assertContains(resp, 'ok') + + def test_users_postauthentication(self): + User.objects.create_superuser(username='gino', password='cic', email='giggi_vv@gmail.it') + olu = RadiusPostAuthentication.objects.create( + user_name='gino', password='ciao', reply='ghdhd', auth_date='2017-09-02', details='nb') + self.client.login(username='gino', password='cic') + resp = self.client.get(reverse( + 'admin:django_freeradius_radiuspostauthentication_change', args=[olu.pk])) + self.assertContains(resp, 'ok') diff --git a/tests/settings.py b/tests/settings.py index cec0e6d..7069f8d 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -2,6 +2,17 @@ import environ +DJANGO_FREERADIUS_RADIUSREPLY_MODEL = "django_freeradius.RadiusReply" +DJANGO_FREERADIUS_RADIUSGROUPREPLY_MODEL = "django_freeradius.RadiusGroupReply" +DJANGO_FREERADIUS_RADIUSCHECK_MODEL = "django_freeradius.RadiusCheck" +DJANGO_FREERADIUS_RADIUSGROUPCHECK_MODEL = "django_freeradius.RadiusGroupCheck" +DJANGO_FREERADIUS_RADIUSACCOUNTING_MODEL = "django_freeradius.RadiusAccounting" +DJANGO_FREERADIUS_NAS_MODEL = "django_freeradius.Nas" +DJANGO_FREERADIUS_RADIUSGROUPUSERS_MODEL = "django_freeradius.RadiusGroupUsers" +DJANGO_FREERADIUS_RADIUSUSERGROUP_MODEL = "django_freeradius.RadiusUserGroup" +DJANGO_FREERADIUS_RADIUSPOSTAUTHENTICATION_MODEL = "django_freeradius.RadiusPostAuthentication" +DJANGO_FREERADIUS_RADIUSGROUP_MODEL = "django_freeradius.RadiusGroup" + BASE_DIR = os.path.dirname(os.path.abspath(__file__)) root = environ.Path(__file__) - 2 @@ -13,8 +24,14 @@ ALLOWED_HOSTS = [] DATABASES = { - 'default': env.db(default='sqlite:///django-freeradius.db'), -} + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'sample_radius', + 'USER': 'root', + 'PASSWORD': 'milafiore91', + }, + } #'users': { env.db(default='sqlite:///django-freeradius.db'), + #} SECRET_KEY = 'fn)t*+$)ugeyip6-#txyy$5wf2ervc0d2n#h)qb)y5@ly$t*@w' @@ -25,7 +42,8 @@ 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', - 'django_freeradius' + 'django_freeradius', + 'sample_radius', ] MIDDLEWARE_CLASSES = [ From bf8c4d66df89f8e7a7d6f5536640da4933197538 Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Tue, 20 Jun 2017 19:01:26 +0200 Subject: [PATCH 14/31] [django-swapper] added changes --- django_freeradius/migrations/0001_initial.py | 123 +++++++--- .../migrations/0002_auto_20170603_1219.py | 25 -- .../migrations/0003_auto_20170603_1345.py | 30 --- .../migrations/0004_auto_20170614_1916.py | 20 -- .../migrations/0005_auto_20170617_1816.py | 232 ------------------ .../migrations/0006_auto_20170617_2032.py | 95 ------- .../migrations/0007_auto_20170617_2140.py | 95 ------- .../sample_radius/migrations/0001_initial.py | 214 ---------------- tests/sample_radius/models.py | 7 +- tests/settings.py | 20 +- 10 files changed, 100 insertions(+), 761 deletions(-) delete mode 100644 django_freeradius/migrations/0002_auto_20170603_1219.py delete mode 100644 django_freeradius/migrations/0003_auto_20170603_1345.py delete mode 100644 django_freeradius/migrations/0004_auto_20170614_1916.py delete mode 100644 django_freeradius/migrations/0005_auto_20170617_1816.py delete mode 100644 django_freeradius/migrations/0006_auto_20170617_2032.py delete mode 100644 django_freeradius/migrations/0007_auto_20170617_2140.py delete mode 100644 tests/sample_radius/migrations/0001_initial.py diff --git a/django_freeradius/migrations/0001_initial.py b/django_freeradius/migrations/0001_initial.py index 5e62ce3..fb6a416 100644 --- a/django_freeradius/migrations/0001_initial.py +++ b/django_freeradius/migrations/0001_initial.py @@ -1,15 +1,20 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.11.1 on 2017-06-03 08:39 +# Generated by Django 1.11.1 on 2017-06-20 15:40 from __future__ import unicode_literals +from django.conf import settings from django.db import migrations, models - +import django.utils.timezone +import model_utils.fields +import swapper class Migration(migrations.Migration): initial = True dependencies = [ + swapper.dependency('django_freeradius', 'RadiusReply'), + swapper.dependency('django_freeradius', 'RadiusCheck'), ] operations = [ @@ -17,30 +22,36 @@ class Migration(migrations.Migration): name='Nas', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), ('nas_name', models.CharField(db_column='nasname', db_index=True, help_text='NAS Name (or IP address)', max_length=128, unique=True, verbose_name='nas name')), ('short_name', models.CharField(db_column='shortname', max_length=32, verbose_name='short name')), - ('type', models.CharField(db_column='type', max_length=30, verbose_name='type')), - ('secret', models.CharField(db_column='secret', help_text='Shared Secret', max_length=60, verbose_name='secret')), - ('ports', models.IntegerField(blank=True, db_column='ports', null=True, verbose_name='ports')), - ('community', models.CharField(blank=True, db_column='community', max_length=50, null=True, verbose_name='community')), - ('description', models.CharField(db_column='description', max_length=200, null=True, verbose_name='description')), - ('server', models.CharField(db_column='server', max_length=64, null=True, verbose_name='server')), + ('type', models.CharField(max_length=30, verbose_name='type')), + ('secret', models.CharField(help_text='Shared Secret', max_length=60, verbose_name='secret')), + ('ports', models.IntegerField(blank=True, null=True, verbose_name='ports')), + ('community', models.CharField(blank=True, max_length=50, null=True, verbose_name='community')), + ('description', models.CharField(max_length=200, null=True, verbose_name='description')), + ('server', models.CharField(max_length=64, null=True, verbose_name='server')), ], options={ - 'verbose_name': 'nas', 'db_table': 'nas', + 'swappable': swapper.swappable_setting('django_freeradius', 'Nas'), + 'verbose_name': 'nas', + 'abstract': False, 'verbose_name_plural': 'nas', }, ), migrations.CreateModel( name='RadiusAccounting', fields=[ + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), ('rad_acct_id', models.BigIntegerField(db_column='radacctid', primary_key=True, serialize=False)), ('acct_session_id', models.CharField(db_column='acctsessionid', db_index=True, max_length=64)), ('acct_unique_id', models.CharField(db_column='acctuniqueid', max_length=32, unique=True)), ('user_name', models.CharField(db_column='username', db_index=True, max_length=64, verbose_name='username')), ('group_name', models.CharField(db_column='groupname', max_length=64, verbose_name='groupname')), - ('realm', models.CharField(db_column='realm', max_length=64, null=True, verbose_name='realm')), + ('realm', models.CharField(max_length=64, null=True, verbose_name='realm')), ('nas_ip_address', models.CharField(db_column='nasipaddress', db_index=True, max_length=15)), ('nas_port_id', models.CharField(db_column='nasportid', max_length=15, null=True)), ('nas_port_type', models.CharField(db_column='nasporttype', max_length=32, verbose_name='nas port type')), @@ -63,8 +74,10 @@ class Migration(migrations.Migration): ('xascend_session_svrkey', models.CharField(db_column='xascendsessionsvrkey', max_length=10, null=True, verbose_name='xascend session svrkey')), ], options={ - 'verbose_name': 'accounting', 'db_table': 'radacct', + 'swappable': swapper.swappable_setting('django_freeradius', 'RadiusAccounting'), + 'verbose_name': 'accounting', + 'abstract': False, 'verbose_name_plural': 'accounting', }, ), @@ -72,30 +85,38 @@ class Migration(migrations.Migration): name='RadiusCheck', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), ('user_name', models.CharField(db_column='username', db_index=True, max_length=64, verbose_name='username')), - ('value', models.CharField(db_column='value', default='==', max_length=253, verbose_name='radiusvalue')), - ('op', models.CharField(db_column='op', max_length=2, verbose_name='operator')), - ('attribute', models.CharField(db_column='attribute', max_length=64, verbose_name='attribute')), + ('value', models.CharField(max_length=253, verbose_name='radiusvalue')), + ('op', models.CharField(choices=[('=', '='), (':=', ':='), ('==', '=='), ('+=', '+='), ('!=', '!='), ('>', '>'), ('>=', '>='), ('<', '<'), ('<=', '<='), ('=~', '=~'), ('!~', '!~'), ('=*', '=*'), ('!*', '!*')], default=':=', max_length=2, verbose_name='operator')), + ('attribute', models.CharField(max_length=64, verbose_name='attribute')), ], options={ - 'verbose_name': 'radiuscheck', 'db_table': 'radcheck', + 'swappable': swapper.swappable_setting('django_freeradius', 'RadiusCheck'), + 'verbose_name': 'radiuscheck', + 'abstract': False, 'verbose_name_plural': 'radiuschecks', }, ), migrations.CreateModel( name='RadiusGroup', fields=[ + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), ('id', models.UUIDField(db_column='id', primary_key=True, serialize=False)), - ('group_name', models.CharField(db_column='username', db_index=True, max_length=255, unique=True, verbose_name='groupname')), - ('priority', models.IntegerField(db_column='priority', default=1, verbose_name='priority')), + ('group_name', models.CharField(db_column='groupname', db_index=True, max_length=255, unique=True, verbose_name='groupname')), + ('priority', models.IntegerField(default=1, verbose_name='priority')), ('creation_date', models.DateField(db_column='created_at', null=True, verbose_name='creation date')), ('modification_date', models.DateField(db_column='updated_at', null=True, verbose_name='modification date')), - ('notes', models.CharField(blank=True, db_column='notes', max_length=64, null=True, verbose_name='notes')), + ('notes', models.CharField(blank=True, max_length=64, null=True, verbose_name='notes')), ], options={ - 'verbose_name': 'radiusgroup', 'db_table': 'radiusgroup', + 'swappable': swapper.swappable_setting('django_freeradius', 'RadiusGroup'), + 'verbose_name': 'radiusgroup', + 'abstract': False, 'verbose_name_plural': 'radiusgroups', }, ), @@ -103,14 +124,18 @@ class Migration(migrations.Migration): name='RadiusGroupCheck', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), ('group_name', models.CharField(db_column='groupname', db_index=True, max_length=64, verbose_name='groupname')), - ('attribute', models.CharField(db_column='attribute', max_length=64, verbose_name='attribute')), - ('op', models.CharField(choices=[('=', '='), (':=', ':='), ('==', '=='), ('+=', '+='), ('!=', '!='), ('>', '>'), ('>=', '>='), ('<', '<'), ('<=', '<='), ('=~', '=~'), ('!~', '!~'), ('=*', '=*'), ('!*', '!*')], db_column='op', default='==', max_length=2, verbose_name='operator')), - ('value', models.CharField(db_column='value', max_length=253, verbose_name='value')), + ('attribute', models.CharField(max_length=64, verbose_name='attribute')), + ('op', models.CharField(choices=[('=', '='), (':=', ':='), ('==', '=='), ('+=', '+='), ('!=', '!='), ('>', '>'), ('>=', '>='), ('<', '<'), ('<=', '<='), ('=~', '=~'), ('!~', '!~'), ('=*', '=*'), ('!*', '!*')], default=':=', max_length=2, verbose_name='operator')), + ('value', models.CharField(max_length=253, verbose_name='value')), ], options={ - 'verbose_name': 'radiusgroupcheck', 'db_table': 'radgroupcheck', + 'swappable': swapper.swappable_setting('django_freeradius', 'RadiusGroupCheck'), + 'verbose_name': 'radiusgroupcheck', + 'abstract': False, 'verbose_name_plural': 'radiusgroupcheck', }, ), @@ -118,28 +143,36 @@ class Migration(migrations.Migration): name='RadiusGroupReply', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), ('group_name', models.CharField(db_column='groupname', db_index=True, max_length=64, verbose_name='groupname')), - ('attribute', models.CharField(db_column='attribute', max_length=64, verbose_name='attribute')), - ('op', models.CharField(choices=[('=', '='), (':=', ':='), ('+=', '+=')], db_column='op', default='=', max_length=2, verbose_name='operator')), - ('value', models.CharField(db_column='value', max_length=253, verbose_name='value')), + ('attribute', models.CharField(max_length=64, verbose_name='attribute')), + ('op', models.CharField(choices=[('=', '='), (':=', ':='), ('+=', '+=')], default='=', max_length=2, verbose_name='operator')), + ('value', models.CharField(max_length=253, verbose_name='value')), ], options={ - 'verbose_name': 'radiusgroupreply', 'db_table': 'radgroupreply', + 'swappable': swapper.swappable_setting('django_freeradius', 'RadiusGroupReply'), + 'verbose_name': 'radiusgroupreply', + 'abstract': False, 'verbose_name_plural': 'radiusgroupreplies', }, ), migrations.CreateModel( name='RadiusGroupUsers', fields=[ - ('user_name', models.CharField(db_column='username', max_length=64, unique=True, verbose_name='username')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), ('id', models.UUIDField(db_column='id', primary_key=True, serialize=False)), + ('user_name', models.CharField(db_column='username', max_length=64, unique=True, verbose_name='username')), ('group_name', models.CharField(db_column='groupname', max_length=255, unique=True, verbose_name='groupname')), - ('radius_check', models.ManyToManyField(blank=True, db_column='radiuscheck', to='django_freeradius.RadiusCheck', verbose_name='radius check')), + ('radius_check', models.ManyToManyField(blank=True, db_column='radiuscheck', to=settings.DJANGO_FREERADIUS_RADIUSCHECK_MODEL, verbose_name='radius check')), ], options={ - 'verbose_name': 'radiusgroupusers', 'db_table': 'radiusgroupusers', + 'swappable': swapper.swappable_setting('django_freeradius', 'RadiusGroupUsers'), + 'verbose_name': 'radiusgroupusers', + 'abstract': False, 'verbose_name_plural': 'radiusgroupusers', }, ), @@ -147,14 +180,18 @@ class Migration(migrations.Migration): name='RadiusPostAuthentication', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), ('user_name', models.CharField(db_column='username', max_length=64, verbose_name='username')), ('password', models.CharField(db_column='pass', max_length=64, verbose_name='password')), - ('reply', models.CharField(db_column='reply', max_length=32, verbose_name='reply')), + ('reply', models.CharField(max_length=32, verbose_name='reply')), ('auth_date', models.DateTimeField(auto_now=True, db_column='authdate', verbose_name='authdate')), ], options={ - 'verbose_name': 'radiuspostauthentication', 'db_table': 'radpostauth', + 'swappable': swapper.swappable_setting('django_freeradius', 'RadiusPostAuthentication'), + 'verbose_name': 'radiuspostauthentication', + 'abstract': False, 'verbose_name_plural': 'radiuspostauthentication', }, ), @@ -162,14 +199,18 @@ class Migration(migrations.Migration): name='RadiusReply', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), ('user_name', models.CharField(db_column='username', db_index=True, max_length=64, verbose_name='username')), - ('value', models.CharField(db_column='value', max_length=253, verbose_name='value')), - ('op', models.CharField(db_column='op', default='=', max_length=2, verbose_name='operator')), - ('attribute', models.CharField(db_column='attribute', max_length=64, verbose_name='attribute')), + ('value', models.CharField(max_length=253, verbose_name='value')), + ('op', models.CharField(choices=[('=', '='), (':=', ':='), ('+=', '+=')], default='=', max_length=2, verbose_name='operator')), + ('attribute', models.CharField(max_length=64, verbose_name='attribute')), ], options={ - 'verbose_name': 'radiusreply', 'db_table': 'radreply', + 'swappable': swapper.swappable_setting('django_freeradius', 'RadiusReply'), + 'verbose_name': 'radiusreply', + 'abstract': False, 'verbose_name_plural': 'radiusreplies', }, ), @@ -177,19 +218,23 @@ class Migration(migrations.Migration): name='RadiusUserGroup', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), ('user_name', models.CharField(db_column='username', db_index=True, max_length=64, verbose_name='username')), ('group_name', models.CharField(db_column='groupname', max_length=64, verbose_name='groupname')), - ('priority', models.IntegerField(db_column='priority', default=1, verbose_name='priority')), + ('priority', models.IntegerField(default=1, verbose_name='priority')), ], options={ - 'verbose_name': 'radiususergroup', 'db_table': 'radusergroup', + 'swappable': swapper.swappable_setting('django_freeradius', 'RadiusUserGroup'), + 'verbose_name': 'radiususergroup', + 'abstract': False, 'verbose_name_plural': 'radiususergroup', }, ), migrations.AddField( model_name='radiusgroupusers', name='radius_reply', - field=models.ManyToManyField(blank=True, db_column='radiusreply', to='django_freeradius.RadiusReply', verbose_name='radius reply'), + field=models.ManyToManyField(blank=True, db_column='radiusreply', to=swapper.get_model_name('django_freeradius', 'RadiusReply'), verbose_name='radius reply'), ), ] diff --git a/django_freeradius/migrations/0002_auto_20170603_1219.py b/django_freeradius/migrations/0002_auto_20170603_1219.py deleted file mode 100644 index 54f8676..0000000 --- a/django_freeradius/migrations/0002_auto_20170603_1219.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.1 on 2017-06-03 10:19 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('django_freeradius', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='radiuscheck', - name='op', - field=models.CharField(db_column='op', default='==', max_length=2, verbose_name='operator'), - ), - migrations.AlterField( - model_name='radiuscheck', - name='value', - field=models.CharField(db_column='value', max_length=253, verbose_name='radiusvalue'), - ), - ] diff --git a/django_freeradius/migrations/0003_auto_20170603_1345.py b/django_freeradius/migrations/0003_auto_20170603_1345.py deleted file mode 100644 index 5d8c608..0000000 --- a/django_freeradius/migrations/0003_auto_20170603_1345.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.1 on 2017-06-03 11:45 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('django_freeradius', '0002_auto_20170603_1219'), - ] - - operations = [ - migrations.AlterField( - model_name='radiuscheck', - name='op', - field=models.CharField(choices=[('=', '='), (':=', ':='), ('==', '=='), ('+=', '+='), ('!=', '!='), ('>', '>'), ('>=', '>='), ('<', '<'), ('<=', '<='), ('=~', '=~'), ('!~', '!~'), ('=*', '=*'), ('!*', '!*')], db_column='op', default=':=', max_length=2, verbose_name='operator'), - ), - migrations.AlterField( - model_name='radiusgroupcheck', - name='op', - field=models.CharField(choices=[('=', '='), (':=', ':='), ('==', '=='), ('+=', '+='), ('!=', '!='), ('>', '>'), ('>=', '>='), ('<', '<'), ('<=', '<='), ('=~', '=~'), ('!~', '!~'), ('=*', '=*'), ('!*', '!*')], db_column='op', default=':=', max_length=2, verbose_name='operator'), - ), - migrations.AlterField( - model_name='radiusreply', - name='op', - field=models.CharField(choices=[('=', '='), (':=', ':='), ('+=', '+=')], db_column='op', default='=', max_length=2, verbose_name='operator'), - ), - ] diff --git a/django_freeradius/migrations/0004_auto_20170614_1916.py b/django_freeradius/migrations/0004_auto_20170614_1916.py deleted file mode 100644 index 32398a4..0000000 --- a/django_freeradius/migrations/0004_auto_20170614_1916.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.1 on 2017-06-14 17:16 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('django_freeradius', '0003_auto_20170603_1345'), - ] - - operations = [ - migrations.AlterField( - model_name='radiusgroup', - name='group_name', - field=models.CharField(db_column='groupname', db_index=True, max_length=255, unique=True, verbose_name='groupname'), - ), - ] diff --git a/django_freeradius/migrations/0005_auto_20170617_1816.py b/django_freeradius/migrations/0005_auto_20170617_1816.py deleted file mode 100644 index a0b1ee6..0000000 --- a/django_freeradius/migrations/0005_auto_20170617_1816.py +++ /dev/null @@ -1,232 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.1 on 2017-06-17 16:16 -from __future__ import unicode_literals - -import django.utils.timezone -import model_utils.fields -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('django_freeradius', '0004_auto_20170614_1916'), - ] - - operations = [ - migrations.AddField( - model_name='nas', - name='created', - field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), - ), - migrations.AddField( - model_name='nas', - name='modified', - field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), - ), - migrations.AddField( - model_name='radiusaccounting', - name='created', - field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), - ), - migrations.AddField( - model_name='radiusaccounting', - name='modified', - field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), - ), - migrations.AddField( - model_name='radiuscheck', - name='created', - field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), - ), - migrations.AddField( - model_name='radiuscheck', - name='modified', - field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), - ), - migrations.AddField( - model_name='radiusgroup', - name='created', - field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), - ), - migrations.AddField( - model_name='radiusgroup', - name='modified', - field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), - ), - migrations.AddField( - model_name='radiusgroupcheck', - name='created', - field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), - ), - migrations.AddField( - model_name='radiusgroupcheck', - name='modified', - field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), - ), - migrations.AddField( - model_name='radiusgroupreply', - name='created', - field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), - ), - migrations.AddField( - model_name='radiusgroupreply', - name='modified', - field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), - ), - migrations.AddField( - model_name='radiusgroupusers', - name='created', - field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), - ), - migrations.AddField( - model_name='radiusgroupusers', - name='modified', - field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), - ), - migrations.AddField( - model_name='radiuspostauthentication', - name='created', - field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), - ), - migrations.AddField( - model_name='radiuspostauthentication', - name='modified', - field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), - ), - migrations.AddField( - model_name='radiusreply', - name='created', - field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), - ), - migrations.AddField( - model_name='radiusreply', - name='modified', - field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), - ), - migrations.AddField( - model_name='radiususergroup', - name='created', - field=model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created'), - ), - migrations.AddField( - model_name='radiususergroup', - name='modified', - field=model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified'), - ), - migrations.AlterField( - model_name='nas', - name='community', - field=models.CharField(blank=True, max_length=50, null=True, verbose_name='community'), - ), - migrations.AlterField( - model_name='nas', - name='description', - field=models.CharField(max_length=200, null=True, verbose_name='description'), - ), - migrations.AlterField( - model_name='nas', - name='ports', - field=models.IntegerField(blank=True, null=True, verbose_name='ports'), - ), - migrations.AlterField( - model_name='nas', - name='secret', - field=models.CharField(help_text='Shared Secret', max_length=60, verbose_name='secret'), - ), - migrations.AlterField( - model_name='nas', - name='server', - field=models.CharField(max_length=64, null=True, verbose_name='server'), - ), - migrations.AlterField( - model_name='nas', - name='type', - field=models.CharField(max_length=30, verbose_name='type'), - ), - migrations.AlterField( - model_name='radiusaccounting', - name='realm', - field=models.CharField(max_length=64, null=True, verbose_name='realm'), - ), - migrations.AlterField( - model_name='radiuscheck', - name='attribute', - field=models.CharField(max_length=64, verbose_name='attribute'), - ), - migrations.AlterField( - model_name='radiuscheck', - name='op', - field=models.CharField(choices=[('=', '='), (':=', ':='), ('==', '=='), ('+=', '+='), ('!=', '!='), ('>', '>'), ('>=', '>='), ('<', '<'), ('<=', '<='), ('=~', '=~'), ('!~', '!~'), ('=*', '=*'), ('!*', '!*')], default=':=', max_length=2, verbose_name='operator'), - ), - migrations.AlterField( - model_name='radiuscheck', - name='value', - field=models.CharField(max_length=253, verbose_name='radiusvalue'), - ), - migrations.AlterField( - model_name='radiusgroup', - name='notes', - field=models.CharField(blank=True, max_length=64, null=True, verbose_name='notes'), - ), - migrations.AlterField( - model_name='radiusgroup', - name='priority', - field=models.IntegerField(default=1, verbose_name='priority'), - ), - migrations.AlterField( - model_name='radiusgroupcheck', - name='attribute', - field=models.CharField(max_length=64, verbose_name='attribute'), - ), - migrations.AlterField( - model_name='radiusgroupcheck', - name='op', - field=models.CharField(choices=[('=', '='), (':=', ':='), ('==', '=='), ('+=', '+='), ('!=', '!='), ('>', '>'), ('>=', '>='), ('<', '<'), ('<=', '<='), ('=~', '=~'), ('!~', '!~'), ('=*', '=*'), ('!*', '!*')], default=':=', max_length=2, verbose_name='operator'), - ), - migrations.AlterField( - model_name='radiusgroupcheck', - name='value', - field=models.CharField(max_length=253, verbose_name='value'), - ), - migrations.AlterField( - model_name='radiusgroupreply', - name='attribute', - field=models.CharField(max_length=64, verbose_name='attribute'), - ), - migrations.AlterField( - model_name='radiusgroupreply', - name='op', - field=models.CharField(choices=[('=', '='), (':=', ':='), ('+=', '+=')], default='=', max_length=2, verbose_name='operator'), - ), - migrations.AlterField( - model_name='radiusgroupreply', - name='value', - field=models.CharField(max_length=253, verbose_name='value'), - ), - migrations.AlterField( - model_name='radiuspostauthentication', - name='reply', - field=models.CharField(max_length=32, verbose_name='reply'), - ), - migrations.AlterField( - model_name='radiusreply', - name='attribute', - field=models.CharField(max_length=64, verbose_name='attribute'), - ), - migrations.AlterField( - model_name='radiusreply', - name='op', - field=models.CharField(choices=[('=', '='), (':=', ':='), ('+=', '+=')], default='=', max_length=2, verbose_name='operator'), - ), - migrations.AlterField( - model_name='radiusreply', - name='value', - field=models.CharField(max_length=253, verbose_name='value'), - ), - migrations.AlterField( - model_name='radiususergroup', - name='priority', - field=models.IntegerField(default=1, verbose_name='priority'), - ), - ] diff --git a/django_freeradius/migrations/0006_auto_20170617_2032.py b/django_freeradius/migrations/0006_auto_20170617_2032.py deleted file mode 100644 index a9fc438..0000000 --- a/django_freeradius/migrations/0006_auto_20170617_2032.py +++ /dev/null @@ -1,95 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.1 on 2017-06-17 18:32 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('django_freeradius', '0005_auto_20170617_1816'), - ] - - operations = [ - migrations.AlterModelOptions( - name='nas', - options={}, - ), - migrations.AlterModelOptions( - name='radiusaccounting', - options={}, - ), - migrations.AlterModelOptions( - name='radiuscheck', - options={}, - ), - migrations.AlterModelOptions( - name='radiusgroup', - options={}, - ), - migrations.AlterModelOptions( - name='radiusgroupcheck', - options={}, - ), - migrations.AlterModelOptions( - name='radiusgroupreply', - options={}, - ), - migrations.AlterModelOptions( - name='radiusgroupusers', - options={}, - ), - migrations.AlterModelOptions( - name='radiuspostauthentication', - options={}, - ), - migrations.AlterModelOptions( - name='radiusreply', - options={}, - ), - migrations.AlterModelOptions( - name='radiususergroup', - options={}, - ), - migrations.AlterModelTable( - name='nas', - table=None, - ), - migrations.AlterModelTable( - name='radiusaccounting', - table=None, - ), - migrations.AlterModelTable( - name='radiuscheck', - table=None, - ), - migrations.AlterModelTable( - name='radiusgroup', - table=None, - ), - migrations.AlterModelTable( - name='radiusgroupcheck', - table=None, - ), - migrations.AlterModelTable( - name='radiusgroupreply', - table=None, - ), - migrations.AlterModelTable( - name='radiusgroupusers', - table=None, - ), - migrations.AlterModelTable( - name='radiuspostauthentication', - table=None, - ), - migrations.AlterModelTable( - name='radiusreply', - table=None, - ), - migrations.AlterModelTable( - name='radiususergroup', - table=None, - ), - ] diff --git a/django_freeradius/migrations/0007_auto_20170617_2140.py b/django_freeradius/migrations/0007_auto_20170617_2140.py deleted file mode 100644 index e704669..0000000 --- a/django_freeradius/migrations/0007_auto_20170617_2140.py +++ /dev/null @@ -1,95 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.1 on 2017-06-17 19:40 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('django_freeradius', '0006_auto_20170617_2032'), - ] - - operations = [ - migrations.AlterModelOptions( - name='nas', - options={'verbose_name': 'nas', 'verbose_name_plural': 'nas'}, - ), - migrations.AlterModelOptions( - name='radiusaccounting', - options={'verbose_name': 'accounting', 'verbose_name_plural': 'accounting'}, - ), - migrations.AlterModelOptions( - name='radiuscheck', - options={'verbose_name': 'radiuscheck', 'verbose_name_plural': 'radiuschecks'}, - ), - migrations.AlterModelOptions( - name='radiusgroup', - options={'verbose_name': 'radiusgroup', 'verbose_name_plural': 'radiusgroups'}, - ), - migrations.AlterModelOptions( - name='radiusgroupcheck', - options={'verbose_name': 'radiusgroupcheck', 'verbose_name_plural': 'radiusgroupcheck'}, - ), - migrations.AlterModelOptions( - name='radiusgroupreply', - options={'verbose_name': 'radiusgroupreply', 'verbose_name_plural': 'radiusgroupreplies'}, - ), - migrations.AlterModelOptions( - name='radiusgroupusers', - options={'verbose_name': 'radiusgroupusers', 'verbose_name_plural': 'radiusgroupusers'}, - ), - migrations.AlterModelOptions( - name='radiuspostauthentication', - options={'verbose_name': 'radiuspostauthentication', 'verbose_name_plural': 'radiuspostauthentication'}, - ), - migrations.AlterModelOptions( - name='radiusreply', - options={'verbose_name': 'radiusreply', 'verbose_name_plural': 'radiusreplies'}, - ), - migrations.AlterModelOptions( - name='radiususergroup', - options={'verbose_name': 'radiususergroup', 'verbose_name_plural': 'radiususergroup'}, - ), - migrations.AlterModelTable( - name='nas', - table='nas', - ), - migrations.AlterModelTable( - name='radiusaccounting', - table='radacct', - ), - migrations.AlterModelTable( - name='radiuscheck', - table='radcheck', - ), - migrations.AlterModelTable( - name='radiusgroup', - table='radiusgroup', - ), - migrations.AlterModelTable( - name='radiusgroupcheck', - table='radgroupcheck', - ), - migrations.AlterModelTable( - name='radiusgroupreply', - table='radgroupreply', - ), - migrations.AlterModelTable( - name='radiusgroupusers', - table='radiusgroupusers', - ), - migrations.AlterModelTable( - name='radiuspostauthentication', - table='radpostauth', - ), - migrations.AlterModelTable( - name='radiusreply', - table='radreply', - ), - migrations.AlterModelTable( - name='radiususergroup', - table='radusergroup', - ), - ] diff --git a/tests/sample_radius/migrations/0001_initial.py b/tests/sample_radius/migrations/0001_initial.py deleted file mode 100644 index 29974ef..0000000 --- a/tests/sample_radius/migrations/0001_initial.py +++ /dev/null @@ -1,214 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.1 on 2017-06-20 13:55 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.utils.timezone -import model_utils.fields - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='Nas', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), - ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), - ('nas_name', models.CharField(db_column='nasname', db_index=True, help_text='NAS Name (or IP address)', max_length=128, unique=True, verbose_name='nas name')), - ('short_name', models.CharField(db_column='shortname', max_length=32, verbose_name='short name')), - ('type', models.CharField(max_length=30, verbose_name='type')), - ('secret', models.CharField(help_text='Shared Secret', max_length=60, verbose_name='secret')), - ('ports', models.IntegerField(blank=True, null=True, verbose_name='ports')), - ('community', models.CharField(blank=True, max_length=50, null=True, verbose_name='community')), - ('description', models.CharField(max_length=200, null=True, verbose_name='description')), - ('server', models.CharField(max_length=64, null=True, verbose_name='server')), - ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), - ], - options={ - 'abstract': False, - 'verbose_name_plural': 'nas', - 'verbose_name': 'nas', - 'db_table': 'nas', - }, - ), - migrations.CreateModel( - name='RadiusAccounting', - fields=[ - ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), - ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), - ('rad_acct_id', models.BigIntegerField(db_column='radacctid', primary_key=True, serialize=False)), - ('acct_session_id', models.CharField(db_column='acctsessionid', db_index=True, max_length=64)), - ('acct_unique_id', models.CharField(db_column='acctuniqueid', max_length=32, unique=True)), - ('user_name', models.CharField(db_column='username', db_index=True, max_length=64, verbose_name='username')), - ('group_name', models.CharField(db_column='groupname', max_length=64, verbose_name='groupname')), - ('realm', models.CharField(max_length=64, null=True, verbose_name='realm')), - ('nas_ip_address', models.CharField(db_column='nasipaddress', db_index=True, max_length=15)), - ('nas_port_id', models.CharField(db_column='nasportid', max_length=15, null=True)), - ('nas_port_type', models.CharField(db_column='nasporttype', max_length=32, verbose_name='nas port type')), - ('acct_start_time', models.DateTimeField(db_column='acctstarttime', db_index=True, verbose_name='acct start time')), - ('acct_stop_time', models.DateTimeField(db_column='acctstoptime', db_index=True, null=True, verbose_name='acct stop time')), - ('acct_session_time', models.IntegerField(db_column='acctsessiontime', db_index=True, null=True, verbose_name='acct session time')), - ('acct_authentic', models.CharField(db_column='acctauthentic', max_length=32, null=True, verbose_name='acct authentic')), - ('connection_info_start', models.CharField(db_column='connectinfo_start', max_length=50, null=True, verbose_name='connection info start')), - ('connection_info_stop', models.CharField(db_column='connectinfo_stop', max_length=50, null=True, verbose_name='connection info stop')), - ('acct_input_octets', models.BigIntegerField(db_column='acctinputoctets', null=True, verbose_name='acct input octets')), - ('acct_output_octets', models.BigIntegerField(db_column='acctoutputoctets', null=True, verbose_name='acct output octets')), - ('callingStationId', models.CharField(db_column='calledstationid', max_length=50)), - ('calledStationId', models.CharField(db_column='callingstationid', max_length=50)), - ('acct_terminate_cause', models.CharField(db_column='acctterminatecause', max_length=32, verbose_name='acct terminate cause')), - ('service_type', models.CharField(db_column='servicetype', max_length=32, null=True, verbose_name='service type')), - ('framed_protocol', models.CharField(db_column='framedprotocol', max_length=32, null=True, verbose_name='framed protocol')), - ('framed_ip_address', models.CharField(db_column='framedipaddress', db_index=True, max_length=15)), - ('acct_start_delay', models.IntegerField(db_column='acctstartdelay', null=True, verbose_name='acct start delay')), - ('acct_stop_delay', models.IntegerField(db_column='acctstopdelay', null=True, verbose_name='acct stop delay')), - ('xascend_session_svrkey', models.CharField(db_column='xascendsessionsvrkey', max_length=10, null=True, verbose_name='xascend session svrkey')), - ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), - ], - options={ - 'abstract': False, - 'verbose_name_plural': 'accounting', - 'verbose_name': 'accounting', - 'db_table': 'radacct', - }, - ), - migrations.CreateModel( - name='RadiusCheck', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), - ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), - ('user_name', models.CharField(db_column='username', db_index=True, max_length=64, verbose_name='username')), - ('value', models.CharField(max_length=253, verbose_name='radiusvalue')), - ('op', models.CharField(choices=[('=', '='), (':=', ':='), ('==', '=='), ('+=', '+='), ('!=', '!='), ('>', '>'), ('>=', '>='), ('<', '<'), ('<=', '<='), ('=~', '=~'), ('!~', '!~'), ('=*', '=*'), ('!*', '!*')], default=':=', max_length=2, verbose_name='operator')), - ('attribute', models.CharField(max_length=64, verbose_name='attribute')), - ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), - ], - options={ - 'abstract': False, - 'verbose_name_plural': 'radiuschecks', - 'verbose_name': 'radiuscheck', - 'db_table': 'radcheck', - }, - ), - migrations.CreateModel( - name='RadiusGroup', - fields=[ - ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), - ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), - ('id', models.UUIDField(db_column='id', primary_key=True, serialize=False)), - ('group_name', models.CharField(db_column='groupname', db_index=True, max_length=255, unique=True, verbose_name='groupname')), - ('priority', models.IntegerField(default=1, verbose_name='priority')), - ('creation_date', models.DateField(db_column='created_at', null=True, verbose_name='creation date')), - ('modification_date', models.DateField(db_column='updated_at', null=True, verbose_name='modification date')), - ('notes', models.CharField(blank=True, max_length=64, null=True, verbose_name='notes')), - ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), - ], - options={ - 'abstract': False, - 'verbose_name_plural': 'radiusgroups', - 'verbose_name': 'radiusgroup', - 'db_table': 'radiusgroup', - }, - ), - migrations.CreateModel( - name='RadiusGroupCheck', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), - ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), - ('group_name', models.CharField(db_column='groupname', db_index=True, max_length=64, verbose_name='groupname')), - ('attribute', models.CharField(max_length=64, verbose_name='attribute')), - ('op', models.CharField(choices=[('=', '='), (':=', ':='), ('==', '=='), ('+=', '+='), ('!=', '!='), ('>', '>'), ('>=', '>='), ('<', '<'), ('<=', '<='), ('=~', '=~'), ('!~', '!~'), ('=*', '=*'), ('!*', '!*')], default=':=', max_length=2, verbose_name='operator')), - ('value', models.CharField(max_length=253, verbose_name='value')), - ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), - ], - options={ - 'abstract': False, - 'verbose_name_plural': 'radiusgroupcheck', - 'verbose_name': 'radiusgroupcheck', - 'db_table': 'radgroupcheck', - }, - ), - migrations.CreateModel( - name='RadiusGroupReply', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), - ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), - ('group_name', models.CharField(db_column='groupname', db_index=True, max_length=64, verbose_name='groupname')), - ('attribute', models.CharField(max_length=64, verbose_name='attribute')), - ('op', models.CharField(choices=[('=', '='), (':=', ':='), ('+=', '+=')], default='=', max_length=2, verbose_name='operator')), - ('value', models.CharField(max_length=253, verbose_name='value')), - ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), - ], - options={ - 'abstract': False, - 'verbose_name_plural': 'radiusgroupreplies', - 'verbose_name': 'radiusgroupreply', - 'db_table': 'radgroupreply', - }, - ), - migrations.CreateModel( - name='RadiusPostAuthentication', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), - ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), - ('user_name', models.CharField(db_column='username', max_length=64, verbose_name='username')), - ('password', models.CharField(db_column='pass', max_length=64, verbose_name='password')), - ('reply', models.CharField(max_length=32, verbose_name='reply')), - ('auth_date', models.DateTimeField(auto_now=True, db_column='authdate', verbose_name='authdate')), - ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), - ], - options={ - 'abstract': False, - 'verbose_name_plural': 'radiuspostauthentication', - 'verbose_name': 'radiuspostauthentication', - 'db_table': 'radpostauth', - }, - ), - migrations.CreateModel( - name='RadiusReply', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), - ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), - ('user_name', models.CharField(db_column='username', db_index=True, max_length=64, verbose_name='username')), - ('value', models.CharField(max_length=253, verbose_name='value')), - ('op', models.CharField(choices=[('=', '='), (':=', ':='), ('+=', '+=')], default='=', max_length=2, verbose_name='operator')), - ('attribute', models.CharField(max_length=64, verbose_name='attribute')), - ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), - ], - options={ - 'abstract': False, - 'verbose_name_plural': 'radiusreplies', - 'verbose_name': 'radiusreply', - 'db_table': 'radreply', - }, - ), - migrations.CreateModel( - name='RadiusUserGroup', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), - ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), - ('user_name', models.CharField(db_column='username', db_index=True, max_length=64, verbose_name='username')), - ('group_name', models.CharField(db_column='groupname', max_length=64, verbose_name='groupname')), - ('priority', models.IntegerField(default=1, verbose_name='priority')), - ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), - ], - options={ - 'abstract': False, - 'verbose_name_plural': 'radiususergroup', - 'verbose_name': 'radiususergroup', - 'db_table': 'radusergroup', - }, - ), - ] diff --git a/tests/sample_radius/models.py b/tests/sample_radius/models.py index 6491b98..22ef64f 100644 --- a/tests/sample_radius/models.py +++ b/tests/sample_radius/models.py @@ -49,6 +49,11 @@ class RadiusUserGroup(AbstractRadiusUserGroup): verbose_name=_('details'), max_length=64, blank=True, null=True) -class RadiusNas(AbstractNas): +class Nas(AbstractNas): + details = models.CharField( + verbose_name=_('details'), max_length=64, blank=True, null=True) + + +class RadiusGroupUsers(AbstractNas): details = models.CharField( verbose_name=_('details'), max_length=64, blank=True, null=True) diff --git a/tests/settings.py b/tests/settings.py index 7069f8d..08453ac 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -2,16 +2,16 @@ import environ -DJANGO_FREERADIUS_RADIUSREPLY_MODEL = "django_freeradius.RadiusReply" -DJANGO_FREERADIUS_RADIUSGROUPREPLY_MODEL = "django_freeradius.RadiusGroupReply" -DJANGO_FREERADIUS_RADIUSCHECK_MODEL = "django_freeradius.RadiusCheck" -DJANGO_FREERADIUS_RADIUSGROUPCHECK_MODEL = "django_freeradius.RadiusGroupCheck" -DJANGO_FREERADIUS_RADIUSACCOUNTING_MODEL = "django_freeradius.RadiusAccounting" -DJANGO_FREERADIUS_NAS_MODEL = "django_freeradius.Nas" -DJANGO_FREERADIUS_RADIUSGROUPUSERS_MODEL = "django_freeradius.RadiusGroupUsers" -DJANGO_FREERADIUS_RADIUSUSERGROUP_MODEL = "django_freeradius.RadiusUserGroup" -DJANGO_FREERADIUS_RADIUSPOSTAUTHENTICATION_MODEL = "django_freeradius.RadiusPostAuthentication" -DJANGO_FREERADIUS_RADIUSGROUP_MODEL = "django_freeradius.RadiusGroup" +DJANGO_FREERADIUS_RADIUSREPLY_MODEL = "sample_radius.RadiusReply" +DJANGO_FREERADIUS_RADIUSGROUPREPLY_MODEL = "sample_radius.RadiusGroupReply" +DJANGO_FREERADIUS_RADIUSCHECK_MODEL = "sample_radius.RadiusCheck" +DJANGO_FREERADIUS_RADIUSGROUPCHECK_MODEL = "sample_radius.RadiusGroupCheck" +DJANGO_FREERADIUS_RADIUSACCOUNTING_MODEL = "sample_radius.RadiusAccounting" +DJANGO_FREERADIUS_NAS_MODEL = "sample_radius.Nas" +DJANGO_FREERADIUS_RADIUSGROUPUSERS_MODEL = "sample_radius.RadiusGroupUsers" +DJANGO_FREERADIUS_RADIUSUSERGROUP_MODEL = "sample_radius.RadiusUserGroup" +DJANGO_FREERADIUS_RADIUSPOSTAUTHENTICATION_MODEL = "sample_radius.RadiusPostAuthentication" +DJANGO_FREERADIUS_RADIUSGROUP_MODEL = "sample_radius.RadiusGroup" BASE_DIR = os.path.dirname(os.path.abspath(__file__)) From 7039ed5c2eb37b6ee0f2cb310a3f55fce6606bed Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Tue, 20 Jun 2017 20:23:16 +0200 Subject: [PATCH 15/31] [general] clean code --- .../sample_radius/migrations/0001_initial.py | 238 ++++++++++++++++++ tests/sample_radius/models.py | 2 +- tests/sample_radius/tests.py | 2 +- tests/settings.py | 4 +- 4 files changed, 242 insertions(+), 4 deletions(-) create mode 100644 tests/sample_radius/migrations/0001_initial.py diff --git a/tests/sample_radius/migrations/0001_initial.py b/tests/sample_radius/migrations/0001_initial.py new file mode 100644 index 0000000..6f645b9 --- /dev/null +++ b/tests/sample_radius/migrations/0001_initial.py @@ -0,0 +1,238 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.1 on 2017-06-20 17:35 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.utils.timezone +import model_utils.fields + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Nas', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('nas_name', models.CharField(db_column='nasname', db_index=True, help_text='NAS Name (or IP address)', max_length=128, unique=True, verbose_name='nas name')), + ('short_name', models.CharField(db_column='shortname', max_length=32, verbose_name='short name')), + ('type', models.CharField(max_length=30, verbose_name='type')), + ('secret', models.CharField(help_text='Shared Secret', max_length=60, verbose_name='secret')), + ('ports', models.IntegerField(blank=True, null=True, verbose_name='ports')), + ('community', models.CharField(blank=True, max_length=50, null=True, verbose_name='community')), + ('description', models.CharField(max_length=200, null=True, verbose_name='description')), + ('server', models.CharField(max_length=64, null=True, verbose_name='server')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ], + options={ + 'verbose_name': 'nas', + 'abstract': False, + 'verbose_name_plural': 'nas', + 'db_table': 'nas', + }, + ), + migrations.CreateModel( + name='RadiusAccounting', + fields=[ + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('rad_acct_id', models.BigIntegerField(db_column='radacctid', primary_key=True, serialize=False)), + ('acct_session_id', models.CharField(db_column='acctsessionid', db_index=True, max_length=64)), + ('acct_unique_id', models.CharField(db_column='acctuniqueid', max_length=32, unique=True)), + ('user_name', models.CharField(db_column='username', db_index=True, max_length=64, verbose_name='username')), + ('group_name', models.CharField(db_column='groupname', max_length=64, verbose_name='groupname')), + ('realm', models.CharField(max_length=64, null=True, verbose_name='realm')), + ('nas_ip_address', models.CharField(db_column='nasipaddress', db_index=True, max_length=15)), + ('nas_port_id', models.CharField(db_column='nasportid', max_length=15, null=True)), + ('nas_port_type', models.CharField(db_column='nasporttype', max_length=32, verbose_name='nas port type')), + ('acct_start_time', models.DateTimeField(db_column='acctstarttime', db_index=True, verbose_name='acct start time')), + ('acct_stop_time', models.DateTimeField(db_column='acctstoptime', db_index=True, null=True, verbose_name='acct stop time')), + ('acct_session_time', models.IntegerField(db_column='acctsessiontime', db_index=True, null=True, verbose_name='acct session time')), + ('acct_authentic', models.CharField(db_column='acctauthentic', max_length=32, null=True, verbose_name='acct authentic')), + ('connection_info_start', models.CharField(db_column='connectinfo_start', max_length=50, null=True, verbose_name='connection info start')), + ('connection_info_stop', models.CharField(db_column='connectinfo_stop', max_length=50, null=True, verbose_name='connection info stop')), + ('acct_input_octets', models.BigIntegerField(db_column='acctinputoctets', null=True, verbose_name='acct input octets')), + ('acct_output_octets', models.BigIntegerField(db_column='acctoutputoctets', null=True, verbose_name='acct output octets')), + ('callingStationId', models.CharField(db_column='calledstationid', max_length=50)), + ('calledStationId', models.CharField(db_column='callingstationid', max_length=50)), + ('acct_terminate_cause', models.CharField(db_column='acctterminatecause', max_length=32, verbose_name='acct terminate cause')), + ('service_type', models.CharField(db_column='servicetype', max_length=32, null=True, verbose_name='service type')), + ('framed_protocol', models.CharField(db_column='framedprotocol', max_length=32, null=True, verbose_name='framed protocol')), + ('framed_ip_address', models.CharField(db_column='framedipaddress', db_index=True, max_length=15)), + ('acct_start_delay', models.IntegerField(db_column='acctstartdelay', null=True, verbose_name='acct start delay')), + ('acct_stop_delay', models.IntegerField(db_column='acctstopdelay', null=True, verbose_name='acct stop delay')), + ('xascend_session_svrkey', models.CharField(db_column='xascendsessionsvrkey', max_length=10, null=True, verbose_name='xascend session svrkey')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ], + options={ + 'verbose_name': 'accounting', + 'abstract': False, + 'verbose_name_plural': 'accounting', + 'db_table': 'radacct', + }, + ), + migrations.CreateModel( + name='RadiusCheck', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('user_name', models.CharField(db_column='username', db_index=True, max_length=64, verbose_name='username')), + ('value', models.CharField(max_length=253, verbose_name='radiusvalue')), + ('op', models.CharField(choices=[('=', '='), (':=', ':='), ('==', '=='), ('+=', '+='), ('!=', '!='), ('>', '>'), ('>=', '>='), ('<', '<'), ('<=', '<='), ('=~', '=~'), ('!~', '!~'), ('=*', '=*'), ('!*', '!*')], default=':=', max_length=2, verbose_name='operator')), + ('attribute', models.CharField(max_length=64, verbose_name='attribute')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ], + options={ + 'verbose_name': 'radiuscheck', + 'abstract': False, + 'verbose_name_plural': 'radiuschecks', + 'db_table': 'radcheck', + }, + ), + migrations.CreateModel( + name='RadiusGroup', + fields=[ + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('id', models.UUIDField(db_column='id', primary_key=True, serialize=False)), + ('group_name', models.CharField(db_column='groupname', db_index=True, max_length=255, unique=True, verbose_name='groupname')), + ('priority', models.IntegerField(default=1, verbose_name='priority')), + ('creation_date', models.DateField(db_column='created_at', null=True, verbose_name='creation date')), + ('modification_date', models.DateField(db_column='updated_at', null=True, verbose_name='modification date')), + ('notes', models.CharField(blank=True, max_length=64, null=True, verbose_name='notes')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ], + options={ + 'verbose_name': 'radiusgroup', + 'abstract': False, + 'verbose_name_plural': 'radiusgroups', + 'db_table': 'radiusgroup', + }, + ), + migrations.CreateModel( + name='RadiusGroupCheck', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('group_name', models.CharField(db_column='groupname', db_index=True, max_length=64, verbose_name='groupname')), + ('attribute', models.CharField(max_length=64, verbose_name='attribute')), + ('op', models.CharField(choices=[('=', '='), (':=', ':='), ('==', '=='), ('+=', '+='), ('!=', '!='), ('>', '>'), ('>=', '>='), ('<', '<'), ('<=', '<='), ('=~', '=~'), ('!~', '!~'), ('=*', '=*'), ('!*', '!*')], default=':=', max_length=2, verbose_name='operator')), + ('value', models.CharField(max_length=253, verbose_name='value')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ], + options={ + 'verbose_name': 'radiusgroupcheck', + 'abstract': False, + 'verbose_name_plural': 'radiusgroupcheck', + 'db_table': 'radgroupcheck', + }, + ), + migrations.CreateModel( + name='RadiusGroupReply', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('group_name', models.CharField(db_column='groupname', db_index=True, max_length=64, verbose_name='groupname')), + ('attribute', models.CharField(max_length=64, verbose_name='attribute')), + ('op', models.CharField(choices=[('=', '='), (':=', ':='), ('+=', '+=')], default='=', max_length=2, verbose_name='operator')), + ('value', models.CharField(max_length=253, verbose_name='value')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ], + options={ + 'verbose_name': 'radiusgroupreply', + 'abstract': False, + 'verbose_name_plural': 'radiusgroupreplies', + 'db_table': 'radgroupreply', + }, + ), + migrations.CreateModel( + name='RadiusGroupUsers', + fields=[ + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('id', models.UUIDField(db_column='id', primary_key=True, serialize=False)), + ('user_name', models.CharField(db_column='username', max_length=64, unique=True, verbose_name='username')), + ('group_name', models.CharField(db_column='groupname', max_length=255, unique=True, verbose_name='groupname')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ('radius_check', models.ManyToManyField(blank=True, db_column='radiuscheck', to=settings.DJANGO_FREERADIUS_RADIUSCHECK_MODEL, verbose_name='radius check')), + ], + options={ + 'verbose_name': 'radiusgroupusers', + 'abstract': False, + 'verbose_name_plural': 'radiusgroupusers', + 'db_table': 'radiusgroupusers', + }, + ), + migrations.CreateModel( + name='RadiusPostAuthentication', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('user_name', models.CharField(db_column='username', max_length=64, verbose_name='username')), + ('password', models.CharField(db_column='pass', max_length=64, verbose_name='password')), + ('reply', models.CharField(max_length=32, verbose_name='reply')), + ('auth_date', models.DateTimeField(auto_now=True, db_column='authdate', verbose_name='authdate')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ], + options={ + 'verbose_name': 'radiuspostauthentication', + 'abstract': False, + 'verbose_name_plural': 'radiuspostauthentication', + 'db_table': 'radpostauth', + }, + ), + migrations.CreateModel( + name='RadiusReply', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('user_name', models.CharField(db_column='username', db_index=True, max_length=64, verbose_name='username')), + ('value', models.CharField(max_length=253, verbose_name='value')), + ('op', models.CharField(choices=[('=', '='), (':=', ':='), ('+=', '+=')], default='=', max_length=2, verbose_name='operator')), + ('attribute', models.CharField(max_length=64, verbose_name='attribute')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ], + options={ + 'verbose_name': 'radiusreply', + 'abstract': False, + 'verbose_name_plural': 'radiusreplies', + 'db_table': 'radreply', + }, + ), + migrations.CreateModel( + name='RadiusUserGroup', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), + ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), + ('user_name', models.CharField(db_column='username', db_index=True, max_length=64, verbose_name='username')), + ('group_name', models.CharField(db_column='groupname', max_length=64, verbose_name='groupname')), + ('priority', models.IntegerField(default=1, verbose_name='priority')), + ('details', models.CharField(blank=True, max_length=64, null=True, verbose_name='details')), + ], + options={ + 'verbose_name': 'radiususergroup', + 'abstract': False, + 'verbose_name_plural': 'radiususergroup', + 'db_table': 'radusergroup', + }, + ), + migrations.AddField( + model_name='radiusgroupusers', + name='radius_reply', + field=models.ManyToManyField(blank=True, db_column='radiusreply', to=settings.DJANGO_FREERADIUS_RADIUSREPLY_MODEL, verbose_name='radius reply'), + ), + ] diff --git a/tests/sample_radius/models.py b/tests/sample_radius/models.py index 22ef64f..75288bf 100644 --- a/tests/sample_radius/models.py +++ b/tests/sample_radius/models.py @@ -54,6 +54,6 @@ class Nas(AbstractNas): verbose_name=_('details'), max_length=64, blank=True, null=True) -class RadiusGroupUsers(AbstractNas): +class RadiusGroupUsers(AbstractRadiusGroupUsers): details = models.CharField( verbose_name=_('details'), max_length=64, blank=True, null=True) diff --git a/tests/sample_radius/tests.py b/tests/sample_radius/tests.py index 10c11d6..0171a36 100644 --- a/tests/sample_radius/tests.py +++ b/tests/sample_radius/tests.py @@ -3,7 +3,7 @@ from django.test import Client from django.urls import reverse -from ..models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, +from .models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, RadiusPostAuthentication, RadiusReply, RadiusUserGroup) diff --git a/tests/settings.py b/tests/settings.py index 08453ac..84d3de1 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -30,8 +30,8 @@ 'USER': 'root', 'PASSWORD': 'milafiore91', }, - } #'users': { env.db(default='sqlite:///django-freeradius.db'), - #} + #'default': env.db(default='sqlite:///django-freeradius.db'), + } SECRET_KEY = 'fn)t*+$)ugeyip6-#txyy$5wf2ervc0d2n#h)qb)y5@ly$t*@w' From a854e1bb6a41e45b32ae2f4488ace50521828b6a Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Tue, 20 Jun 2017 21:03:48 +0200 Subject: [PATCH 16/31] [general] added swapper import --- django_freeradius/models.py | 12 ++++ django_freeradius/tests/tests_admin.py | 17 ++++-- django_freeradius/tests/tests_models.py | 16 ++++-- tests/sample_radius/admin.py | 73 +++++++++++++++++++++---- tests/sample_radius/models.py | 13 ++++- tests/sample_radius/tests.py | 17 ++++-- 6 files changed, 123 insertions(+), 25 deletions(-) diff --git a/django_freeradius/models.py b/django_freeradius/models.py index ce54b5f..391659a 100644 --- a/django_freeradius/models.py +++ b/django_freeradius/models.py @@ -8,6 +8,18 @@ AbstractRadiusReply, AbstractRadiusUserGroup) +RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") +RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") +RadiusGroupUsers = swapper.load_model("django_freeradius", "RadiusGroupUsers") +RadiusUserGroup = swapper.load_model("django_freeradius", "RadiusUserGroup") +RadiusReply = swapper.load_model("django_freeradius", "RadiusReply") +RadiusCheck = swapper.load_model("django_freeradius", "RadiusCheck") +RadiusPostAuthentication = swapper.load_model("django_freeradius", "RadiusPostAuthentication") +Nas = swapper.load_model("django_freeradius", "Nas") +RadiusAccounting = swapper.load_model("django_freeradius", "RadiusAccounting") +RadiusGroup = swapper.load_model("django_freeradius", "RadiusGroup") + + class RadiusGroup(AbstractRadiusGroup): class Meta(AbstractRadiusGroup.Meta): diff --git a/django_freeradius/tests/tests_admin.py b/django_freeradius/tests/tests_admin.py index d71d386..62ac03f 100644 --- a/django_freeradius/tests/tests_admin.py +++ b/django_freeradius/tests/tests_admin.py @@ -1,10 +1,19 @@ from django.contrib.auth.models import User from django.test import Client, TestCase from django.urls import reverse - -from ..models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, - RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, - RadiusPostAuthentication, RadiusReply, RadiusUserGroup) +import swapper + + +RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") +RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") +RadiusGroupUsers = swapper.load_model("django_freeradius", "RadiusGroupUsers") +RadiusUserGroup = swapper.load_model("django_freeradius", "RadiusUserGroup") +RadiusReply = swapper.load_model("django_freeradius", "RadiusReply") +RadiusCheck = swapper.load_model("django_freeradius", "RadiusCheck") +RadiusPostAuthentication = swapper.load_model("django_freeradius", "RadiusPostAuthentication") +Nas = swapper.load_model("django_freeradius", "Nas") +RadiusAccounting = swapper.load_model("django_freeradius", "RadiusAccounting") +RadiusGroup = swapper.load_model("django_freeradius", "RadiusGroup") class UserTest(TestCase): diff --git a/django_freeradius/tests/tests_models.py b/django_freeradius/tests/tests_models.py index b5804f2..e60d878 100644 --- a/django_freeradius/tests/tests_models.py +++ b/django_freeradius/tests/tests_models.py @@ -1,8 +1,16 @@ from django.test import TestCase - -from ..models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, - RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, - RadiusPostAuthentication, RadiusReply, RadiusUserGroup) +import swapper + +RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") +RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") +RadiusGroupUsers = swapper.load_model("django_freeradius", "RadiusGroupUsers") +RadiusUserGroup = swapper.load_model("django_freeradius", "RadiusUserGroup") +RadiusReply = swapper.load_model("django_freeradius", "RadiusReply") +RadiusCheck = swapper.load_model("django_freeradius", "RadiusCheck") +RadiusPostAuthentication = swapper.load_model("django_freeradius", "RadiusPostAuthentication") +Nas = swapper.load_model("django_freeradius", "Nas") +RadiusAccounting = swapper.load_model("django_freeradius", "RadiusAccounting") +RadiusGroup = swapper.load_model("django_freeradius", "RadiusGroup") class NasModelTest(TestCase): diff --git a/tests/sample_radius/admin.py b/tests/sample_radius/admin.py index cc8b141..e9cd337 100644 --- a/tests/sample_radius/admin.py +++ b/tests/sample_radius/admin.py @@ -1,14 +1,63 @@ from django.contrib import admin +import swapper -from django_freeradius.admin import (AbstractNasAdmin, AbstractRadiusAccountingAdmin, - AbstractRadiusCheckAdmin, AbstractRadiusGroupAdmin, - AbstractRadiusGroupCheckAdmin, - AbstractRadiusGroupReplyAdmin, - AbstractRadiusGroupUsersAdmin, - AbstractRadiusPostAuthenticationAdmin, - AbstractRadiusReplyAdmin, - AbstractRadiusUserGroupAdmin) - -from django_freeradius.models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, - RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, - RadiusPostAuthentication, RadiusReply, RadiusUserGroup) +RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") +RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") +RadiusGroupUsers = swapper.load_model("django_freeradius", "RadiusGroupUsers") +RadiusUserGroup = swapper.load_model("django_freeradius", "RadiusUserGroup") +RadiusReply = swapper.load_model("django_freeradius", "RadiusReply") +RadiusCheck = swapper.load_model("django_freeradius", "RadiusCheck") +RadiusPostAuthentication = swapper.load_model("django_freeradius", "RadiusPostAuthentication") +Nas = swapper.load_model("django_freeradius", "Nas") +RadiusAccounting = swapper.load_model("django_freeradius", "RadiusAccounting") +RadiusGroup = swapper.load_model("django_freeradius", "RadiusGroup") + + +@admin.register(RadiusGroup) +class RadiusGroupAdmin(AbstractRadiusGroupAdmin): + model = RadiusGroup + + +@admin.register(RadiusGroupUsers) +class RadiusGroupUsersAdmin(AbstractRadiusGroupUsersAdmin): + model = RadiusGroupUsers + + +@admin.register(RadiusCheck) +class RadiusCheckAdmin(AbstractRadiusCheckAdmin): + model = RadiusCheck + + +@admin.register(RadiusReply) +class RadiusReplyAdmin(AbstractRadiusReplyAdmin): + model = RadiusReply + + +@admin.register(RadiusAccounting) +class RadiusAccountingAdmin(AbstractRadiusAccountingAdmin): + model = RadiusAccounting + + +@admin.register(Nas) +class NasAdmin(AbstractNasAdmin): + model = Nas + + +@admin.register(RadiusUserGroup) +class RadiusUserGroupAdmin(AbstractRadiusUserGroupAdmin): + model = RadiusUserGroup + + +@admin.register(RadiusGroupReply) +class RadiusGroupReplyAdmin(AbstractRadiusGroupReplyAdmin): + model = RadiusGroupReply + + +@admin.register(RadiusGroupCheck) +class RadiusGroupCheckAdmin(AbstractRadiusGroupCheckAdmin): + model = RadiusGroupCheck + + +@admin.register(RadiusPostAuthentication) +class RadiusPostAuthenticationAdmin(AbstractRadiusPostAuthenticationAdmin): + model = RadiusPostAuthentication diff --git a/tests/sample_radius/models.py b/tests/sample_radius/models.py index 75288bf..a7aa25e 100644 --- a/tests/sample_radius/models.py +++ b/tests/sample_radius/models.py @@ -1,6 +1,6 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ - +import swapper from django_freeradius.models import (AbstractNas, AbstractRadiusAccounting, AbstractRadiusCheck, AbstractRadiusGroup, AbstractRadiusGroupCheck, AbstractRadiusGroupReply, @@ -8,6 +8,17 @@ AbstractRadiusPostAuthentication, AbstractRadiusReply, AbstractRadiusUserGroup) +RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") +RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") +RadiusGroupUsers = swapper.load_model("django_freeradius", "RadiusGroupUsers") +RadiusUserGroup = swapper.load_model("django_freeradius", "RadiusUserGroup") +RadiusReply = swapper.load_model("django_freeradius", "RadiusReply") +RadiusCheck = swapper.load_model("django_freeradius", "RadiusCheck") +RadiusPostAuthentication = swapper.load_model("django_freeradius", "RadiusPostAuthentication") +Nas = swapper.load_model("django_freeradius", "Nas") +RadiusAccounting = swapper.load_model("django_freeradius", "RadiusAccounting") +RadiusGroup = swapper.load_model("django_freeradius", "RadiusGroup") + class RadiusGroup(AbstractRadiusGroup): details = models.CharField( diff --git a/tests/sample_radius/tests.py b/tests/sample_radius/tests.py index 0171a36..3d4db15 100644 --- a/tests/sample_radius/tests.py +++ b/tests/sample_radius/tests.py @@ -2,10 +2,19 @@ from django.contrib.auth.models import User from django.test import Client from django.urls import reverse - -from .models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, - RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, - RadiusPostAuthentication, RadiusReply, RadiusUserGroup) +import swapper + + +RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") +RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") +RadiusGroupUsers = swapper.load_model("django_freeradius", "RadiusGroupUsers") +RadiusUserGroup = swapper.load_model("django_freeradius", "RadiusUserGroup") +RadiusReply = swapper.load_model("django_freeradius", "RadiusReply") +RadiusCheck = swapper.load_model("django_freeradius", "RadiusCheck") +RadiusPostAuthentication = swapper.load_model("django_freeradius", "RadiusPostAuthentication") +Nas = swapper.load_model("django_freeradius", "Nas") +RadiusAccounting = swapper.load_model("django_freeradius", "RadiusAccounting") +RadiusGroup = swapper.load_model("django_freeradius", "RadiusGroup") class NasModelTest(TestCase): From 79d5d2df2accfcbd99cb777141cf9ca2d95b967b Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Wed, 21 Jun 2017 15:49:57 +0200 Subject: [PATCH 17/31] [general] added modifications to test application --- django_freeradius/models.py | 12 ------ django_freeradius/tests/tests_admin.py | 2 +- tests/sample_radius/admin.py | 52 +------------------------- tests/sample_radius/models.py | 12 ------ tests/sample_radius/tests.py | 26 +++++++------ tests/settings.py | 9 +---- 6 files changed, 18 insertions(+), 95 deletions(-) diff --git a/django_freeradius/models.py b/django_freeradius/models.py index 391659a..ce54b5f 100644 --- a/django_freeradius/models.py +++ b/django_freeradius/models.py @@ -8,18 +8,6 @@ AbstractRadiusReply, AbstractRadiusUserGroup) -RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") -RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") -RadiusGroupUsers = swapper.load_model("django_freeradius", "RadiusGroupUsers") -RadiusUserGroup = swapper.load_model("django_freeradius", "RadiusUserGroup") -RadiusReply = swapper.load_model("django_freeradius", "RadiusReply") -RadiusCheck = swapper.load_model("django_freeradius", "RadiusCheck") -RadiusPostAuthentication = swapper.load_model("django_freeradius", "RadiusPostAuthentication") -Nas = swapper.load_model("django_freeradius", "Nas") -RadiusAccounting = swapper.load_model("django_freeradius", "RadiusAccounting") -RadiusGroup = swapper.load_model("django_freeradius", "RadiusGroup") - - class RadiusGroup(AbstractRadiusGroup): class Meta(AbstractRadiusGroup.Meta): diff --git a/django_freeradius/tests/tests_admin.py b/django_freeradius/tests/tests_admin.py index 62ac03f..2771fee 100644 --- a/django_freeradius/tests/tests_admin.py +++ b/django_freeradius/tests/tests_admin.py @@ -105,7 +105,7 @@ def test_users_accounting(self): User.objects.create_superuser(username='gino', password='cic', email='giggi_vv@gmail.it') ola = RadiusAccounting.objects.create( acct_unique_id='-2', user_name='bob', nas_ip_address='ff', acct_start_time='2017-06-10 10:50:00', - acct_stop_time='2017-06-10 12:10:00', acct_session_time='5', acct_authentic='kj', + acct_stop_time='2017-06-10 11:50:00', acct_session_time='5', acct_authentic='kj', connection_info_start='f', connection_info_stop='hgh', acct_input_octets='1', acct_output_octets='4', rad_acct_id='123') self.client.login(username='gino', password='cic') diff --git a/tests/sample_radius/admin.py b/tests/sample_radius/admin.py index e9cd337..afe2983 100644 --- a/tests/sample_radius/admin.py +++ b/tests/sample_radius/admin.py @@ -1,4 +1,4 @@ -from django.contrib import admin +# from django.contrib import admin import swapper RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") @@ -11,53 +11,3 @@ Nas = swapper.load_model("django_freeradius", "Nas") RadiusAccounting = swapper.load_model("django_freeradius", "RadiusAccounting") RadiusGroup = swapper.load_model("django_freeradius", "RadiusGroup") - - -@admin.register(RadiusGroup) -class RadiusGroupAdmin(AbstractRadiusGroupAdmin): - model = RadiusGroup - - -@admin.register(RadiusGroupUsers) -class RadiusGroupUsersAdmin(AbstractRadiusGroupUsersAdmin): - model = RadiusGroupUsers - - -@admin.register(RadiusCheck) -class RadiusCheckAdmin(AbstractRadiusCheckAdmin): - model = RadiusCheck - - -@admin.register(RadiusReply) -class RadiusReplyAdmin(AbstractRadiusReplyAdmin): - model = RadiusReply - - -@admin.register(RadiusAccounting) -class RadiusAccountingAdmin(AbstractRadiusAccountingAdmin): - model = RadiusAccounting - - -@admin.register(Nas) -class NasAdmin(AbstractNasAdmin): - model = Nas - - -@admin.register(RadiusUserGroup) -class RadiusUserGroupAdmin(AbstractRadiusUserGroupAdmin): - model = RadiusUserGroup - - -@admin.register(RadiusGroupReply) -class RadiusGroupReplyAdmin(AbstractRadiusGroupReplyAdmin): - model = RadiusGroupReply - - -@admin.register(RadiusGroupCheck) -class RadiusGroupCheckAdmin(AbstractRadiusGroupCheckAdmin): - model = RadiusGroupCheck - - -@admin.register(RadiusPostAuthentication) -class RadiusPostAuthenticationAdmin(AbstractRadiusPostAuthenticationAdmin): - model = RadiusPostAuthentication diff --git a/tests/sample_radius/models.py b/tests/sample_radius/models.py index a7aa25e..b083f64 100644 --- a/tests/sample_radius/models.py +++ b/tests/sample_radius/models.py @@ -1,6 +1,5 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ -import swapper from django_freeradius.models import (AbstractNas, AbstractRadiusAccounting, AbstractRadiusCheck, AbstractRadiusGroup, AbstractRadiusGroupCheck, AbstractRadiusGroupReply, @@ -8,17 +7,6 @@ AbstractRadiusPostAuthentication, AbstractRadiusReply, AbstractRadiusUserGroup) -RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") -RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") -RadiusGroupUsers = swapper.load_model("django_freeradius", "RadiusGroupUsers") -RadiusUserGroup = swapper.load_model("django_freeradius", "RadiusUserGroup") -RadiusReply = swapper.load_model("django_freeradius", "RadiusReply") -RadiusCheck = swapper.load_model("django_freeradius", "RadiusCheck") -RadiusPostAuthentication = swapper.load_model("django_freeradius", "RadiusPostAuthentication") -Nas = swapper.load_model("django_freeradius", "Nas") -RadiusAccounting = swapper.load_model("django_freeradius", "RadiusAccounting") -RadiusGroup = swapper.load_model("django_freeradius", "RadiusGroup") - class RadiusGroup(AbstractRadiusGroup): details = models.CharField( diff --git a/tests/sample_radius/tests.py b/tests/sample_radius/tests.py index 3d4db15..38be6f0 100644 --- a/tests/sample_radius/tests.py +++ b/tests/sample_radius/tests.py @@ -2,6 +2,7 @@ from django.contrib.auth.models import User from django.test import Client from django.urls import reverse + import swapper @@ -107,7 +108,7 @@ def test_users_nas(self): nas_name='fiore', short_name='ff', type='cisco', secret='d', ports='22', community='vmv', description='ciao', server='jsjs', details='nb') self.client.login(username='gino', password='cc') - resp = self.client.get(reverse('admin:django_freeradius_nas_change', args=[obj.pk])) + resp = self.client.get(reverse('admin:sample_radius_nas_change', args=[obj.pk])) self.assertContains(resp, 'ok') def test_users_check(self): @@ -115,7 +116,7 @@ def test_users_check(self): obj = RadiusCheck.objects.create( user_name='bob', attribute='Cleartext-Password', op=':=', value='passbob', details='nb') self.client.login(username='gino', password='cic') - resp = self.client.get(reverse('admin:django_freeradius_radiuscheck_change', args=[obj.pk])) + resp = self.client.get(reverse('admin:sample_radius_radiuscheck_change', args=[obj.pk])) self.assertContains(resp, 'ok') def test_users_reply(self): @@ -123,7 +124,7 @@ def test_users_reply(self): obj = RadiusReply.objects.create( user_name='bob', attribute='Cleartext-Password', op=':=', value='passbob', details='nb') self.client.login(username='gino', password='cic') - resp = self.client.get(reverse('admin:django_freeradius_radiusreply_change', args=[obj.pk])) + resp = self.client.get(reverse('admin:sample_radius_radiusreply_change', args=[obj.pk])) self.assertContains(resp, 'ok') def test_users_group_reply(self): @@ -131,7 +132,7 @@ def test_users_group_reply(self): obj = RadiusGroupReply.objects.create( group_name='students', attribute='Cleartext-Password', op=':=', value='PPP', details='nb') self.client.login(username='gino', password='cic') - resp = self.client.get(reverse('admin:django_freeradius_radiusgroupreply_change', args=[obj.pk])) + resp = self.client.get(reverse('admin:sample_radius_radiusgroupreply_change', args=[obj.pk])) self.assertContains(resp, 'ok') def test_users_group_check(self): @@ -139,7 +140,7 @@ def test_users_group_check(self): obj = RadiusGroupCheck.objects.create( group_name='students', attribute='Cleartext-Password', op=':=', value='PPP', details='nb') self.client.login(username='fiorella', password='ciao') - resp = self.client.get(reverse('admin:django_freeradius_radiusgroupcheck_change', args=[obj.pk])) + resp = self.client.get(reverse('admin:sample_radius_radiusgroupcheck_change', args=[obj.pk])) self.assertContains(resp, 'ok') def test_users_group(self): @@ -148,7 +149,7 @@ def test_users_group(self): id='870df8e8-3107-4487-8316-81e089b8c2cf', group_name='students', priority='1', creation_date='2017-09-02', modification_date='2017-08-03', notes='hh', details='nb') self.client.login(username='gino', password='cic') - resp = self.client.get(reverse('admin:django_freeradius_radiusgroup_change', args=[obj.pk])) + resp = self.client.get(reverse('admin:sample_radius_radiusgroup_change', args=[obj.pk])) self.assertContains(resp, 'ok') def test_users_usersgroup(self): @@ -156,7 +157,7 @@ def test_users_usersgroup(self): obj = RadiusUserGroup.objects.create( user_name='bob', group_name='students', priority='1', details='nb') self.client.login(username='gino', password='cic') - resp = self.client.get(reverse('admin:django_freeradius_radiususergroup_change', args=[obj.pk])) + resp = self.client.get(reverse('admin:sample_radius_radiususergroup_change', args=[obj.pk])) self.assertContains(resp, 'ok') def test_users_groupusers(self): @@ -170,18 +171,19 @@ def test_users_groupusers(self): obj.radius_reply.add(reply) obj.radius_check.add(check) self.client.login(username='gino', password='cic') - resp = self.client.get(reverse('admin:django_freeradius_radiusgroupusers_change', args=[obj.pk])) + resp = self.client.get(reverse('admin:sample_radius_radiusgroupusers_change', args=[obj.pk])) self.assertContains(resp, 'ok') def test_users_accounting(self): User.objects.create_superuser(username='gino', password='cic', email='giggi_vv@gmail.it') ola = RadiusAccounting.objects.create( - acct_unique_id='-2', user_name='bob', nas_ip_address='ff', acct_start_time='2017-06-10 10:50:00', - acct_stop_time='2017-06-10 12:10:00', acct_session_time='5', acct_authentic='kj', + acct_unique_id='-2', user_name='bob', nas_ip_address='ff', + acct_start_time='2012-09-04 06:00:00.000000-01:00', + acct_stop_time='2012-09-04 06:00:00.000000-08:00', acct_session_time='5', acct_authentic='kj', connection_info_start='f', connection_info_stop='hgh', acct_input_octets='1', acct_output_octets='4', rad_acct_id='123', details='nb') self.client.login(username='gino', password='cic') - resp = self.client.get(reverse('admin:django_freeradius_radiusaccounting_change', args=[ola.pk])) + resp = self.client.get(reverse('admin:sample_radius_radiusaccounting_change', args=[ola.pk])) self.assertContains(resp, 'ok') def test_users_postauthentication(self): @@ -190,5 +192,5 @@ def test_users_postauthentication(self): user_name='gino', password='ciao', reply='ghdhd', auth_date='2017-09-02', details='nb') self.client.login(username='gino', password='cic') resp = self.client.get(reverse( - 'admin:django_freeradius_radiuspostauthentication_change', args=[olu.pk])) + 'admin:sample_radius_radiuspostauthentication_change', args=[olu.pk])) self.assertContains(resp, 'ok') diff --git a/tests/settings.py b/tests/settings.py index 84d3de1..6fb0a8e 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -24,13 +24,8 @@ ALLOWED_HOSTS = [] DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.mysql', - 'NAME': 'sample_radius', - 'USER': 'root', - 'PASSWORD': 'milafiore91', - }, - #'default': env.db(default='sqlite:///django-freeradius.db'), + + 'default': env.db(default='sqlite:///django-freeradius.db'), } SECRET_KEY = 'fn)t*+$)ugeyip6-#txyy$5wf2ervc0d2n#h)qb)y5@ly$t*@w' From 7c29a4d3d9cf3285366bb134a2077a48505df783 Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Wed, 21 Jun 2017 19:12:53 +0200 Subject: [PATCH 18/31] [general] clean code --- django_freeradius/admin.py | 15 +---- django_freeradius/migrations/0001_initial.py | 5 +- django_freeradius/tests/tests_admin.py | 17 ++--- django_freeradius/tests/tests_models.py | 16 ++--- tests/sample_radius/admin.py | 63 ++++++++++++++++++- .../sample_radius/migrations/0001_initial.py | 4 +- tests/sample_radius/models.py | 7 ++- tests/sample_radius/tests.py | 7 +-- 8 files changed, 85 insertions(+), 49 deletions(-) diff --git a/django_freeradius/admin.py b/django_freeradius/admin.py index 63f268c..e718f80 100644 --- a/django_freeradius/admin.py +++ b/django_freeradius/admin.py @@ -1,4 +1,3 @@ -import swapper from django.contrib import admin from .base.admin import (AbstractNasAdmin, AbstractRadiusAccountingAdmin, @@ -9,17 +8,9 @@ AbstractRadiusPostAuthenticationAdmin, AbstractRadiusReplyAdmin, AbstractRadiusUserGroupAdmin) - -RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") -RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") -RadiusGroupUsers = swapper.load_model("django_freeradius", "RadiusGroupUsers") -RadiusUserGroup = swapper.load_model("django_freeradius", "RadiusUserGroup") -RadiusReply = swapper.load_model("django_freeradius", "RadiusReply") -RadiusCheck = swapper.load_model("django_freeradius", "RadiusCheck") -RadiusPostAuthentication = swapper.load_model("django_freeradius", "RadiusPostAuthentication") -Nas = swapper.load_model("django_freeradius", "Nas") -RadiusAccounting = swapper.load_model("django_freeradius", "RadiusAccounting") -RadiusGroup = swapper.load_model("django_freeradius", "RadiusGroup") +from .models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, + RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, + RadiusPostAuthentication, RadiusReply, RadiusUserGroup) @admin.register(RadiusGroup) diff --git a/django_freeradius/migrations/0001_initial.py b/django_freeradius/migrations/0001_initial.py index fb6a416..efe7cc0 100644 --- a/django_freeradius/migrations/0001_initial.py +++ b/django_freeradius/migrations/0001_initial.py @@ -2,11 +2,12 @@ # Generated by Django 1.11.1 on 2017-06-20 15:40 from __future__ import unicode_literals -from django.conf import settings -from django.db import migrations, models import django.utils.timezone import model_utils.fields import swapper +from django.conf import settings +from django.db import migrations, models + class Migration(migrations.Migration): diff --git a/django_freeradius/tests/tests_admin.py b/django_freeradius/tests/tests_admin.py index 2771fee..a537ca6 100644 --- a/django_freeradius/tests/tests_admin.py +++ b/django_freeradius/tests/tests_admin.py @@ -1,19 +1,10 @@ from django.contrib.auth.models import User from django.test import Client, TestCase from django.urls import reverse -import swapper - - -RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") -RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") -RadiusGroupUsers = swapper.load_model("django_freeradius", "RadiusGroupUsers") -RadiusUserGroup = swapper.load_model("django_freeradius", "RadiusUserGroup") -RadiusReply = swapper.load_model("django_freeradius", "RadiusReply") -RadiusCheck = swapper.load_model("django_freeradius", "RadiusCheck") -RadiusPostAuthentication = swapper.load_model("django_freeradius", "RadiusPostAuthentication") -Nas = swapper.load_model("django_freeradius", "Nas") -RadiusAccounting = swapper.load_model("django_freeradius", "RadiusAccounting") -RadiusGroup = swapper.load_model("django_freeradius", "RadiusGroup") + +from ..models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, + RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, + RadiusPostAuthentication, RadiusReply, RadiusUserGroup) class UserTest(TestCase): diff --git a/django_freeradius/tests/tests_models.py b/django_freeradius/tests/tests_models.py index e60d878..b5804f2 100644 --- a/django_freeradius/tests/tests_models.py +++ b/django_freeradius/tests/tests_models.py @@ -1,16 +1,8 @@ from django.test import TestCase -import swapper - -RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") -RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") -RadiusGroupUsers = swapper.load_model("django_freeradius", "RadiusGroupUsers") -RadiusUserGroup = swapper.load_model("django_freeradius", "RadiusUserGroup") -RadiusReply = swapper.load_model("django_freeradius", "RadiusReply") -RadiusCheck = swapper.load_model("django_freeradius", "RadiusCheck") -RadiusPostAuthentication = swapper.load_model("django_freeradius", "RadiusPostAuthentication") -Nas = swapper.load_model("django_freeradius", "Nas") -RadiusAccounting = swapper.load_model("django_freeradius", "RadiusAccounting") -RadiusGroup = swapper.load_model("django_freeradius", "RadiusGroup") + +from ..models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, + RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, + RadiusPostAuthentication, RadiusReply, RadiusUserGroup) class NasModelTest(TestCase): diff --git a/tests/sample_radius/admin.py b/tests/sample_radius/admin.py index afe2983..76d9d75 100644 --- a/tests/sample_radius/admin.py +++ b/tests/sample_radius/admin.py @@ -1,5 +1,16 @@ -# from django.contrib import admin import swapper +from django.contrib import admin + +from django_freeradius.admin import (AbstractNasAdmin, + AbstractRadiusAccountingAdmin, + AbstractRadiusCheckAdmin, + AbstractRadiusGroupAdmin, + AbstractRadiusGroupCheckAdmin, + AbstractRadiusGroupReplyAdmin, + AbstractRadiusGroupUsersAdmin, + AbstractRadiusPostAuthenticationAdmin, + AbstractRadiusReplyAdmin, + AbstractRadiusUserGroupAdmin) RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") @@ -11,3 +22,53 @@ Nas = swapper.load_model("django_freeradius", "Nas") RadiusAccounting = swapper.load_model("django_freeradius", "RadiusAccounting") RadiusGroup = swapper.load_model("django_freeradius", "RadiusGroup") + + +@admin.register(RadiusGroup) +class RadiusGroupAdmin(AbstractRadiusGroupAdmin): + model = RadiusGroup + + +@admin.register(RadiusGroupUsers) +class RadiusGroupUsersAdmin(AbstractRadiusGroupUsersAdmin): + model = RadiusGroupUsers + + +@admin.register(RadiusCheck) +class RadiusCheckAdmin(AbstractRadiusCheckAdmin): + model = RadiusCheck + + +@admin.register(RadiusReply) +class RadiusReplyAdmin(AbstractRadiusReplyAdmin): + model = RadiusReply + + +@admin.register(RadiusAccounting) +class RadiusAccountingAdmin(AbstractRadiusAccountingAdmin): + model = RadiusAccounting + + +@admin.register(Nas) +class NasAdmin(AbstractNasAdmin): + model = Nas + + +@admin.register(RadiusUserGroup) +class RadiusUserGroupAdmin(AbstractRadiusUserGroupAdmin): + model = RadiusUserGroup + + +@admin.register(RadiusGroupReply) +class RadiusGroupReplyAdmin(AbstractRadiusGroupReplyAdmin): + model = RadiusGroupReply + + +@admin.register(RadiusGroupCheck) +class RadiusGroupCheckAdmin(AbstractRadiusGroupCheckAdmin): + model = RadiusGroupCheck + + +@admin.register(RadiusPostAuthentication) +class RadiusPostAuthenticationAdmin(AbstractRadiusPostAuthenticationAdmin): + model = RadiusPostAuthentication diff --git a/tests/sample_radius/migrations/0001_initial.py b/tests/sample_radius/migrations/0001_initial.py index 6f645b9..8100c4f 100644 --- a/tests/sample_radius/migrations/0001_initial.py +++ b/tests/sample_radius/migrations/0001_initial.py @@ -2,10 +2,10 @@ # Generated by Django 1.11.1 on 2017-06-20 17:35 from __future__ import unicode_literals -from django.conf import settings -from django.db import migrations, models import django.utils.timezone import model_utils.fields +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/tests/sample_radius/models.py b/tests/sample_radius/models.py index b083f64..4745191 100644 --- a/tests/sample_radius/models.py +++ b/tests/sample_radius/models.py @@ -1,11 +1,14 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ + from django_freeradius.models import (AbstractNas, AbstractRadiusAccounting, AbstractRadiusCheck, AbstractRadiusGroup, - AbstractRadiusGroupCheck, AbstractRadiusGroupReply, + AbstractRadiusGroupCheck, + AbstractRadiusGroupReply, AbstractRadiusGroupUsers, AbstractRadiusPostAuthentication, - AbstractRadiusReply, AbstractRadiusUserGroup) + AbstractRadiusReply, + AbstractRadiusUserGroup) class RadiusGroup(AbstractRadiusGroup): diff --git a/tests/sample_radius/tests.py b/tests/sample_radius/tests.py index 38be6f0..fff6847 100644 --- a/tests/sample_radius/tests.py +++ b/tests/sample_radius/tests.py @@ -1,11 +1,8 @@ -from django.test import TestCase +import swapper from django.contrib.auth.models import User -from django.test import Client +from django.test import Client, TestCase from django.urls import reverse -import swapper - - RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") RadiusGroupUsers = swapper.load_model("django_freeradius", "RadiusGroupUsers") From eaf974c30cc254aaa608f23c636ac1b906001503 Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Thu, 22 Jun 2017 16:44:34 +0200 Subject: [PATCH 19/31] [general] clean code --- .travis.yml | 2 ++ django_freeradius/admin.py | 18 +++++++----------- django_freeradius/models.py | 9 +++------ django_freeradius/tests/tests_admin.py | 8 +++++--- django_freeradius/tests/tests_models.py | 8 +++++--- tests/sample_radius/admin.py | 9 ++++----- tests/sample_radius/models.py | 6 ++---- tests/sample_radius/tests.py | 1 + tests/settings.py | 25 ++++++++++++++----------- 9 files changed, 43 insertions(+), 43 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7eed38c..240553f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,8 @@ env: - DJANGO="django>=1.11,<1.12" DATABASE_URL='mysql://root@127.0.0.1/freeradius_test' - DJANGO="django>=1.10,<1.11" DATABASE_URL='postgres://postgres@127.0.0.1/freeradius_test' - DJANGO="django>=1.11,<1.12" DATABASE_URL='postgres://postgres@127.0.0.1/freeradius_test' + - DJANGO="django>=1.10,<1.11" DATABASE_URL='mysql://mysql@127.0.0.1/sample_test' SAMPLE_APP=1 + - DJANGO="django>=1.11,<1.12" DATABASE_URL='mysql://mysql@127.0.0.1/sample_test' SAMPLE_APP=1 before_install: - pip install --no-cache-dir -U -r requirements-test.txt diff --git a/django_freeradius/admin.py b/django_freeradius/admin.py index e718f80..79f7f29 100644 --- a/django_freeradius/admin.py +++ b/django_freeradius/admin.py @@ -1,16 +1,12 @@ from django.contrib import admin -from .base.admin import (AbstractNasAdmin, AbstractRadiusAccountingAdmin, - AbstractRadiusCheckAdmin, AbstractRadiusGroupAdmin, - AbstractRadiusGroupCheckAdmin, - AbstractRadiusGroupReplyAdmin, - AbstractRadiusGroupUsersAdmin, - AbstractRadiusPostAuthenticationAdmin, - AbstractRadiusReplyAdmin, - AbstractRadiusUserGroupAdmin) -from .models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, - RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, - RadiusPostAuthentication, RadiusReply, RadiusUserGroup) +from .base.admin import (AbstractNasAdmin, AbstractRadiusAccountingAdmin, AbstractRadiusCheckAdmin, + AbstractRadiusGroupAdmin, AbstractRadiusGroupCheckAdmin, + AbstractRadiusGroupReplyAdmin, AbstractRadiusGroupUsersAdmin, + AbstractRadiusPostAuthenticationAdmin, AbstractRadiusReplyAdmin, + AbstractRadiusUserGroupAdmin,) +from .models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, RadiusGroupCheck, RadiusGroupReply, + RadiusGroupUsers, RadiusPostAuthentication, RadiusReply, RadiusUserGroup,) @admin.register(RadiusGroup) diff --git a/django_freeradius/models.py b/django_freeradius/models.py index ce54b5f..fdfe5e4 100644 --- a/django_freeradius/models.py +++ b/django_freeradius/models.py @@ -1,11 +1,8 @@ import swapper -from .base.models import (AbstractNas, AbstractRadiusAccounting, - AbstractRadiusCheck, AbstractRadiusGroup, - AbstractRadiusGroupCheck, AbstractRadiusGroupReply, - AbstractRadiusGroupUsers, - AbstractRadiusPostAuthentication, - AbstractRadiusReply, AbstractRadiusUserGroup) +from .base.models import (AbstractNas, AbstractRadiusAccounting, AbstractRadiusCheck, AbstractRadiusGroup, + AbstractRadiusGroupCheck, AbstractRadiusGroupReply, AbstractRadiusGroupUsers, + AbstractRadiusPostAuthentication, AbstractRadiusReply, AbstractRadiusUserGroup,) class RadiusGroup(AbstractRadiusGroup): diff --git a/django_freeradius/tests/tests_admin.py b/django_freeradius/tests/tests_admin.py index a537ca6..325929f 100644 --- a/django_freeradius/tests/tests_admin.py +++ b/django_freeradius/tests/tests_admin.py @@ -1,12 +1,14 @@ +from unittest import skipIf + from django.contrib.auth.models import User from django.test import Client, TestCase from django.urls import reverse -from ..models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, - RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, - RadiusPostAuthentication, RadiusReply, RadiusUserGroup) +from ..models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, RadiusGroupCheck, RadiusGroupReply, + RadiusGroupUsers, RadiusPostAuthentication, RadiusReply, RadiusUserGroup,) +@skipIf(True, "env = DATABASE_URL='mysql://mysql@127.0.0.1/sample_test' SAMPLE_APP=1") class UserTest(TestCase): def setUp(self): diff --git a/django_freeradius/tests/tests_models.py b/django_freeradius/tests/tests_models.py index b5804f2..9e05a2b 100644 --- a/django_freeradius/tests/tests_models.py +++ b/django_freeradius/tests/tests_models.py @@ -1,10 +1,12 @@ +from unittest import skipIf + from django.test import TestCase -from ..models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, - RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, - RadiusPostAuthentication, RadiusReply, RadiusUserGroup) +from ..models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, RadiusGroupCheck, RadiusGroupReply, + RadiusGroupUsers, RadiusPostAuthentication, RadiusReply, RadiusUserGroup,) +@skipIf(True, "env = DATABASE_URL='mysql://mysql@127.0.0.1/sample_test' SAMPLE_APP=1") class NasModelTest(TestCase): def test_string_representation(self): diff --git a/tests/sample_radius/admin.py b/tests/sample_radius/admin.py index 76d9d75..065c056 100644 --- a/tests/sample_radius/admin.py +++ b/tests/sample_radius/admin.py @@ -1,10 +1,8 @@ -import swapper from django.contrib import admin +import swapper -from django_freeradius.admin import (AbstractNasAdmin, - AbstractRadiusAccountingAdmin, - AbstractRadiusCheckAdmin, - AbstractRadiusGroupAdmin, +from django_freeradius.admin import (AbstractNasAdmin, AbstractRadiusAccountingAdmin, + AbstractRadiusCheckAdmin, AbstractRadiusGroupAdmin, AbstractRadiusGroupCheckAdmin, AbstractRadiusGroupReplyAdmin, AbstractRadiusGroupUsersAdmin, @@ -12,6 +10,7 @@ AbstractRadiusReplyAdmin, AbstractRadiusUserGroupAdmin) + RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") RadiusGroupUsers = swapper.load_model("django_freeradius", "RadiusGroupUsers") diff --git a/tests/sample_radius/models.py b/tests/sample_radius/models.py index 4745191..75288bf 100644 --- a/tests/sample_radius/models.py +++ b/tests/sample_radius/models.py @@ -3,12 +3,10 @@ from django_freeradius.models import (AbstractNas, AbstractRadiusAccounting, AbstractRadiusCheck, AbstractRadiusGroup, - AbstractRadiusGroupCheck, - AbstractRadiusGroupReply, + AbstractRadiusGroupCheck, AbstractRadiusGroupReply, AbstractRadiusGroupUsers, AbstractRadiusPostAuthentication, - AbstractRadiusReply, - AbstractRadiusUserGroup) + AbstractRadiusReply, AbstractRadiusUserGroup) class RadiusGroup(AbstractRadiusGroup): diff --git a/tests/sample_radius/tests.py b/tests/sample_radius/tests.py index fff6847..70afab6 100644 --- a/tests/sample_radius/tests.py +++ b/tests/sample_radius/tests.py @@ -3,6 +3,7 @@ from django.test import Client, TestCase from django.urls import reverse + RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") RadiusGroupUsers = swapper.load_model("django_freeradius", "RadiusGroupUsers") diff --git a/tests/settings.py b/tests/settings.py index 6fb0a8e..d9be524 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -2,16 +2,18 @@ import environ -DJANGO_FREERADIUS_RADIUSREPLY_MODEL = "sample_radius.RadiusReply" -DJANGO_FREERADIUS_RADIUSGROUPREPLY_MODEL = "sample_radius.RadiusGroupReply" -DJANGO_FREERADIUS_RADIUSCHECK_MODEL = "sample_radius.RadiusCheck" -DJANGO_FREERADIUS_RADIUSGROUPCHECK_MODEL = "sample_radius.RadiusGroupCheck" -DJANGO_FREERADIUS_RADIUSACCOUNTING_MODEL = "sample_radius.RadiusAccounting" -DJANGO_FREERADIUS_NAS_MODEL = "sample_radius.Nas" -DJANGO_FREERADIUS_RADIUSGROUPUSERS_MODEL = "sample_radius.RadiusGroupUsers" -DJANGO_FREERADIUS_RADIUSUSERGROUP_MODEL = "sample_radius.RadiusUserGroup" -DJANGO_FREERADIUS_RADIUSPOSTAUTHENTICATION_MODEL = "sample_radius.RadiusPostAuthentication" -DJANGO_FREERADIUS_RADIUSGROUP_MODEL = "sample_radius.RadiusGroup" +if os.environ.get('SAMPLE_RADIUS', False): + INSTALLED_APPS.append('sample_radius') + DJANGO_FREERADIUS_RADIUSREPLY_MODEL = "sample_radius.RadiusReply" + DJANGO_FREERADIUS_RADIUSGROUPREPLY_MODEL = "sample_radius.RadiusGroupReply" + DJANGO_FREERADIUS_RADIUSCHECK_MODEL = "sample_radius.RadiusCheck" + DJANGO_FREERADIUS_RADIUSGROUPCHECK_MODEL = "sample_radius.RadiusGroupCheck" + DJANGO_FREERADIUS_RADIUSACCOUNTING_MODEL = "sample_radius.RadiusAccounting" + DJANGO_FREERADIUS_NAS_MODEL = "sample_radius.Nas" + DJANGO_FREERADIUS_RADIUSGROUPUSERS_MODEL = "sample_radius.RadiusGroupUsers" + DJANGO_FREERADIUS_RADIUSUSERGROUP_MODEL = "sample_radius.RadiusUserGroup" + DJANGO_FREERADIUS_RADIUSPOSTAUTHENTICATION_MODEL = "sample_radius.RadiusPostAuthentication" + DJANGO_FREERADIUS_RADIUSGROUP_MODEL = "sample_radius.RadiusGroup" BASE_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -38,7 +40,8 @@ 'django.contrib.staticfiles', 'django.contrib.admin', 'django_freeradius', - 'sample_radius', + + ] MIDDLEWARE_CLASSES = [ From 270fb5f4894893b41eb96e991c8b10426f928076 Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Thu, 22 Jun 2017 23:02:20 +0200 Subject: [PATCH 20/31] [general] added skipIf --- tests/sample_radius/tests.py | 6 +++++- tests/settings.py | 27 ++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/tests/sample_radius/tests.py b/tests/sample_radius/tests.py index 70afab6..d17bcaa 100644 --- a/tests/sample_radius/tests.py +++ b/tests/sample_radius/tests.py @@ -2,7 +2,8 @@ from django.contrib.auth.models import User from django.test import Client, TestCase from django.urls import reverse - +from unittest import skipIf +import os RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") @@ -16,6 +17,9 @@ RadiusGroup = swapper.load_model("django_freeradius", "RadiusGroup") +@skipIf(True, "env = DATABASE_URL='postgres://postgres@127.0.0.1/freeradius_test'") +@skipIf(True, "env = DATABASE_URL='mysql://root@127.0.0.1/freeradius_test'") + class NasModelTest(TestCase): def test_string_representation(self): diff --git a/tests/settings.py b/tests/settings.py index d9be524..4fe982c 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -2,18 +2,16 @@ import environ -if os.environ.get('SAMPLE_RADIUS', False): - INSTALLED_APPS.append('sample_radius') - DJANGO_FREERADIUS_RADIUSREPLY_MODEL = "sample_radius.RadiusReply" - DJANGO_FREERADIUS_RADIUSGROUPREPLY_MODEL = "sample_radius.RadiusGroupReply" - DJANGO_FREERADIUS_RADIUSCHECK_MODEL = "sample_radius.RadiusCheck" - DJANGO_FREERADIUS_RADIUSGROUPCHECK_MODEL = "sample_radius.RadiusGroupCheck" - DJANGO_FREERADIUS_RADIUSACCOUNTING_MODEL = "sample_radius.RadiusAccounting" - DJANGO_FREERADIUS_NAS_MODEL = "sample_radius.Nas" - DJANGO_FREERADIUS_RADIUSGROUPUSERS_MODEL = "sample_radius.RadiusGroupUsers" - DJANGO_FREERADIUS_RADIUSUSERGROUP_MODEL = "sample_radius.RadiusUserGroup" - DJANGO_FREERADIUS_RADIUSPOSTAUTHENTICATION_MODEL = "sample_radius.RadiusPostAuthentication" - DJANGO_FREERADIUS_RADIUSGROUP_MODEL = "sample_radius.RadiusGroup" +DJANGO_FREERADIUS_RADIUSREPLY_MODEL = "sample_radius.RadiusReply" +DJANGO_FREERADIUS_RADIUSGROUPREPLY_MODEL = "sample_radius.RadiusGroupReply" +DJANGO_FREERADIUS_RADIUSCHECK_MODEL = "sample_radius.RadiusCheck" +DJANGO_FREERADIUS_RADIUSGROUPCHECK_MODEL = "sample_radius.RadiusGroupCheck" +DJANGO_FREERADIUS_RADIUSACCOUNTING_MODEL = "sample_radius.RadiusAccounting" +DJANGO_FREERADIUS_NAS_MODEL = "sample_radius.Nas" +DJANGO_FREERADIUS_RADIUSGROUPUSERS_MODEL = "sample_radius.RadiusGroupUsers" +DJANGO_FREERADIUS_RADIUSUSERGROUP_MODEL = "sample_radius.RadiusUserGroup" +DJANGO_FREERADIUS_RADIUSPOSTAUTHENTICATION_MODEL = "sample_radius.RadiusPostAuthentication" +DJANGO_FREERADIUS_RADIUSGROUP_MODEL = "sample_radius.RadiusGroup" BASE_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -40,10 +38,13 @@ 'django.contrib.staticfiles', 'django.contrib.admin', 'django_freeradius', - + ] +if os.environ.get('SAMPLE_RADIUS', True): + INSTALLED_APPS.append('sample_radius') + MIDDLEWARE_CLASSES = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', From 9cd859bb8cbdfab9ea7dda820040fecdc3ede848 Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 24 Jun 2017 17:07:21 +0200 Subject: [PATCH 21/31] [tests] Correct error --- tests/sample_radius/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sample_radius/tests.py b/tests/sample_radius/tests.py index d17bcaa..f5142fe 100644 --- a/tests/sample_radius/tests.py +++ b/tests/sample_radius/tests.py @@ -3,7 +3,7 @@ from django.test import Client, TestCase from django.urls import reverse from unittest import skipIf -import os + RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") From 685ec3c96c0897df5604998818d98f355de96748 Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 24 Jun 2017 17:55:49 +0200 Subject: [PATCH 22/31] [general] added clean code --- django_freeradius/tests/tests_admin.py | 4 ++-- tests/sample_radius/tests.py | 8 +++---- tests/settings.py | 29 ++++++++++++-------------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/django_freeradius/tests/tests_admin.py b/django_freeradius/tests/tests_admin.py index 325929f..ef32daa 100644 --- a/django_freeradius/tests/tests_admin.py +++ b/django_freeradius/tests/tests_admin.py @@ -3,12 +3,12 @@ from django.contrib.auth.models import User from django.test import Client, TestCase from django.urls import reverse - +import os from ..models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, RadiusPostAuthentication, RadiusReply, RadiusUserGroup,) -@skipIf(True, "env = DATABASE_URL='mysql://mysql@127.0.0.1/sample_test' SAMPLE_APP=1") +@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') class UserTest(TestCase): def setUp(self): diff --git a/tests/sample_radius/tests.py b/tests/sample_radius/tests.py index f5142fe..919188d 100644 --- a/tests/sample_radius/tests.py +++ b/tests/sample_radius/tests.py @@ -2,8 +2,8 @@ from django.contrib.auth.models import User from django.test import Client, TestCase from django.urls import reverse -from unittest import skipIf - +from unittest import skipUnless +import os RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") @@ -17,9 +17,7 @@ RadiusGroup = swapper.load_model("django_freeradius", "RadiusGroup") -@skipIf(True, "env = DATABASE_URL='postgres://postgres@127.0.0.1/freeradius_test'") -@skipIf(True, "env = DATABASE_URL='mysql://root@127.0.0.1/freeradius_test'") - +@skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class NasModelTest(TestCase): def test_string_representation(self): diff --git a/tests/settings.py b/tests/settings.py index 4fe982c..7d81a91 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -2,17 +2,6 @@ import environ -DJANGO_FREERADIUS_RADIUSREPLY_MODEL = "sample_radius.RadiusReply" -DJANGO_FREERADIUS_RADIUSGROUPREPLY_MODEL = "sample_radius.RadiusGroupReply" -DJANGO_FREERADIUS_RADIUSCHECK_MODEL = "sample_radius.RadiusCheck" -DJANGO_FREERADIUS_RADIUSGROUPCHECK_MODEL = "sample_radius.RadiusGroupCheck" -DJANGO_FREERADIUS_RADIUSACCOUNTING_MODEL = "sample_radius.RadiusAccounting" -DJANGO_FREERADIUS_NAS_MODEL = "sample_radius.Nas" -DJANGO_FREERADIUS_RADIUSGROUPUSERS_MODEL = "sample_radius.RadiusGroupUsers" -DJANGO_FREERADIUS_RADIUSUSERGROUP_MODEL = "sample_radius.RadiusUserGroup" -DJANGO_FREERADIUS_RADIUSPOSTAUTHENTICATION_MODEL = "sample_radius.RadiusPostAuthentication" -DJANGO_FREERADIUS_RADIUSGROUP_MODEL = "sample_radius.RadiusGroup" - BASE_DIR = os.path.dirname(os.path.abspath(__file__)) root = environ.Path(__file__) - 2 @@ -38,13 +27,8 @@ 'django.contrib.staticfiles', 'django.contrib.admin', 'django_freeradius', - - ] -if os.environ.get('SAMPLE_RADIUS', True): - INSTALLED_APPS.append('sample_radius') - MIDDLEWARE_CLASSES = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -86,3 +70,16 @@ from local_settings import * except ImportError: pass + + if os.environ.get('SAMPLE_APP', True): + INSTALLED_APPS.append('sample_radius') + DJANGO_FREERADIUS_RADIUSREPLY_MODEL = "sample_radius.RadiusReply" + DJANGO_FREERADIUS_RADIUSGROUPREPLY_MODEL = "sample_radius.RadiusGroupReply" + DJANGO_FREERADIUS_RADIUSCHECK_MODEL = "sample_radius.RadiusCheck" + DJANGO_FREERADIUS_RADIUSGROUPCHECK_MODEL = "sample_radius.RadiusGroupCheck" + DJANGO_FREERADIUS_RADIUSACCOUNTING_MODEL = "sample_radius.RadiusAccounting" + DJANGO_FREERADIUS_NAS_MODEL = "sample_radius.Nas" + DJANGO_FREERADIUS_RADIUSGROUPUSERS_MODEL = "sample_radius.RadiusGroupUsers" + DJANGO_FREERADIUS_RADIUSUSERGROUP_MODEL = "sample_radius.RadiusUserGroup" + DJANGO_FREERADIUS_RADIUSPOSTAUTHENTICATION_MODEL = "sample_radius.RadiusPostAuthentication" + DJANGO_FREERADIUS_RADIUSGROUP_MODEL = "sample_radius.RadiusGroup" From c04348de4e2a9a89e91d3448c0148506be8eaba5 Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 24 Jun 2017 18:05:45 +0200 Subject: [PATCH 23/31] [general] correct import --- django_freeradius/admin.py | 18 +++++++++++------- django_freeradius/models.py | 9 ++++++--- django_freeradius/tests/tests_admin.py | 8 +++++--- django_freeradius/tests/tests_models.py | 5 +++-- tests/sample_radius/admin.py | 9 +++++---- tests/sample_radius/models.py | 6 ++++-- tests/sample_radius/tests.py | 5 +++-- 7 files changed, 37 insertions(+), 23 deletions(-) diff --git a/django_freeradius/admin.py b/django_freeradius/admin.py index 79f7f29..e718f80 100644 --- a/django_freeradius/admin.py +++ b/django_freeradius/admin.py @@ -1,12 +1,16 @@ from django.contrib import admin -from .base.admin import (AbstractNasAdmin, AbstractRadiusAccountingAdmin, AbstractRadiusCheckAdmin, - AbstractRadiusGroupAdmin, AbstractRadiusGroupCheckAdmin, - AbstractRadiusGroupReplyAdmin, AbstractRadiusGroupUsersAdmin, - AbstractRadiusPostAuthenticationAdmin, AbstractRadiusReplyAdmin, - AbstractRadiusUserGroupAdmin,) -from .models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, RadiusGroupCheck, RadiusGroupReply, - RadiusGroupUsers, RadiusPostAuthentication, RadiusReply, RadiusUserGroup,) +from .base.admin import (AbstractNasAdmin, AbstractRadiusAccountingAdmin, + AbstractRadiusCheckAdmin, AbstractRadiusGroupAdmin, + AbstractRadiusGroupCheckAdmin, + AbstractRadiusGroupReplyAdmin, + AbstractRadiusGroupUsersAdmin, + AbstractRadiusPostAuthenticationAdmin, + AbstractRadiusReplyAdmin, + AbstractRadiusUserGroupAdmin) +from .models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, + RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, + RadiusPostAuthentication, RadiusReply, RadiusUserGroup) @admin.register(RadiusGroup) diff --git a/django_freeradius/models.py b/django_freeradius/models.py index fdfe5e4..ce54b5f 100644 --- a/django_freeradius/models.py +++ b/django_freeradius/models.py @@ -1,8 +1,11 @@ import swapper -from .base.models import (AbstractNas, AbstractRadiusAccounting, AbstractRadiusCheck, AbstractRadiusGroup, - AbstractRadiusGroupCheck, AbstractRadiusGroupReply, AbstractRadiusGroupUsers, - AbstractRadiusPostAuthentication, AbstractRadiusReply, AbstractRadiusUserGroup,) +from .base.models import (AbstractNas, AbstractRadiusAccounting, + AbstractRadiusCheck, AbstractRadiusGroup, + AbstractRadiusGroupCheck, AbstractRadiusGroupReply, + AbstractRadiusGroupUsers, + AbstractRadiusPostAuthentication, + AbstractRadiusReply, AbstractRadiusUserGroup) class RadiusGroup(AbstractRadiusGroup): diff --git a/django_freeradius/tests/tests_admin.py b/django_freeradius/tests/tests_admin.py index ef32daa..8056032 100644 --- a/django_freeradius/tests/tests_admin.py +++ b/django_freeradius/tests/tests_admin.py @@ -1,11 +1,13 @@ +import os from unittest import skipIf from django.contrib.auth.models import User from django.test import Client, TestCase from django.urls import reverse -import os -from ..models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, RadiusGroupCheck, RadiusGroupReply, - RadiusGroupUsers, RadiusPostAuthentication, RadiusReply, RadiusUserGroup,) + +from ..models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, + RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, + RadiusPostAuthentication, RadiusReply, RadiusUserGroup) @skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') diff --git a/django_freeradius/tests/tests_models.py b/django_freeradius/tests/tests_models.py index 9e05a2b..ef6aeaf 100644 --- a/django_freeradius/tests/tests_models.py +++ b/django_freeradius/tests/tests_models.py @@ -2,8 +2,9 @@ from django.test import TestCase -from ..models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, RadiusGroupCheck, RadiusGroupReply, - RadiusGroupUsers, RadiusPostAuthentication, RadiusReply, RadiusUserGroup,) +from ..models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, + RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, + RadiusPostAuthentication, RadiusReply, RadiusUserGroup) @skipIf(True, "env = DATABASE_URL='mysql://mysql@127.0.0.1/sample_test' SAMPLE_APP=1") diff --git a/tests/sample_radius/admin.py b/tests/sample_radius/admin.py index 065c056..76d9d75 100644 --- a/tests/sample_radius/admin.py +++ b/tests/sample_radius/admin.py @@ -1,8 +1,10 @@ -from django.contrib import admin import swapper +from django.contrib import admin -from django_freeradius.admin import (AbstractNasAdmin, AbstractRadiusAccountingAdmin, - AbstractRadiusCheckAdmin, AbstractRadiusGroupAdmin, +from django_freeradius.admin import (AbstractNasAdmin, + AbstractRadiusAccountingAdmin, + AbstractRadiusCheckAdmin, + AbstractRadiusGroupAdmin, AbstractRadiusGroupCheckAdmin, AbstractRadiusGroupReplyAdmin, AbstractRadiusGroupUsersAdmin, @@ -10,7 +12,6 @@ AbstractRadiusReplyAdmin, AbstractRadiusUserGroupAdmin) - RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") RadiusGroupUsers = swapper.load_model("django_freeradius", "RadiusGroupUsers") diff --git a/tests/sample_radius/models.py b/tests/sample_radius/models.py index 75288bf..4745191 100644 --- a/tests/sample_radius/models.py +++ b/tests/sample_radius/models.py @@ -3,10 +3,12 @@ from django_freeradius.models import (AbstractNas, AbstractRadiusAccounting, AbstractRadiusCheck, AbstractRadiusGroup, - AbstractRadiusGroupCheck, AbstractRadiusGroupReply, + AbstractRadiusGroupCheck, + AbstractRadiusGroupReply, AbstractRadiusGroupUsers, AbstractRadiusPostAuthentication, - AbstractRadiusReply, AbstractRadiusUserGroup) + AbstractRadiusReply, + AbstractRadiusUserGroup) class RadiusGroup(AbstractRadiusGroup): diff --git a/tests/sample_radius/tests.py b/tests/sample_radius/tests.py index 919188d..9fac388 100644 --- a/tests/sample_radius/tests.py +++ b/tests/sample_radius/tests.py @@ -1,9 +1,10 @@ +import os +from unittest import skipUnless + import swapper from django.contrib.auth.models import User from django.test import Client, TestCase from django.urls import reverse -from unittest import skipUnless -import os RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") From 40d0baf282492590e0f860a07f6e11b84fe59816 Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 24 Jun 2017 18:20:53 +0200 Subject: [PATCH 24/31] [general] correct error --- django_freeradius/tests/tests_models.py | 2 +- tests/settings.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/django_freeradius/tests/tests_models.py b/django_freeradius/tests/tests_models.py index ef6aeaf..d496108 100644 --- a/django_freeradius/tests/tests_models.py +++ b/django_freeradius/tests/tests_models.py @@ -7,7 +7,7 @@ RadiusPostAuthentication, RadiusReply, RadiusUserGroup) -@skipIf(True, "env = DATABASE_URL='mysql://mysql@127.0.0.1/sample_test' SAMPLE_APP=1") +@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') class NasModelTest(TestCase): def test_string_representation(self): diff --git a/tests/settings.py b/tests/settings.py index 7d81a91..fa72c90 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -16,7 +16,7 @@ 'default': env.db(default='sqlite:///django-freeradius.db'), } - + SECRET_KEY = 'fn)t*+$)ugeyip6-#txyy$5wf2ervc0d2n#h)qb)y5@ly$t*@w' INSTALLED_APPS = [ @@ -65,13 +65,14 @@ }, ] -# local settings must be imported before test runner otherwise they'll be ignored + local settings must be imported before test runner otherwise they'll be ignored try: from local_settings import * except ImportError: pass - if os.environ.get('SAMPLE_APP', True): + +if os.environ.get('SAMPLE_APP', True): INSTALLED_APPS.append('sample_radius') DJANGO_FREERADIUS_RADIUSREPLY_MODEL = "sample_radius.RadiusReply" DJANGO_FREERADIUS_RADIUSGROUPREPLY_MODEL = "sample_radius.RadiusGroupReply" From 59b8f65103b6af08f43d9bc92777d97c95471dd8 Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 24 Jun 2017 18:46:59 +0200 Subject: [PATCH 25/31] [general] clean code --- django_freeradius/tests/tests_models.py | 20 ++++++++++---------- tests/sample_radius/tests.py | 20 ++++++++++---------- tests/settings.py | 4 ++-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/django_freeradius/tests/tests_models.py b/django_freeradius/tests/tests_models.py index d496108..03c2a11 100644 --- a/django_freeradius/tests/tests_models.py +++ b/django_freeradius/tests/tests_models.py @@ -5,7 +5,7 @@ from ..models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, RadiusPostAuthentication, RadiusReply, RadiusUserGroup) - +import os @skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') class NasModelTest(TestCase): @@ -14,63 +14,63 @@ def test_string_representation(self): nas = Nas(nas_name='entry nasname') self.assertEqual(str(nas), nas.nas_name) - +@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') class RadiusAccountingModelTest(TestCase): def test_string_representation(self): radiusaccounting = RadiusAccounting(acct_unique_id='entry acctuniqueid') self.assertEqual(str(radiusaccounting), radiusaccounting.acct_unique_id) - +@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') class RadiusCheckModelTest(TestCase): def test_string_representation(self): radiuscheck = RadiusCheck(user_name='entry username') self.assertEqual(str(radiuscheck), radiuscheck.user_name) - +@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') class RadiusReplyModelTest(TestCase): def test_string_representation(self): radiusreply = RadiusReply(user_name='entry username') self.assertEqual(str(radiusreply), radiusreply.user_name) - +@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') class RadiusGroupReplyModelTest(TestCase): def test_string_representation(self): radiusgroupreply = RadiusGroupReply(group_name='entry groupname') self.assertEqual(str(radiusgroupreply), radiusgroupreply.group_name) - +@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') class RadiusGroupCheckModelTest(TestCase): def test_string_representation(self): radiusgroupcheck = RadiusGroupCheck(group_name='entry groupname') self.assertEqual(str(radiusgroupcheck), radiusgroupcheck.group_name) - +@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') class RadiusUserGroupModelTest(TestCase): def test_string_representation(self): radiususergroup = RadiusUserGroup(user_name='entry username') self.assertEqual(str(radiususergroup), radiususergroup.user_name) - +@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') class RadiusPostAuthenticationModelTest(TestCase): def test_string_representation(self): radiuspostauthentication = RadiusPostAuthentication(user_name='entry username') self.assertEqual(str(radiuspostauthentication), radiuspostauthentication.user_name) - +@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') class RadiusGroupModelTest(TestCase): def test_string_representation(self): radiusgroup = RadiusGroup(group_name='entry groupname') self.assertEqual(str(radiusgroup), radiusgroup.group_name) - +@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') class RadiusGroupUsersModelTest(TestCase): def test_string_representation(self): diff --git a/tests/sample_radius/tests.py b/tests/sample_radius/tests.py index 9fac388..6cd7e0f 100644 --- a/tests/sample_radius/tests.py +++ b/tests/sample_radius/tests.py @@ -25,70 +25,70 @@ def test_string_representation(self): nas = Nas(nas_name='entry nasname') self.assertEqual(str(nas), nas.nas_name) - +@skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class RadiusAccountingModelTest(TestCase): def test_string_representation(self): radiusaccounting = RadiusAccounting(acct_unique_id='entry acctuniqueid') self.assertEqual(str(radiusaccounting), radiusaccounting.acct_unique_id) - +@skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class RadiusCheckModelTest(TestCase): def test_string_representation(self): radiuscheck = RadiusCheck(user_name='entry username') self.assertEqual(str(radiuscheck), radiuscheck.user_name) - +@skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class RadiusReplyModelTest(TestCase): def test_string_representation(self): radiusreply = RadiusReply(user_name='entry username') self.assertEqual(str(radiusreply), radiusreply.user_name) - +@skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class RadiusGroupReplyModelTest(TestCase): def test_string_representation(self): radiusgroupreply = RadiusGroupReply(group_name='entry groupname') self.assertEqual(str(radiusgroupreply), radiusgroupreply.group_name) - +@skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class RadiusGroupCheckModelTest(TestCase): def test_string_representation(self): radiusgroupcheck = RadiusGroupCheck(group_name='entry groupname') self.assertEqual(str(radiusgroupcheck), radiusgroupcheck.group_name) - +@skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class RadiusUserGroupModelTest(TestCase): def test_string_representation(self): radiususergroup = RadiusUserGroup(user_name='entry username') self.assertEqual(str(radiususergroup), radiususergroup.user_name) - +@skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class RadiusPostAuthenticationModelTest(TestCase): def test_string_representation(self): radiuspostauthentication = RadiusPostAuthentication(user_name='entry username') self.assertEqual(str(radiuspostauthentication), radiuspostauthentication.user_name) - +@skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class RadiusGroupModelTest(TestCase): def test_string_representation(self): radiusgroup = RadiusGroup(group_name='entry groupname') self.assertEqual(str(radiusgroup), radiusgroup.group_name) - +@skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class RadiusGroupUsersModelTest(TestCase): def test_string_representation(self): radiusgroupusers = RadiusGroupUsers(user_name='entry groupname') self.assertEqual(str(radiusgroupusers), radiusgroupusers.user_name) - +@skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class UserTest(TestCase): def setUp(self): diff --git a/tests/settings.py b/tests/settings.py index fa72c90..94dd101 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -16,7 +16,7 @@ 'default': env.db(default='sqlite:///django-freeradius.db'), } - + SECRET_KEY = 'fn)t*+$)ugeyip6-#txyy$5wf2ervc0d2n#h)qb)y5@ly$t*@w' INSTALLED_APPS = [ @@ -65,7 +65,7 @@ }, ] - local settings must be imported before test runner otherwise they'll be ignored +#local settings must be imported before test runner otherwise they'll be ignored try: from local_settings import * except ImportError: From 02290da40a289bab8908e2d76807d573543cfff1 Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 24 Jun 2017 19:38:49 +0200 Subject: [PATCH 26/31] [general] code clean --- django_freeradius/tests/tests_admin.py | 3 ++- django_freeradius/tests/tests_models.py | 32 ++++++++++++++++--------- tests/sample_radius/tests.py | 11 +++++++++ tests/settings.py | 2 +- 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/django_freeradius/tests/tests_admin.py b/django_freeradius/tests/tests_admin.py index 8056032..73ece4a 100644 --- a/django_freeradius/tests/tests_admin.py +++ b/django_freeradius/tests/tests_admin.py @@ -10,11 +10,12 @@ RadiusPostAuthentication, RadiusReply, RadiusUserGroup) -@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') +@skipIf(os.environ.get('SAMPLE_APP', False), 'Running tests on SAMPLE_APP') class UserTest(TestCase): def setUp(self): self.client = Client() + super(UserTest, self).setUp() def test_users_not_login(self): resp = self.client.get('/admin/auth/') diff --git a/django_freeradius/tests/tests_models.py b/django_freeradius/tests/tests_models.py index 03c2a11..7017671 100644 --- a/django_freeradius/tests/tests_models.py +++ b/django_freeradius/tests/tests_models.py @@ -1,3 +1,4 @@ +import os from unittest import skipIf from django.test import TestCase @@ -5,72 +6,81 @@ from ..models import (Nas, RadiusAccounting, RadiusCheck, RadiusGroup, RadiusGroupCheck, RadiusGroupReply, RadiusGroupUsers, RadiusPostAuthentication, RadiusReply, RadiusUserGroup) -import os -@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') + +@skipIf(os.environ.get('SAMPLE_APP', False), 'Running tests on SAMPLE_APP') class NasModelTest(TestCase): def test_string_representation(self): nas = Nas(nas_name='entry nasname') self.assertEqual(str(nas), nas.nas_name) -@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') + +@skipIf(os.environ.get('SAMPLE_APP', False), 'Running tests on SAMPLE_APP') class RadiusAccountingModelTest(TestCase): def test_string_representation(self): radiusaccounting = RadiusAccounting(acct_unique_id='entry acctuniqueid') self.assertEqual(str(radiusaccounting), radiusaccounting.acct_unique_id) -@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') + +@skipIf(os.environ.get('SAMPLE_APP', False), 'Running tests on SAMPLE_APP') class RadiusCheckModelTest(TestCase): def test_string_representation(self): radiuscheck = RadiusCheck(user_name='entry username') self.assertEqual(str(radiuscheck), radiuscheck.user_name) -@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') + +@skipIf(os.environ.get('SAMPLE_APP', False), 'Running tests on SAMPLE_APP') class RadiusReplyModelTest(TestCase): def test_string_representation(self): radiusreply = RadiusReply(user_name='entry username') self.assertEqual(str(radiusreply), radiusreply.user_name) -@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') + +@skipIf(os.environ.get('SAMPLE_APP', False), 'Running tests on SAMPLE_APP') class RadiusGroupReplyModelTest(TestCase): def test_string_representation(self): radiusgroupreply = RadiusGroupReply(group_name='entry groupname') self.assertEqual(str(radiusgroupreply), radiusgroupreply.group_name) -@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') + +@skipIf(os.environ.get('SAMPLE_APP', False), 'Running tests on SAMPLE_APP') class RadiusGroupCheckModelTest(TestCase): def test_string_representation(self): radiusgroupcheck = RadiusGroupCheck(group_name='entry groupname') self.assertEqual(str(radiusgroupcheck), radiusgroupcheck.group_name) -@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') + +@skipIf(os.environ.get('SAMPLE_APP', False), 'Running tests on SAMPLE_APP') class RadiusUserGroupModelTest(TestCase): def test_string_representation(self): radiususergroup = RadiusUserGroup(user_name='entry username') self.assertEqual(str(radiususergroup), radiususergroup.user_name) -@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') + +@skipIf(os.environ.get('SAMPLE_APP', False), 'Running tests on SAMPLE_APP') class RadiusPostAuthenticationModelTest(TestCase): def test_string_representation(self): radiuspostauthentication = RadiusPostAuthentication(user_name='entry username') self.assertEqual(str(radiuspostauthentication), radiuspostauthentication.user_name) -@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') + +@skipIf(os.environ.get('SAMPLE_APP', False), 'Running tests on SAMPLE_APP') class RadiusGroupModelTest(TestCase): def test_string_representation(self): radiusgroup = RadiusGroup(group_name='entry groupname') self.assertEqual(str(radiusgroup), radiusgroup.group_name) -@skipIf(os.environ.get('SAMPLE_APP', True), 'Running tests on SAMPLE_APP') + +@skipIf(os.environ.get('SAMPLE_APP', False), 'Running tests on SAMPLE_APP') class RadiusGroupUsersModelTest(TestCase): def test_string_representation(self): diff --git a/tests/sample_radius/tests.py b/tests/sample_radius/tests.py index 6cd7e0f..25dfa72 100644 --- a/tests/sample_radius/tests.py +++ b/tests/sample_radius/tests.py @@ -25,6 +25,7 @@ def test_string_representation(self): nas = Nas(nas_name='entry nasname') self.assertEqual(str(nas), nas.nas_name) + @skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class RadiusAccountingModelTest(TestCase): @@ -32,6 +33,7 @@ def test_string_representation(self): radiusaccounting = RadiusAccounting(acct_unique_id='entry acctuniqueid') self.assertEqual(str(radiusaccounting), radiusaccounting.acct_unique_id) + @skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class RadiusCheckModelTest(TestCase): @@ -39,6 +41,7 @@ def test_string_representation(self): radiuscheck = RadiusCheck(user_name='entry username') self.assertEqual(str(radiuscheck), radiuscheck.user_name) + @skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class RadiusReplyModelTest(TestCase): @@ -46,6 +49,7 @@ def test_string_representation(self): radiusreply = RadiusReply(user_name='entry username') self.assertEqual(str(radiusreply), radiusreply.user_name) + @skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class RadiusGroupReplyModelTest(TestCase): @@ -53,6 +57,7 @@ def test_string_representation(self): radiusgroupreply = RadiusGroupReply(group_name='entry groupname') self.assertEqual(str(radiusgroupreply), radiusgroupreply.group_name) + @skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class RadiusGroupCheckModelTest(TestCase): @@ -60,6 +65,7 @@ def test_string_representation(self): radiusgroupcheck = RadiusGroupCheck(group_name='entry groupname') self.assertEqual(str(radiusgroupcheck), radiusgroupcheck.group_name) + @skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class RadiusUserGroupModelTest(TestCase): @@ -67,6 +73,7 @@ def test_string_representation(self): radiususergroup = RadiusUserGroup(user_name='entry username') self.assertEqual(str(radiususergroup), radiususergroup.user_name) + @skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class RadiusPostAuthenticationModelTest(TestCase): @@ -74,6 +81,7 @@ def test_string_representation(self): radiuspostauthentication = RadiusPostAuthentication(user_name='entry username') self.assertEqual(str(radiuspostauthentication), radiuspostauthentication.user_name) + @skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class RadiusGroupModelTest(TestCase): @@ -81,6 +89,7 @@ def test_string_representation(self): radiusgroup = RadiusGroup(group_name='entry groupname') self.assertEqual(str(radiusgroup), radiusgroup.group_name) + @skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class RadiusGroupUsersModelTest(TestCase): @@ -88,11 +97,13 @@ def test_string_representation(self): radiusgroupusers = RadiusGroupUsers(user_name='entry groupname') self.assertEqual(str(radiusgroupusers), radiusgroupusers.user_name) + @skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django_freeradius models') class UserTest(TestCase): def setUp(self): self.client = Client() + super(UserTest, self).setUp() def test_users_not_login(self): resp = self.client.get('/admin/auth/') diff --git a/tests/settings.py b/tests/settings.py index 94dd101..5102f1a 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -72,7 +72,7 @@ pass -if os.environ.get('SAMPLE_APP', True): +if os.environ.get('SAMPLE_APP', False): INSTALLED_APPS.append('sample_radius') DJANGO_FREERADIUS_RADIUSREPLY_MODEL = "sample_radius.RadiusReply" DJANGO_FREERADIUS_RADIUSGROUPREPLY_MODEL = "sample_radius.RadiusGroupReply" From e36c42cbca045db2407c61937f0a0383fd82bb6a Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 24 Jun 2017 19:55:03 +0200 Subject: [PATCH 27/31] [general]correct error --- .travis.yml | 4 ++-- tests/sample_radius/tests.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 240553f..544d14d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,8 +19,8 @@ env: - DJANGO="django>=1.11,<1.12" DATABASE_URL='mysql://root@127.0.0.1/freeradius_test' - DJANGO="django>=1.10,<1.11" DATABASE_URL='postgres://postgres@127.0.0.1/freeradius_test' - DJANGO="django>=1.11,<1.12" DATABASE_URL='postgres://postgres@127.0.0.1/freeradius_test' - - DJANGO="django>=1.10,<1.11" DATABASE_URL='mysql://mysql@127.0.0.1/sample_test' SAMPLE_APP=1 - - DJANGO="django>=1.11,<1.12" DATABASE_URL='mysql://mysql@127.0.0.1/sample_test' SAMPLE_APP=1 + - DJANGO="django>=1.10,<1.11" DATABASE_URL='mysql://root@127.0.0.1/freeradius_test' SAMPLE_APP=1 + - DJANGO="django>=1.11,<1.12" DATABASE_URL='mysql://root@127.0.0.1/freeradius_test' SAMPLE_APP=1 before_install: - pip install --no-cache-dir -U -r requirements-test.txt diff --git a/tests/sample_radius/tests.py b/tests/sample_radius/tests.py index 25dfa72..79ea10f 100644 --- a/tests/sample_radius/tests.py +++ b/tests/sample_radius/tests.py @@ -1,6 +1,5 @@ import os from unittest import skipUnless - import swapper from django.contrib.auth.models import User from django.test import Client, TestCase From 3103a952aa0e76ca64fb9b436af68e1653b6dd1c Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 24 Jun 2017 20:00:42 +0200 Subject: [PATCH 28/31] [test] correct import --- tests/sample_radius/tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/sample_radius/tests.py b/tests/sample_radius/tests.py index 79ea10f..25dfa72 100644 --- a/tests/sample_radius/tests.py +++ b/tests/sample_radius/tests.py @@ -1,5 +1,6 @@ import os from unittest import skipUnless + import swapper from django.contrib.auth.models import User from django.test import Client, TestCase From 8700250159f26f70b08c6221924697d05285fea2 Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 24 Jun 2017 20:13:15 +0200 Subject: [PATCH 29/31] [general] correct import --- django_freeradius/base/models.py | 1 + tests/sample_radius/admin.py | 2 +- tests/sample_radius/tests.py | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/django_freeradius/base/models.py b/django_freeradius/base/models.py index 3dc904d..e5c80dd 100644 --- a/django_freeradius/base/models.py +++ b/django_freeradius/base/models.py @@ -1,5 +1,6 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ + from model_utils.fields import AutoCreatedField, AutoLastModifiedField RADOP_CHECK_TYPES = ( diff --git a/tests/sample_radius/admin.py b/tests/sample_radius/admin.py index 76d9d75..7ad9dc9 100644 --- a/tests/sample_radius/admin.py +++ b/tests/sample_radius/admin.py @@ -1,6 +1,6 @@ -import swapper from django.contrib import admin +import swapper from django_freeradius.admin import (AbstractNasAdmin, AbstractRadiusAccountingAdmin, AbstractRadiusCheckAdmin, diff --git a/tests/sample_radius/tests.py b/tests/sample_radius/tests.py index 25dfa72..21171d8 100644 --- a/tests/sample_radius/tests.py +++ b/tests/sample_radius/tests.py @@ -1,11 +1,11 @@ import os from unittest import skipUnless - -import swapper from django.contrib.auth.models import User from django.test import Client, TestCase from django.urls import reverse +import swapper + RadiusGroupReply = swapper.load_model("django_freeradius", "RadiusGroupReply") RadiusGroupCheck = swapper.load_model("django_freeradius", "RadiusGroupCheck") RadiusGroupUsers = swapper.load_model("django_freeradius", "RadiusGroupUsers") From 15395522254f83b60b3aa5e93ffacd59274807f1 Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 24 Jun 2017 20:17:20 +0200 Subject: [PATCH 30/31] [general] correct import --- tests/sample_radius/tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/sample_radius/tests.py b/tests/sample_radius/tests.py index 21171d8..0f05fdb 100644 --- a/tests/sample_radius/tests.py +++ b/tests/sample_radius/tests.py @@ -1,5 +1,6 @@ import os from unittest import skipUnless + from django.contrib.auth.models import User from django.test import Client, TestCase from django.urls import reverse From 1e40453d5620c4501a979e3b02b524d0de1acd3d Mon Sep 17 00:00:00 2001 From: Fiorella De Luca Date: Sat, 24 Jun 2017 20:37:21 +0200 Subject: [PATCH 31/31] [runtests] added sample_radius to runtests --- runtests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/runtests.py b/runtests.py index 15c07c0..e5d8c95 100755 --- a/runtests.py +++ b/runtests.py @@ -12,4 +12,5 @@ args = sys.argv args.insert(1, "test") args.insert(2, "django_freeradius") + args.insert(3, "sample_radius") execute_from_command_line(args)