def test_activate(self, connection_mock): conn = connection_mock.instance() connection_mock.return_value = conn db = conn[self.settings["mongodb.db_name"]] backend = MongoDBRegistrationBackend(self.settings, self.config) utcnow = datetime.datetime.utcnow() with patch('datetime.datetime'): datetime.datetime.utcnow.return_value = utcnow backend.activate("token") db.users.update.assert_called_once_with({"access_tokens.token":"token"}, {"$set":{"access_tokens.$.activated_timestamp":utcnow}}, safe=True)
def test_activate(self, connection_mock): conn = connection_mock.instance() connection_mock.return_value = conn db = conn[self.settings["mongodb.db_name"]] backend = MongoDBRegistrationBackend(self.settings, self.config) utcnow = datetime.datetime.utcnow() with patch('datetime.datetime'): datetime.datetime.utcnow.return_value = utcnow backend.activate("token") db.users.update.assert_called_once_with( {"access_tokens.token": "token"}, {"$set": { "access_tokens.$.activated_timestamp": utcnow }}, safe=True)
def test_activation(self): backend = MongoDBRegistrationBackend(self.settings, self.config) struct = { "username": "******", "password": "******", "email": "*****@*****.**" } backend.add_user(struct) user_doc = self.db.users.find_one({"username": struct["username"]}) self.assertEquals(user_doc["username"], struct["username"]) self.assertEquals(user_doc["email"], struct["email"]) self.assertNotEquals(user_doc["password"], struct["password"]) # User has been added - verify it has no activated tokens for token in user_doc.get("access_tokens", []): self.assertFalse(token.get("activated_timestamp")) # Issue a token for this user access_token = backend.issue_access_token(user_doc["_id"]) # Verify user has this access token in their user document user_doc = self.db.users.find_one({"username": struct["username"]}) doc_token = False for token in user_doc.get("access_tokens", []): if token.get("token") == access_token: doc_token = token break self.assertEquals(doc_token["token"], access_token) # Verify this token is not activated self.assertFalse(doc_token.get("activated_timestamp")) # Ensure verify_access_token on this token returns False self.assertFalse(backend.verify_access_token(access_token)) # Now activate the token, and assert that the token is marked as # activated in the database. backend.activate(access_token) user_doc = self.db.users.find_one({"username": struct["username"]}) doc_token = False for token in user_doc.get("access_tokens", []): if token.get("token") == access_token: self.assertTrue(token.get("activated_timestamp")) break # Ensure verify_access_token on this token returns the user_id userid = backend.verify_access_token(access_token) self.assertEquals(userid, str(user_doc["_id"]))
def test_activation(self): backend = MongoDBRegistrationBackend(self.settings, self.config) struct = {"username":"******", "password":"******", "email":"*****@*****.**"} backend.add_user(struct) user_doc = self.db.users.find_one({"username":struct["username"]}) self.assertEquals(user_doc["username"], struct["username"]) self.assertEquals(user_doc["email"], struct["email"]) self.assertNotEquals(user_doc["password"], struct["password"]) # User has been added - verify it has no activated tokens for token in user_doc.get("access_tokens", []): self.assertFalse(token.get("activated_timestamp")) # Issue a token for this user access_token = backend.issue_access_token(user_doc["_id"]) # Verify user has this access token in their user document user_doc = self.db.users.find_one({"username":struct["username"]}) doc_token = False for token in user_doc.get("access_tokens", []): if token.get("token") == access_token: doc_token = token break self.assertEquals(doc_token["token"], access_token) # Verify this token is not activated self.assertFalse(doc_token.get("activated_timestamp")) # Ensure verify_access_token on this token returns False self.assertFalse(backend.verify_access_token(access_token)) # Now activate the token, and assert that the token is marked as # activated in the database. backend.activate(access_token) user_doc = self.db.users.find_one({"username":struct["username"]}) doc_token = False for token in user_doc.get("access_tokens", []): if token.get("token") == access_token: self.assertTrue(token.get("activated_timestamp")) break # Ensure verify_access_token on this token returns the user_id userid = backend.verify_access_token(access_token) self.assertEquals(userid, str(user_doc["_id"]))