def test_create(self): ReleatedModelFormSet = inlineformset_factory(SimpleModel, ReleatedModel, extra=2) obj = SimpleModel.objects.create(name="test") data = { 'releatedmodel_set-TOTAL_FORMS': u'2', 'releatedmodel_set-INITIAL_FORMS': u'0', 'releatedmodel_set-MAX_NUM_FORMS': u'', 'releatedmodel_set-0-name': u'test 0', 'releatedmodel_set-1-name': u'test 1' } formset = ReleatedModelFormSet(data, instance=obj) self.assertTrue(formset.is_valid()) formset.save() log = History.log.inlineformset(formset) self.assertEqual(len(log), 3) self.assertEqual(log[0].content_object, obj) self.assertTrue(all([element.action == History.ADDITION for element in log[1:]])) log = History.log(formset) self.assertEqual(len(log), 3) self.assertEqual(log[0].content_object, obj) self.assertTrue(all([element.action == History.ADDITION for element in log[1:]]))
def test_create(self): obj = SimpleModel.objects.create(name="test") log = History.log.obj(obj) self.assertEqual(log.action, History.ADDITION) log = History.log(obj) self.assertEqual(log.action, History.ADDITION)
def test_message(self): message = "message" obj = SimpleModel.objects.create(name="test") log = History.log.obj(obj, message) self.assertEqual(log.message, message) log = History.log(obj, message) self.assertEqual(log.message, message)
def test_create(self): form = SimpleModelForm({"name": "test"}) self.assertTrue(form.is_valid()) form.save() log = History.log.form(form) self.assertEqual(log.action, History.ADDITION) log = History.log(form) self.assertEqual(log.action, History.ADDITION)
def test_create(self): SimpleModelFormSet = modelformset_factory(SimpleModel, extra=2) data = { 'form-TOTAL_FORMS': 2, 'form-INITIAL_FORMS': 0, 'form-0-name': u'test 1', 'form-1-name': u'test 2', } formset = SimpleModelFormSet(data) self.assertTrue(formset.is_valid()) formset.save() log = History.log.formset(formset) self.assertEqual(len(log), 2) self.assertTrue(all([element.action == History.ADDITION for element in log])) log = History.log(formset) self.assertEqual(len(log), 2) self.assertTrue(all([element.action == History.ADDITION for element in log]))