-
Notifications
You must be signed in to change notification settings - Fork 87
[QA] Increasing test coverage to 100% #186 #202
Conversation
I stuck while testing these lines (I tried to test it in |
I have tried to test these lines by that:
but by And I can not figure out where this function is used, so I added for both |
django_freeradius/base/models.py
Outdated
@@ -206,7 +206,7 @@ class AbstractRadiusCheckManager(models.Manager): | |||
def get_queryset(self): | |||
return AbstractRadiusCheckQueryset(self.model, using=self._db) | |||
|
|||
def create(self, *args, **kwargs): | |||
def create(self, *args, **kwargs): # pragma nocover |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can test this with RadiusCheck.objects.create()
and supply new_value
in the keyword arguments
@@ -187,6 +187,7 @@ def test_radiuscheck_filter_expired(self): | |||
def test_radiuscheck_filter_not_expired(self): | |||
url = reverse('admin:{0}_radiuscheck_changelist'.format(self.app_name)) + '?expired=not_expired' | |||
resp = self.client.get(url, follow=True) | |||
# print(resp.context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this line
django_freeradius/base/admin.py
Outdated
@@ -83,7 +83,7 @@ class AbstractRadiusCheckAdmin(TimeStampedEditableAdmin): | |||
autocomplete_fields = ['user'] | |||
actions = [disable_action, enable_action, delete_selected] | |||
|
|||
def save_model(self, request, obj, form, change): | |||
def save_model(self, request, obj, form, change): # pragma: nocover |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove # pragma: nocover
. Never use this for real code but only for exceptional and special cases.
I will test this method and let you know what I find.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OltarzewskiK rebase on the current master to fix the issue of save_model
You're good @OltarzewskiK |
Thanks 😊 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great progress Karol!
SAMPLE_APP=1
runs tests for the sample_app in 'tests/` to test custom models using the swappable base models, you can run tests for that as well with:
SAMPLE_APP=1 ./runtests.py --keepdb
The keepdb
flag just speeds up test execution by avoiding to recreate the test db.
@@ -6,6 +6,7 @@ | |||
DEFAULT_SESSION_TIME_LIMIT, DEFAULT_SESSION_TRAFFIC_LIMIT, SESSION_TIME_ATTRIBUTE, | |||
SESSION_TRAFFIC_ATTRIBUTE, | |||
) | |||
from django_freeradius.models import RadiusCheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is what is causing the issue, these tests should not import concrete models because are designed to be reused (and are reused in the sample app).
Read the code of other tests to see how they get the model class: https://github.com/openwisp/django-freeradius/blob/master/django_freeradius/tests/base/test_models.py#L25
You should always do this when in doubt: read how existing code does something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes 👍
GCI task: https://codein.withgoogle.com/dashboard/task-instances/5070054078021632/