1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | '''
example:
form = response.context['myform']
subsidiary = ....
self.assertTrue(
FormTestHelper.check_in_queryset(
form,
'attribute',
property='subsidiary',
type='=',
against=subsidiary
)
)
'''
def check_condition(element1, **condition):
#fill this code with your conditions!!!
if condition.has_key('condition') and condition['type'] == '=':
if condition.has_key('property'):
return getattr(element1,
condition['property']) == condition['against']
else:
return element1 == condition['against']
return False
class FormTestHelper(object):
@staticmethod
def check_in_queryset(form, form_element, **condition):
return all([check_condition(element, **condition) for element in
form.fields[form_element].queryset])
|
More like this
- Embedded inline formsets in ModelForm by stan 2 years, 7 months ago
- Conditional Caching by Archatas 3 years, 9 months ago
- assertQuerysetEqual by coleifer 3 years, 1 month ago
- save form in ajax with jquery in django by ralphleyga 2 years, 9 months ago
- Memory efficient Django Queryset Iterator by WoLpH 3 years, 3 months ago
Comments