def add_spittle(request): """ Adds spittle to current spittle list """ if request.method == 'POST': form = AddSpittleForm(request.POST, request.FILES) if form.is_valid(): spittle = Spittle() spittle.message = form.cleaned_data['message'] spittle.title = form.cleaned_data['subject'] file = form.cleaned_data['file'] if file is not None and is_valid_image(file): spittle.image = True Spittle.save(spittle) handle_uploaded_file(file, spittle.identity) return render_to_response('add_spittle.html', RequestContext(request, {'form': AddSpittleForm(), 'delta': 1}) ) return render_to_response('add_spittle.html', RequestContext(request, {'form': form, 'delta': 0}) ) else: form = AddSpittleForm() return render_to_response('add_spittle.html', RequestContext(request, {'form': form}) )
def testCountSpittle(self): """ Test spittle count functionality """ response = self.app.get(reverse('list_spittles')) self.assertEqual(response.context['spittle_count'], self.count) assert self.count in response response = self.app.get(reverse('add_spittle')) self.assertEqual(response.context['spittle_count'], self.count) assert self.count in response spittle = Spittle() spittle.title = u'Title' spittle.message = u'New short spittle!' Spittle.save(spittle) response = self.app.get(reverse('list_spittles')) self.assertEqual(response.context['spittle_count'], self.count + 1) assert self.count + 1 in response