<s> from __future__ import unicode_literals <EOL> from django import forms <EOL> from django . forms . formsets import DELETION_FIELD_NAME , BaseFormSet <EOL> from django . forms . models import ( <EOL> BaseModelFormSet , inlineformset_factory , modelform_factory , <EOL> modelformset_factory , <EOL> ) <EOL> from django . forms . utils import ErrorDict , ErrorList <EOL> from django . test import TestCase <EOL> from django . utils import six <EOL> from . models import ( <EOL> Host , Manager , Network , ProfileNetwork , Restaurant , User , UserProfile , <EOL> UserSite , <EOL> ) <EOL> class InlineFormsetTests ( TestCase ) : <EOL> def test_formset_over_to_field ( self ) : <EOL> "<STR_LIT>" <EOL> Form = modelform_factory ( User , fields = "<STR_LIT>" ) <EOL> FormSet = inlineformset_factory ( User , UserSite , fields = "<STR_LIT>" ) <EOL> form = Form ( ) <EOL> form_set = FormSet ( instance = User ( ) ) <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> user = User ( ) <EOL> form = Form ( data ) <EOL> if form . is_valid ( ) : <EOL> user = form . save ( ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' % form_set ) <EOL> form_set = FormSet ( data , instance = user ) <EOL> if form_set . is_valid ( ) : <EOL> form_set . save ( ) <EOL> usersite = UserSite . objects . all ( ) . values ( ) <EOL> self . assertEqual ( usersite [ <NUM_LIT:0> ] [ '<STR_LIT:data>' ] , <NUM_LIT:10> ) <EOL> self . assertEqual ( usersite [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' % form_set . errors ) <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : six . text_type ( usersite [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> form_set = FormSet ( data , instance = user ) <EOL> if form_set . is_valid ( ) : <EOL> form_set . save ( ) <EOL> usersite = UserSite . objects . all ( ) . values ( ) <EOL> self . assertEqual ( usersite [ <NUM_LIT:0> ] [ '<STR_LIT:data>' ] , <NUM_LIT:11> ) <EOL> self . assertEqual ( usersite [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' % form_set . errors ) <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : six . text_type ( usersite [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> form_set = FormSet ( data , instance = user ) <EOL> if form_set . is_valid ( ) : <EOL> form_set . save ( ) <EOL> usersite = UserSite . objects . all ( ) . values ( ) . order_by ( '<STR_LIT:data>' ) <EOL> self . assertEqual ( usersite [ <NUM_LIT:0> ] [ '<STR_LIT:data>' ] , <NUM_LIT:11> ) <EOL> self . assertEqual ( usersite [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( usersite [ <NUM_LIT:1> ] [ '<STR_LIT:data>' ] , <NUM_LIT> ) <EOL> self . assertEqual ( usersite [ <NUM_LIT:1> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' % form_set . errors ) <EOL> def test_formset_over_inherited_model ( self ) : <EOL> "<STR_LIT>" <EOL> Form = modelform_factory ( Restaurant , fields = "<STR_LIT>" ) <EOL> FormSet = inlineformset_factory ( Restaurant , Manager , fields = "<STR_LIT>" ) <EOL> form = Form ( ) <EOL> form_set = FormSet ( instance = Restaurant ( ) ) <EOL> data = { <EOL> '<STR_LIT:name>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> restaurant = User ( ) <EOL> form = Form ( data ) <EOL> if form . is_valid ( ) : <EOL> restaurant = form . save ( ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' % form_set ) <EOL> form_set = FormSet ( data , instance = restaurant ) <EOL> if form_set . is_valid ( ) : <EOL> form_set . save ( ) <EOL> manager = Manager . objects . all ( ) . values ( ) <EOL> self . assertEqual ( manager [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' % form_set . errors ) <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : six . text_type ( manager [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] ) , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> form_set = FormSet ( data , instance = restaurant ) <EOL> if form_set . is_valid ( ) : <EOL> form_set . save ( ) <EOL> manager = Manager . objects . all ( ) . values ( ) <EOL> self . assertEqual ( manager [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' % form_set . errors ) <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : six . text_type ( manager [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> form_set = FormSet ( data , instance = restaurant ) <EOL> if form_set . is_valid ( ) : <EOL> form_set . save ( ) <EOL> manager = Manager . objects . all ( ) . values ( ) . order_by ( '<STR_LIT:name>' ) <EOL> self . assertEqual ( manager [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( manager [ <NUM_LIT:1> ] [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' % form_set . errors ) <EOL> def test_inline_model_with_to_field ( self ) : <EOL> """<STR_LIT>""" <EOL> FormSet = inlineformset_factory ( User , UserSite , exclude = ( '<STR_LIT>' , ) ) <EOL> user = User . objects . create ( username = "<STR_LIT>" , serial = <NUM_LIT> ) <EOL> UserSite . objects . create ( user = user , data = <NUM_LIT:10> ) <EOL> formset = FormSet ( instance = user ) <EOL> self . assertEqual ( formset [ <NUM_LIT:0> ] . instance . user_id , "<STR_LIT>" ) <EOL> def test_inline_model_with_to_field_to_rel ( self ) : <EOL> """<STR_LIT>""" <EOL> FormSet = inlineformset_factory ( UserProfile , ProfileNetwork , exclude = [ ] ) <EOL> user = User . objects . create ( username = "<STR_LIT>" , serial = <NUM_LIT> , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( user . pk , <NUM_LIT:1> ) <EOL> profile = UserProfile . objects . create ( user = user , about = "<STR_LIT>" , pk = <NUM_LIT:2> ) <EOL> self . assertEqual ( profile . pk , <NUM_LIT:2> ) <EOL> ProfileNetwork . objects . create ( profile = profile , network = <NUM_LIT:10> , identifier = <NUM_LIT:10> ) <EOL> formset = FormSet ( instance = profile ) <EOL> self . assertEqual ( formset [ <NUM_LIT:0> ] . instance . profile_id , <NUM_LIT:1> ) <EOL> def test_formset_with_none_instance ( self ) : <EOL> "<STR_LIT>" <EOL> Form = modelform_factory ( User , fields = "<STR_LIT>" ) <EOL> FormSet = inlineformset_factory ( User , UserSite , fields = "<STR_LIT>" ) <EOL> Form ( instance = None ) <EOL> FormSet ( instance = None ) <EOL> def test_empty_fields_on_modelformset ( self ) : <EOL> """<STR_LIT>""" <EOL> UserFormSet = modelformset_factory ( User , fields = ( ) ) <EOL> formset = UserFormSet ( ) <EOL> for form in formset . forms : <EOL> self . assertIn ( '<STR_LIT:id>' , form . fields ) <EOL> self . assertEqual ( len ( form . fields ) , <NUM_LIT:1> ) <EOL> def test_save_as_new_with_new_inlines ( self ) : <EOL> """<STR_LIT>""" <EOL> efnet = Network . objects . create ( name = "<STR_LIT>" ) <EOL> host1 = Host . objects . create ( hostname = "<STR_LIT>" , network = efnet ) <EOL> HostFormSet = inlineformset_factory ( Network , Host , fields = "<STR_LIT>" ) <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : six . text_type ( host1 . id ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> dalnet = Network . objects . create ( name = "<STR_LIT>" ) <EOL> formset = HostFormSet ( data , instance = dalnet , save_as_new = True ) <EOL> self . assertTrue ( formset . is_valid ( ) ) <EOL> formset . save ( ) <EOL> self . assertQuerysetEqual ( <EOL> dalnet . host_set . order_by ( "<STR_LIT>" ) , <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> ) <EOL> def test_initial_data ( self ) : <EOL> user = User . objects . create ( username = "<STR_LIT>" , serial = <NUM_LIT:1> ) <EOL> UserSite . objects . create ( user = user , data = <NUM_LIT:7> ) <EOL> FormSet = inlineformset_factory ( User , UserSite , extra = <NUM_LIT:2> , fields = "<STR_LIT>" ) <EOL> formset = FormSet ( instance = user , initial = [ { '<STR_LIT:data>' : <NUM_LIT> } , { '<STR_LIT:data>' : <NUM_LIT> } ] ) <EOL> self . assertEqual ( formset . forms [ <NUM_LIT:0> ] . initial [ '<STR_LIT:data>' ] , <NUM_LIT:7> ) <EOL> self . assertEqual ( formset . extra_forms [ <NUM_LIT:0> ] . initial [ '<STR_LIT:data>' ] , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , formset . extra_forms [ <NUM_LIT:1> ] . as_p ( ) ) <EOL> class FormsetTests ( TestCase ) : <EOL> def test_error_class ( self ) : <EOL> '''<STR_LIT>''' <EOL> Formset = modelformset_factory ( User , fields = "<STR_LIT>" ) <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> } <EOL> formset = Formset ( data ) <EOL> self . assertIsInstance ( formset . errors , list ) <EOL> self . assertIsInstance ( formset . non_form_errors ( ) , ErrorList ) <EOL> for form in formset . forms : <EOL> self . assertIsInstance ( form . errors , ErrorDict ) <EOL> self . assertIsInstance ( form . non_field_errors ( ) , ErrorList ) <EOL> def test_initial_data ( self ) : <EOL> User . objects . create ( username = "<STR_LIT>" , serial = <NUM_LIT:1> ) <EOL> Formset = modelformset_factory ( User , fields = "<STR_LIT>" , extra = <NUM_LIT:2> ) <EOL> formset = Formset ( initial = [ { '<STR_LIT:username>' : '<STR_LIT>' } , { '<STR_LIT:username>' : '<STR_LIT>' } ] ) <EOL> self . assertEqual ( formset . forms [ <NUM_LIT:0> ] . initial [ '<STR_LIT:username>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( formset . extra_forms [ <NUM_LIT:0> ] . initial [ '<STR_LIT:username>' ] , "<STR_LIT>" ) <EOL> self . assertIn ( '<STR_LIT>' , formset . extra_forms [ <NUM_LIT:1> ] . as_p ( ) ) <EOL> def test_extraneous_query_is_not_run ( self ) : <EOL> Formset = modelformset_factory ( Network , fields = "<STR_LIT>" ) <EOL> data = { '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , } <EOL> with self . assertNumQueries ( <NUM_LIT:1> ) : <EOL> formset = Formset ( data , prefix = "<STR_LIT:test>" ) <EOL> formset . save ( ) <EOL> class CustomWidget ( forms . widgets . TextInput ) : <EOL> pass <EOL> class UserSiteForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = UserSite <EOL> fields = "<STR_LIT>" <EOL> widgets = { <EOL> '<STR_LIT:id>' : CustomWidget , <EOL> '<STR_LIT:data>' : CustomWidget , <EOL> } <EOL> localized_fields = ( '<STR_LIT:data>' , ) <EOL> class Callback ( object ) : <EOL> def __init__ ( self ) : <EOL> self . log = [ ] <EOL> def __call__ ( self , db_field , ** kwargs ) : <EOL> self . log . append ( ( db_field , kwargs ) ) <EOL> return db_field . formfield ( ** kwargs ) <EOL> class FormfieldCallbackTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_inlineformset_factory_default ( self ) : <EOL> Formset = inlineformset_factory ( User , UserSite , form = UserSiteForm , fields = "<STR_LIT>" ) <EOL> form = Formset ( ) . forms [ <NUM_LIT:0> ] <EOL> self . assertIsInstance ( form [ '<STR_LIT:id>' ] . field . widget , CustomWidget ) <EOL> self . assertIsInstance ( form [ '<STR_LIT:data>' ] . field . widget , CustomWidget ) <EOL> self . assertFalse ( form . fields [ '<STR_LIT:id>' ] . localize ) <EOL> self . assertTrue ( form . fields [ '<STR_LIT:data>' ] . localize ) <EOL> def test_modelformset_factory_default ( self ) : <EOL> Formset = modelformset_factory ( UserSite , form = UserSiteForm ) <EOL> form = Formset ( ) . forms [ <NUM_LIT:0> ] <EOL> self . assertIsInstance ( form [ '<STR_LIT:id>' ] . field . widget , CustomWidget ) <EOL> self . assertIsInstance ( form [ '<STR_LIT:data>' ] . field . widget , CustomWidget ) <EOL> self . assertFalse ( form . fields [ '<STR_LIT:id>' ] . localize ) <EOL> self . assertTrue ( form . fields [ '<STR_LIT:data>' ] . localize ) <EOL> def assertCallbackCalled ( self , callback ) : <EOL> id_field , user_field , data_field = UserSite . _meta . fields <EOL> expected_log = [ <EOL> ( id_field , { '<STR_LIT>' : CustomWidget } ) , <EOL> ( user_field , { } ) , <EOL> ( data_field , { '<STR_LIT>' : CustomWidget , '<STR_LIT>' : True } ) , <EOL> ] <EOL> self . assertEqual ( callback . log , expected_log ) <EOL> def test_inlineformset_custom_callback ( self ) : <EOL> callback = Callback ( ) <EOL> inlineformset_factory ( User , UserSite , form = UserSiteForm , <EOL> formfield_callback = callback , fields = "<STR_LIT>" ) <EOL> self . assertCallbackCalled ( callback ) <EOL> def test_modelformset_custom_callback ( self ) : <EOL> callback = Callback ( ) <EOL> modelformset_factory ( UserSite , form = UserSiteForm , <EOL> formfield_callback = callback ) <EOL> self . assertCallbackCalled ( callback ) <EOL> class BaseCustomDeleteFormSet ( BaseFormSet ) : <EOL> """<STR_LIT>""" <EOL> def add_fields ( self , form , index ) : <EOL> super ( BaseCustomDeleteFormSet , self ) . add_fields ( form , index ) <EOL> self . can_delete = True <EOL> if DELETION_FIELD_NAME in form . fields : <EOL> del form . fields [ DELETION_FIELD_NAME ] <EOL> def _should_delete_form ( self , form ) : <EOL> return hasattr ( form , '<STR_LIT>' ) and form . should_delete ( ) <EOL> class FormfieldShouldDeleteFormTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> class BaseCustomDeleteModelFormSet ( BaseModelFormSet , BaseCustomDeleteFormSet ) : <EOL> """<STR_LIT>""" <EOL> class CustomDeleteUserForm ( forms . ModelForm ) : <EOL> """<STR_LIT>""" <EOL> class Meta : <EOL> model = User <EOL> fields = "<STR_LIT>" <EOL> def should_delete ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . instance . pk % <NUM_LIT:2> != <NUM_LIT:0> <EOL> NormalFormset = modelformset_factory ( User , form = CustomDeleteUserForm , can_delete = True ) <EOL> DeleteFormset = modelformset_factory ( User , form = CustomDeleteUserForm , formset = BaseCustomDeleteModelFormSet ) <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT:4>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT:4>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:3>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:5>' , <EOL> } <EOL> delete_all_ids = { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> } <EOL> def test_init_database ( self ) : <EOL> """<STR_LIT>""" <EOL> formset = self . NormalFormset ( self . data ) <EOL> self . assertTrue ( formset . is_valid ( ) ) <EOL> self . assertEqual ( len ( formset . save ( ) ) , <NUM_LIT:4> ) <EOL> def test_no_delete ( self ) : <EOL> """<STR_LIT>""" <EOL> self . test_init_database ( ) <EOL> data = dict ( self . data ) <EOL> data [ '<STR_LIT>' ] = <NUM_LIT:4> <EOL> data . update ( { <EOL> '<STR_LIT>' % i : user . pk <EOL> for i , user in enumerate ( User . objects . all ( ) ) <EOL> } ) <EOL> formset = self . NormalFormset ( data , queryset = User . objects . all ( ) ) <EOL> self . assertTrue ( formset . is_valid ( ) ) <EOL> self . assertEqual ( len ( formset . save ( ) ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( User . objects . all ( ) ) , <NUM_LIT:4> ) <EOL> def test_all_delete ( self ) : <EOL> """<STR_LIT>""" <EOL> self . test_init_database ( ) <EOL> data = dict ( self . data ) <EOL> data [ '<STR_LIT>' ] = <NUM_LIT:4> <EOL> data . update ( { <EOL> '<STR_LIT>' % i : user . pk <EOL> for i , user in enumerate ( User . objects . all ( ) ) <EOL> } ) <EOL> data . update ( self . delete_all_ids ) <EOL> formset = self . NormalFormset ( data , queryset = User . objects . all ( ) ) <EOL> self . assertTrue ( formset . is_valid ( ) ) <EOL> self . assertEqual ( len ( formset . save ( ) ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( User . objects . all ( ) ) , <NUM_LIT:0> ) <EOL> def test_custom_delete ( self ) : <EOL> """<STR_LIT>""" <EOL> self . test_init_database ( ) <EOL> data = dict ( self . data ) <EOL> data [ '<STR_LIT>' ] = <NUM_LIT:4> <EOL> data . update ( { <EOL> '<STR_LIT>' % i : user . pk <EOL> for i , user in enumerate ( User . objects . all ( ) ) <EOL> } ) <EOL> data . update ( self . delete_all_ids ) <EOL> formset = self . DeleteFormset ( data , queryset = User . objects . all ( ) ) <EOL> self . assertTrue ( formset . is_valid ( ) ) <EOL> self . assertEqual ( len ( formset . save ( ) ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( User . objects . all ( ) ) , <NUM_LIT:2> ) <EOL> odd_ids = [ user . pk for user in User . objects . all ( ) if user . pk % <NUM_LIT:2> ] <EOL> self . assertEqual ( len ( odd_ids ) , <NUM_LIT:0> ) <EOL> class RedeleteTests ( TestCase ) : <EOL> def test_resubmit ( self ) : <EOL> u = User . objects . create ( username = '<STR_LIT:foo>' , serial = <NUM_LIT:1> ) <EOL> us = UserSite . objects . create ( user = u , data = <NUM_LIT:7> ) <EOL> formset_cls = inlineformset_factory ( User , UserSite , fields = "<STR_LIT>" ) <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT:username>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : six . text_type ( us . pk ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' <EOL> } <EOL> formset = formset_cls ( data , instance = u ) <EOL> self . assertTrue ( formset . is_valid ( ) ) <EOL> formset . save ( ) <EOL> self . assertEqual ( UserSite . objects . count ( ) , <NUM_LIT:0> ) <EOL> formset = formset_cls ( data , instance = u ) <EOL> self . assertTrue ( formset . is_valid ( ) ) <EOL> formset . save ( ) <EOL> self . assertEqual ( UserSite . objects . count ( ) , <NUM_LIT:0> ) <EOL> def test_delete_already_deleted ( self ) : <EOL> u = User . objects . create ( username = '<STR_LIT:foo>' , serial = <NUM_LIT:1> ) <EOL> us = UserSite . objects . create ( user = u , data = <NUM_LIT:7> ) <EOL> formset_cls = inlineformset_factory ( User , UserSite , fields = "<STR_LIT>" ) <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT:username>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : six . text_type ( us . pk ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' <EOL> } <EOL> formset = formset_cls ( data , instance = u ) <EOL> us . delete ( ) <EOL> self . assertTrue ( formset . is_valid ( ) ) <EOL> formset . save ( ) <EOL> self . assertEqual ( UserSite . objects . count ( ) , <NUM_LIT:0> ) </s>
