def test_form_save(self): form = EventForm(self.form_values) self.assertTrue(form.is_valid()) form.save() self.assertEqual(Event.objects.all().count(), 1) event = Event.objects.get(name=self.form_values['name']) self.assertEqual(event.tags.all().count(), 2)
def test_edit_form(self): form_data = self.event_form_data form_data['name'] = 'Test Edit Form' event = EventForm(form_data) event.is_valid() event.save() event = Event.objects.get(name='Test Edit Form') form_data['name'] = 'Test Edit Form 2' request = self.factory.post('/event/edit/%s' % event.id, form_data) results = edit_form(request, Event, EventForm, event.id) self.assertTrue('success_message' in results)
def test_update_model_from_form(self): tags = Tag.objects.all() dt = datetime.datetime(2013, 10, 11, 12, 41, 00) event = Event.objects.create(name='Test1', short_description='Test1', description='Test1', event_date=dt.isoformat() ) tags = [tag for tag in tags] event.tags.add(*tags) event_id = event.id self.assertTrue(event.tags.all().count() > 1) dt = datetime.datetime(2009, 11, 11, 10, 00, 00) form = EventForm({'name': 'Test2', 'short_description': 'Test2', 'description': 'Test2', 'contact': '*****@*****.**', 'event_date': '2009-11-11 00:00:00', 'applications': 'icadmin', 'contacts': '*****@*****.**'}) self.assertTrue(form.is_valid()) event = update_model_from_form(event, form) event = Event.objects.get(pk=event_id) self.assertEqual(event.tags.count(), 1)