-1
I need to give a post
in a "request creation" view of mine, but when I try to give the post
, I am redirected to my login screen, I am trying to log into the system to then give the post in this view, but I was not successful. Someone could help me?
tests py.
class OrderRegisterView(TestCase):
def test_order_register_view(self):
c = Client()
User.objects.create_user('teste', 'teste', 'teste')
c.login(username='teste', password='teste', follow=True)
response = c.post('/pedidos/cadastro/', {'username':'teste', 'password': 'teste','ship_date':'12/04/14', 'ship_time': 'morning', 'truck': 7, 'city': 4304606, 'value': 12, 'action': 'selected', 'cheapest': True}, follow=True)
# self.assertRedirects(response, '/login/')
Don’t move, don’t give me any mistakes, just pass OK.
Are you trying to test the View or Form? If you are testing the form, the ideal is to instantiate it within the test with the values you want to use.
– Rodrigo Deodoro
The order registration that I am testing, goes through the form and if it is valid, the view itself, creates the Order() object, wanted to test this process, so I just needed to generate the POST in this view, so that it creates the Order itself.
– Guilms
Yes, but what exactly do you want to test? The validation of form data or the creation of Order by view? If it’s just the validation, you should do what I guided in the previous comment; if it’s the creation of the Order by the view: try passing the data through the kwarg
data=
, p ex..c.post('/pedidos/cadastro/', data={'username': 'teste'....}
.– Rodrigo Deodoro
I’m trying to test the creation of Order by view, I’m doing exactly that, passing the parameters in the post, but when I give the post in the order/registration, I’m redirected to the login screen, and nothing happens, even passing the username and pass in the post, I tried several ways to go through the login screen and nothing happened, so I can’t give the post on this screen of /orders/registration/
– Guilms
This question seems to be decontextualized because it is about a problem unrelated to what was asked, already solved by the author of the question.
– mgibsonbr