def testMessage(self): """ This simulates the 'test' application that keeps its own data in the 'user' collection in the 'test' DB and sends a message notifying the attribute manager instance (am) about a new entry in its dataset thereby calling the plugin (above) which is registered with the am in the test setup below. """ test_context = AmTestUserDb(db_uri=self.tmp_db.uri, db_name='eduid_am_test') # register fake AMP plugin named 'test' self.am.registry.attribute_fetcher['test'] = plugin_attribute_fetcher self.am.registry.context['test'] = test_context _id = ObjectId() userdoc = {'_id': _id, 'eduPersonPrincipalName': 'foo-bar', 'uid': 'vlindeman', 'passwords': [{'id': ObjectId('112345678901234567890123'), 'salt': '$NDNv1H1$9c81...545$32$32$', }], } test_user = AmTestUser(userdoc) # Save the user in the eduid_am_test database test_context.save(test_user) # It is important to not import eduid_am.tasks before the Celery config has been # set up (done in MongoTestCase.setUp()). Since Celery uses decorators, it will # have instantiated AttributeManagers without the right config if the import is # done prior to the Celery app configuration. from eduid_am.tasks import update_attributes update_attributes.delay(app_name='test', obj_id=str(_id)) # verify the user has been propagated to the amdb am_user = self.amdb.get_user_by_id(_id) self.assertEqual(am_user.eppn, '*****@*****.**')
def testMessage(self): """ This simulates the 'test' application that keeps its own data in the 'user' collection in the 'test' DB and sends a message notifying the attribute manager instance (am) about a new entry in its dataset thereby calling the plugin (above) which is registered with the am in the test setup below. """ test_context = AmTestUserDb(db_uri = self.tmp_db.get_uri(''), db_name='eduid_am_test') # register fake AMP plugin named 'test' self.am.registry.attribute_fetcher['test'] = plugin_attribute_fetcher self.am.registry.context['test'] = test_context _id = ObjectId() userdoc = {'_id': _id, 'eduPersonPrincipalName': 'foo-bar', 'uid': 'vlindeman', 'passwords': [{'id': ObjectId('112345678901234567890123'), 'salt': '$NDNv1H1$9c81...545$32$32$', }], } test_user = AmTestUser(userdoc) # Save the user in the eduid_am_test database test_context.save(test_user) # It is important to not import eduid_am.tasks before the Celery config has been # set up (done in MongoTestCase.setUp()). Since Celery uses decorators, it will # have instantiated AttributeManagers without the right config if the import is # done prior to the Celery app configuration. from eduid_am.tasks import update_attributes update_attributes.delay(app_name='test', obj_id = _id) # verify the user has been propagated to the amdb am_user = self.amdb.get_user_by_id(_id) self.assertEqual(am_user.eppn, '*****@*****.**')
def testMessage(self): """ This simulates the 'test' application that keeps its own data in the 'user' collection in the 'test' DB and sends a message notifying the attribute manager instance (am) about a new entry in its dataset thereby calling the plugin (above) which is registered with the am in the test setup below. """ settings = { 'BROKER_TRANSPORT': 'memory', 'BROKER_URL': 'memory://', 'CELERY_EAGER_PROPAGATES_EXCEPTIONS': True, 'CELERY_ALWAYS_EAGER': True, 'CELERY_RESULT_BACKEND': "cache", 'CELERY_CACHE_BACKEND': 'memory', 'MONGO_URI': 'mongodb://*****:*****@eduid.se') user = am.get_user_by_field('eppn', '*****@*****.**') assert (user['_id'] == attrs['_id'])
def testMessage(self): """ This simulates the 'test' application that keeps its own data in the 'user' collection in the 'test' DB and sends a message notifying the attribute manager instance (am) about a new entry in its dataset thereby calling the plugin (above) which is registered with the am in the test setup below. """ settings = { 'BROKER_TRANSPORT': 'memory', 'BROKER_URL': 'memory://', 'CELERY_EAGER_PROPAGATES_EXCEPTIONS': True, 'CELERY_ALWAYS_EAGER': True, 'CELERY_RESULT_BACKEND': "cache", 'CELERY_CACHE_BACKEND': 'memory', 'MONGO_URI': 'mongodb://*****:*****@eduid.se') user = am.get_user_by_field('eppn', '*****@*****.**') assert(user['_id'] == attrs['_id'])
def propagate_user_changes(self, newuser): if self.workmode == 'personal': # Only update session if user is the same as currently in session user = self.request.session.get('user') newuser = User(newuser) if user.get_id() == newuser.get_id(): self.request.session['user'] = newuser else: user_session = self.request.session['user'].get(self.main_attribute) if user_session == newuser[self.main_attribute]: self.request.session['user'] = User(newuser) update_attributes.delay('eduid_dashboard', str(newuser['_id']))
def update_am(self, app_name): update_attributes.delay(app_name, str(self._mongo_doc['_id']))
def propagate_user_changes(self, user): update_attributes.delay('eduid_dashboard', str(user['_id']))