def testFormCorrectData(self): """Creates a event form with valid information""" f = EventForm(correct_data) assert ( f.is_valid() is True ), "Correct set of event data but form\
def testSaveFromForm(self): """Adds a user with valid information""" f = EventForm(correct_data) if f.is_valid(): event_data = f.save(commit=False) user = User.objects.get(username="******") event_data.save(editor=user, new=True) assert Event.objects.get(name="TestEvent1"), "couldnt add event"
def testFormWrongData(self): """Creates a event form with invalid information""" f = EventForm(self.wrong_data) assert ( f.is_valid() is False ), "Name of the event is missing, but no\ error raised" assert ( f.errors["name"] != "" ), "Name of the event is missing, but no \ error raised" assert f.errors["startDate"] != "", "Wrong date, but no error raised" assert f.errors["endDate"] != "", "Wrong time, but no error raised" assert ( f.errors["wikiPage"] != "" ), "Wikipage missing, but no error \ raised" print f.errors
def update_event(request, new, object_id=None): if not request.POST or not request.user.is_authenticated(): #return pass if not new: event = Event.all.get(id=object_id) else: event = Event() event_error_id = None event_valid = True if request.method == 'POST': event_form = EventForm(request.POST, instance=event) if event_form.is_valid(): event_data = event_form.save(commit=False) event_data.save(request.user, new) event = Event.objects.get(id=event_data.id) else: event_valid = False event_error_id = event.id else: event_form = EventForm() response = render_to_response('cal/eventinfo_nf.inc', { 'event_has_error': not event_valid, 'event_form': event_form, 'event': event, 'new': not event.pk, }, context_instance=RequestContext(request)) if not event_valid: response.status_code = 500 return response