def test_form_invalid_ip(self):
		'Empty or invalid client ip address is not valid'
		data = self.valid_data()
		data['client_ip'] =  ''
		form = ProxylogForm(data)
		self.assertFalse(form.is_valid())
		self.assertIn('client_ip', form.errors)

		data = self.valid_data()
		data['client_ip'] = '200.300.400.500'
		form = ProxylogForm(data)
		self.assertFalse(form.is_valid())
		self.assertIn('client_ip', form.errors)
	def test_form_invalid_url(self):
		'Empty or invalid url is not valid'
		data = self.valid_data()
		data['url'] = ''
		form = ProxylogForm(data)
		self.assertFalse(form.is_valid())
		self.assertIn('url', form.errors)

		data = self.valid_data()
		data['url'] = 'webeholder.com.br index.html'
		form = ProxylogForm(data)
		self.assertFalse(form.is_valid())
		self.assertIn('url', form.errors)
	def test_form_invalid_access_time(self):
		'Empty or invalid access_time is not valid. access_time is only valid within format %Y-%m-%d %H:%M:%S'
		data = self.valid_data()
		data['access_time'] =  ''
		form = ProxylogForm(data)
		self.assertFalse(form.is_valid())
		self.assertIn('access_time', form.errors)

		data = self.valid_data()
		data['access_time'] = '11/02/2013 18:13:10'
		form = ProxylogForm(data)
		self.assertFalse(form.is_valid())
		self.assertIn('access_time', form.errors)
Exemplo n.º 4
0
def consumer(request):
	if request.method == 'POST':
		form = ProxylogForm(request.POST)
		if not form.is_valid():
			resp = HttpResponse('Invalid data')
			resp.status_code = 400
			return resp
		obj = Proxylog(**form.cleaned_data)
		obj.save()
		return HttpResponse(unicode(obj))
	return HttpResponse('proxylog.consumer')
	def test_form_valid_data(self):
		'When receiving valid data form.is_valid must return True'
		data = self.valid_data()
		form = ProxylogForm(data)
		self.assertTrue(form.is_valid())
		self.assertEqual(form.errors, {})