How to test whether a formset instance is properly initialized

38 views
Skip to first unread message

PARTH PATIL

unread,
Jun 15, 2019, 1:04:12 AM6/15/19
to Django developers (Contributions to Django itself)
I'm currently working on ticket #10403 -- Declarative syntax for Formsets

How to test whether a formset instance is correctly initialized??

The thing which I'm trying to achieve is to initiate a formset without using formset_factory(). I'm able to create objects of class derived from the BaseFormSet, but its really difficult for me to check whether it is properly initiated or not as expected from a formset instance.

Should I write tests for this??
And if yes, which all parameter values should I assert in the test to conclude that my formset instance is indistinguishable from the one created using formset_factory.

Also is there any better way to test this? I'm currently using a python shell to create objects and then check manually its attributes, etc. which I know is not a good way. 

Carlton Gibson

unread,
Jun 15, 2019, 3:14:32 AM6/15/19
to Django developers (Contributions to Django itself)
Hey Parth, 

>  I'm currently using a python shell to create objects and then check manually its attributes, etc.

More or less, do the same thing, but in a test case. 🙂

# Declare class

# Create instance

# self.assertEqual()/assertIs()/etc expected attributes. 
# … same but for behaviour too. (Give it some data, is_valid(), etc)

Look in tests/forms_tests/tests/test_formsets/py::FormsFormsetTestCase. 
There are cases there using formset_factory(). Your versions will just declare the FormSet instead. 

Hope that helps.
If you have difficulties, open a PR with what you’ve got: it may be easier to help you there. 

Kind Regards,

Carlton


--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/583effcf-041e-4d30-9693-62a8f9559901%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages