def register(request): """Registers a user Serves a web to register the user Register and logs the user in if POST data is provided """ logout(request) context = {} if request.POST: email = request.POST['email'] password = request.POST['password'] u = User(email) u.set_password(password) try: MONGO.create_user(u) ga_track_event(category="user", action="registration") return login_user(request) except Exception: context = {'error': _("The email is already registered.")} return render(request, 'register.html', context)
class TestUpdateUserProfile(TestServices): """ Test the update user service """ def setUp(self): super(TestUpdateUserProfile, self).setUp() self.tested_user = User("*****@*****.**") self.tested_user.set_password("fake_pwd") self.user_id = self._driver.save_user(self.tested_user) self.req = lambda: None self.req.user = self.tested_user def tearDown(self): self._driver._users.remove({"_id": self.user_id}) def update_email_test(self): """Test updating the email of an user""" self.req.POST = {"email": "[email protected]"} update_user(self.req) self.assertEqual( "*****@*****.**", # "[email protected]", self._driver.retrieve_user(self.tested_user._id).pk ) def update_password_ok_test(self): """Test updating the password of an user""" self.req.POST = {"current_password": "******", "new_password": "******"} update_user(self.req) self.assertTrue( self._driver.retrieve_user(self.tested_user._id).check_password( "new_awesome_password" ) ) def update_password_ko_test(self): """Test updating the password of an user""" self.req.POST = {"current_password": "******", "new_password": "******"} update_user(self.req) self.assertFalse( self._driver.retrieve_user(self.tested_user._id).check_password( "new_awesome_password" ) ) def update_alias_test(self): """Test updating the alias of an user""" self.req.POST = {"alias": "the_coolest_alias"} update_user(self.req) self.assertEqual( "the_coolest_alias", self._driver.retrieve_user(self.tested_user._id).alias ) def update_avatar_test(self): """Test updating the avatar of an user""" self.req.POST = {"use_gravatar" : "true"} update_user(self.req) self.assertEqual( True, self._driver.retrieve_user(self.tested_user._id).use_gravatar )