Created
December 6, 2013 10:37
-
-
Save murilobsd/7821761 to your computer and use it in GitHub Desktop.
error in post data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CyclePostTest(TestCase): | |
def setUp(self): | |
user = User.objects.create_user('murilo', 'murilo@murilo.com', 'murilo') | |
farm = Farm.objects.create(user=user, name='teste', full_area='123.45', uncultivated_area='0.00') | |
self.client.login(username='murilo', password='murilo') | |
data = dict(farm=farm, user=user, name='2014') | |
self.resp = self.client.post('/ciclo/cadastrar/', data) | |
def test_post(self): | |
'Valid Post should redirect to /ciclo/1/.' | |
self.assertEqual(302, self.resp.status_code) | |
def test_save(self): | |
'Valid POST must be saved' | |
self.assertTrue(Cycle.objects.exists()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_cycle(request): | |
form = RegCycleForm(user=request.user, data=request.POST) | |
if not form.is_valid(): | |
messages.warning(request, 'Erro no cadastro do ciclo.') | |
return render(request, 'gerenciador/reg_cycle.html', {'form': form }) | |
obj = form.save(commit=False) | |
obj.user = request.user | |
obj.save() | |
messages.success(request, 'Ciclo cadastrado com sucesso !!!') | |
return HttpResponseRedirect('/ciclo/%d' % obj.pk) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment