def test_edit_register_user_form_invalid(self): request = self.factory.post("/newuser/", self.data) request.user = AnonymousUser() request = add_middleware_to_request(request, SessionMiddleware) request.session.save() response = RegisterUser.as_view()(request) new_user = User.objects.get(email="*****@*****.**") new_data = {"id": new_user.id, "username": "******", "email": "*****@*****.**"} request = self.factory.post("/newuser/", new_data) response = RegisterUser.as_view()(request) context = response.context_data self.assertFalse(context['form'].is_valid())
def test_register_user_form(self): request = self.factory.get("/newuser/") request.user = AnonymousUser() request = add_middleware_to_request(request, SessionMiddleware) request.session.save() response = RegisterUser.as_view()(request) self.assertContains(response, "Cadastre-se grátis")
def test_edit_register_user_form_valid(self): request = self.factory.post("/newuser/", self.data) request.user = AnonymousUser() request = add_middleware_to_request(request, SessionMiddleware) request.session.save() response = RegisterUser.as_view()(request) new_user = User.objects.get(email="*****@*****.**") new_data = {"id": new_user.id, "username": "******", "email": "*****@*****.**", "first_name": "John", "last_name": "Doe", "password": "******", "organization": "org_teste"} request = self.factory.post("/newuser/", new_data) response = RegisterUser.as_view()(request) user_edited = User.objects.get(email="*****@*****.**") self.assertEqual(new_user.first_name, "John")
def test_register_user_form(self): request = self.factory.get("/newuser/") request.user = AnonymousUser() request = add_middleware_to_request(request, SessionMiddleware) request.session.save() response = RegisterUser.as_view()(request) self.assertContains(response, "Cadastro de Usuário")
def test_register_user_form_valid(self): request = self.factory.post("/newuser/", self.data) request.user = AnonymousUser() request = add_middleware_to_request(request, SessionMiddleware) request.session.save() response = RegisterUser.as_view()(request) self.assertEqual(response.status_code, 302) new_user = User.objects.get(email="*****@*****.**") self.assertEqual(new_user.first_name, "John")
def create_user(self, username="******", email="*****@*****.**", first_name="John", last_name="Doe", password="******", organization="org_teste"): self.data['username'] = username self.data['email'] = email self.data['first_name'] = first_name self.data['last_name'] = last_name self.data['password'] = password self.data['organization'] = organization request = self.factory.post("/newuser/", self.data) request.user = AnonymousUser() request = add_middleware_to_request(request, SessionMiddleware) request.session.save() response = RegisterUser.as_view()(request) return User.objects.get(email=email)