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 setUp(self): super(TestAddUser, self).setUp() self.test_user = User("*****@*****.**", password="******") self.user_id = self._driver.save_user(self.test_user) self.test_draw = RandomNumberDraw(number_of_results=1, is_shared=True) self._driver.save_draw(self.test_draw) self.req = lambda: None self.req.user = self.test_user
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)
def retrieve_user(self, user_id): doc = self._users.find_one({"_id": user_id}) if doc is None: raise MongoDriver.NotFoundError("User not found: {0}".format(user_id)) logger.debug("Retrieved documment: {0} using id {1}".format(doc, user_id)) return User(**doc)
def setUp(self): self.draw = RandomNumberDraw(is_shared=True) self.user = User("test")
def draw_with_another_owner_user_not_in_list_test(self): self.draw.owner = User("another guy") self.draw.users.append("anotherguy") self.assertTrue(self.draw.check_read_access(self.user))
def draw_with_another_owner_test_empty_user_list(self): self.draw.owner = User("another guy") self.assertTrue(self.draw.check_read_access(self.user))
def draw_with_another_owner_test(self): self.draw.owner = User("another guy") self.assertFalse(self.draw.check_write_access(self.user))
def setUp(self): self.draw = RandomNumberDraw() self.user = User("test")
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 )