Skip to content

Commit

Permalink
More tests and better handling for strtobool conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov committed Sep 19, 2017
1 parent 64c9a37 commit c87edd5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tcms/core/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,14 @@ def __init__(self, request, product_id=None):
def builds(self):
from tcms.management.models import TestBuild

try:
_is_active = bool(strtobool(self.request.GET.get('is_active', 'False')))
except (ValueError, TypeError):
_is_active = False

query = {
'product_id': self.product_id,
'is_active': bool(strtobool(self.request.GET.get('is_active', 'False')))
'is_active': _is_active
}
return TestBuild.list(query)

Expand Down
5 changes: 5 additions & 0 deletions tcms/core/tests/test_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ def test_lowercase_string_is_converted_to_bool(self):
url = "%s?info_type=builds&product_id=1&is_active=true" % reverse('ajax-info')
response = self.client.get(url)
self.assertEqual(200, response.status_code)

def test_empty_string_is_converted_to_bool(self):
url = "%s?info_type=builds&product_id=1&is_active=" % reverse('ajax-info')
response = self.client.get(url)
self.assertEqual(200, response.status_code)

0 comments on commit c87edd5

Please sign in to comment.