-
-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34979 from dimagi/mjr/enterprise_form_limits
Added form limits for enterprise form reports
- Loading branch information
Showing
5 changed files
with
90 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
class EnterpriseReportError(Exception): | ||
pass | ||
|
||
|
||
class TooMuchRequestedDataError(Exception): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
def raise_after_max_elements(it, max_elements, exception=None): | ||
for total_yielded, ele in enumerate(it): | ||
if total_yielded >= max_elements: | ||
exception = exception or Exception('Too Many Elements') | ||
raise exception | ||
|
||
yield ele |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.test import SimpleTestCase | ||
|
||
from corehq.apps.enterprise.iterators import raise_after_max_elements | ||
|
||
|
||
class TestRaiseAfterMaxElements(SimpleTestCase): | ||
def test_iterating_beyond_max_items_will_raise_the_default_exception(self): | ||
it = raise_after_max_elements([1, 2, 3], 2) | ||
with self.assertRaisesMessage(Exception, 'Too Many Elements'): | ||
list(it) | ||
|
||
def test_iterating_beyond_max_items_will_raise_provided_exception(self): | ||
it = raise_after_max_elements([1, 2, 3], 2, Exception('Test Message')) | ||
with self.assertRaisesMessage(Exception, 'Test Message'): | ||
list(it) | ||
|
||
def test_can_iterate_through_all_elements_with_no_exception(self): | ||
it = raise_after_max_elements([1, 2, 3], 3) | ||
self.assertEqual(list(it), [1, 2, 3]) |