Пример #1
0
    def test_process_email_then_review(self):
        # it is expected that the user profile will contain both email and
        # ldap-id
        record_processor_inst = self.make_record_processor()

        list(record_processor_inst.process([
            {'record_type': 'email',
             'message_id': '<message-id>',
             'author_email': '*****@*****.**',
             'subject': 'hello, world!',
             'body': 'lorem ipsum',
             'date': 1234567890},
            {'record_type': 'review',
             'id': 'I1045730e47e9e6ad31fcdfbaefdad77e2f3b2c3e',
             'subject': 'Fix AttributeError in Keypair._add_details()',
             'owner': {'name': 'John Doe',
                       'email': '*****@*****.**',
                       'username': '******'},
             'createdOn': 1379404951,
             'module': 'nova', 'branch': 'master'}
        ]))

        user = {'seq': 1,
                'core': [],
                'user_id': 'john_doe',
                'ldap_id': 'john_doe',
                'user_name': 'John Doe',
                'emails': ['*****@*****.**'],
                'companies': [{'company_name': '*independent', 'end_date': 0}]}
        self.assertEqual(user, utils.load_user(
            record_processor_inst.runtime_storage_inst, '*****@*****.**'))
        self.assertEqual(user, utils.load_user(
            record_processor_inst.runtime_storage_inst, 'john_doe'))
Пример #2
0
    def test_process_commit_then_review_with_different_email(self):
        # In this case, we don't know how to associate the email from the
        # commit with the LDAP ID so two users are created.

        record_processor_inst = self.make_record_processor(
            companies=[{'company_name': 'IBM', 'domains': ['ibm.com']}])

        list(record_processor_inst.process([
            {'record_type': 'commit',
             'commit_id': 'de7e8f297c193fb310f22815334a54b9c76a0be1',
             'author_name': 'John Doe', 'author_email': '*****@*****.**',
             'date': 1234567890, 'lines_added': 25, 'lines_deleted': 9,
             'release_name': 'havana'},
            {'record_type': 'review',
             'id': 'I1045730e47e9e6ad31fcdfbaefdad77e2f3b2c3e',
             'subject': 'Fix AttributeError in Keypair._add_details()',
             'owner': {'name': 'Bill Smith', 'email': '*****@*****.**',
                       'username': '******'},
             'createdOn': 1379404951, 'module': 'nova', 'branch': 'master',
             'patchSets': [
                 {'number': '1',
                  'revision': '4d8984e92910c37b7d101c1ae8c8283a2e6f4a76',
                  'ref': 'refs/changes/16/58516/1',
                  'uploader': {'name': 'Bill Smith', 'email': '*****@*****.**',
                               'username': '******'},
                  'createdOn': 1385470730,
                  'approvals': [
                      {'type': 'Code-Review', 'description': 'Code Review',
                       'value': '1', 'grantedOn': 1385478464,
                       'by': {'name': 'John Doe', 'email': '*****@*****.**',
                              'username': '******'}}]}]}
        ]))
        userA = {'seq': 3,
                 'user_id': 'john_doe',
                 'ldap_id': 'john_doe',
                 'user_name': 'John Doe',
                 'emails': ['*****@*****.**'],
                 'companies': [{'company_name': 'IBM', 'end_date': 0}]}
        userB = {'seq': 1,
                 'user_id': '*****@*****.**',
                 'ldap_id': None,
                 'user_name': 'John Doe',
                 'emails': ['*****@*****.**'],
                 'companies': [{'company_name': '*independent',
                                'end_date': 0}]}
        self.assertEqual(userA, utils.load_user(
            record_processor_inst.runtime_storage_inst, 'john_doe'))
        self.assertEqual(userB, utils.load_user(
            record_processor_inst.runtime_storage_inst, '*****@*****.**'))
        self.assertEqual(userA, utils.load_user(
            record_processor_inst.runtime_storage_inst, '*****@*****.**'))
Пример #3
0
    def test_update_member_ldap(self):
        member_record = {
            'member_id': 'dave-tucker',
            'ldap_id': 'dave-tucker',
            'member_name': 'Dave Tucker',
            'date_joined': None,
            'country': 'Great Britain',
            'company_draft': 'Red Hat',
            'email': '*****@*****.**'
        }

        record_processor_inst = self.make_record_processor()

        updated_member_record = member_record
        updated_member_record['member_name'] = 'Baldrick'
        updated_member_record['company_draft'] = 'HP'

        result_member = record_processor_inst._process_member(
            updated_member_record).next()
        self.assertEqual(result_member['author_name'], 'Baldrick')
        self.assertEqual(result_member['company_name'], 'HP')

        result_user = utils.load_user(
            record_processor_inst.runtime_storage_inst, 'dave-tucker')

        self.assertEqual(result_user['user_name'], 'Baldrick')
        self.assertEqual(result_user['companies'], [{
            'company_name': 'HP',
            'end_date': 0
        }])
Пример #4
0
    def test_update_member(self):
        member_record = {
            'member_id': '123456789',
            'member_name': 'John Doe',
            'member_uri': 'http://www.openstack.org/community'
            '/members/profile/123456789',
            'date_joined': 'August 01, 2012 ',
            'company_draft': 'Mirantis'
        }

        record_processor_inst = self.make_record_processor()

        updated_member_record = member_record
        updated_member_record['member_name'] = 'Bill Smith'
        updated_member_record['company_draft'] = 'Rackspace'

        result_member = record_processor_inst._process_member(
            updated_member_record).next()
        self.assertEqual(result_member['author_name'], 'Bill Smith')
        self.assertEqual(result_member['company_name'], 'Rackspace')

        result_user = utils.load_user(
            record_processor_inst.runtime_storage_inst, 'member:123456789')

        self.assertEqual(result_user['user_name'], 'Bill Smith')
        self.assertEqual(result_user['companies'], [{
            'company_name': 'Rackspace',
            'end_date': 0
        }])
Пример #5
0
    def test_create_member(self):
        member_record = {
            'member_id': '123456789',
            'member_name': 'John Doe',
            'member_uri': 'http://www.openstack.org/community'
            '/members/profile/123456789',
            'date_joined': 'August 01, 2012 ',
            'company_draft': 'Mirantis'
        }

        record_processor_inst = self.make_record_processor()
        result_member = record_processor_inst._process_member(
            member_record).next()

        self.assertEqual(result_member['primary_key'], 'member:123456789')
        self.assertEqual(result_member['date'],
                         utils.member_date_to_timestamp('August 01, 2012 '))
        self.assertEqual(result_member['author_name'], 'John Doe')
        self.assertEqual(result_member['company_name'], 'Mirantis')

        result_user = utils.load_user(
            record_processor_inst.runtime_storage_inst, 'member:123456789')

        self.assertEqual(result_user['user_name'], 'John Doe')
        self.assertEqual(result_user['company_name'], 'Mirantis')
        self.assertEqual(result_user['companies'], [{
            'company_name': 'Mirantis',
            'end_date': 0
        }])
Пример #6
0
    def test_update_member_ldap(self):
        member_record = {'member_id': 'dave-tucker',
                         'ldap_id': 'dave-tucker',
                         'member_name': 'Dave Tucker',
                         'date_joined': None,
                         'country': 'Great Britain',
                         'company_draft': 'Red Hat',
                         'email': '*****@*****.**'}

        record_processor_inst = self.make_record_processor()

        updated_member_record = member_record
        updated_member_record['member_name'] = 'Baldrick'
        updated_member_record['company_draft'] = 'HP'

        result_member = record_processor_inst._process_member(
            updated_member_record).next()
        self.assertEqual(result_member['author_name'], 'Baldrick')
        self.assertEqual(result_member['company_name'], 'HP')

        result_user = utils.load_user(
            record_processor_inst.runtime_storage_inst, 'dave-tucker')

        self.assertEqual(result_user['user_name'], 'Baldrick')
        self.assertEqual(result_user['companies'],
                         [{'company_name': 'HP', 'end_date': 0}])
Пример #7
0
    def test_process_commit_existing_user_new_email_known_company(self):
        # User is known but his email is new to us, and maps to other
        # company. Will create a new user with no ldap_id
        record_processor_inst = self.make_record_processor(
            users=[
                {'user_id': 'john_doe',
                 'ldap_id': 'john_doe',
                 'user_name': 'John Doe',
                 'emails': ['*****@*****.**'],
                 'companies': [{'company_name': 'NEC', 'end_date': 0}]}
            ],
            companies=[{'company_name': 'IBM', 'domains': ['ibm.com']}])

        processed_commit = list(record_processor_inst.process(
            generate_commits(author_email='*****@*****.**',
                             author_name='John Doe')))[0]

        expected_commit = {
            'ldap_id': None,
            'author_email': '*****@*****.**',
            'author_name': 'John Doe',
            'company_name': 'IBM',
        }

        self.assertRecordsMatch(expected_commit, processed_commit)
        self.assertIn('*****@*****.**', utils.load_user(
            record_processor_inst.runtime_storage_inst,
            '*****@*****.**')['emails']
        )
Пример #8
0
    def test_update_member(self):
        member_record = {'member_id': '123456789',
                         'member_name': 'John Doe',
                         'member_uri': 'http://www.openstack.org/community'
                                       '/members/profile/123456789',
                         'date_joined': 'August 01, 2012 ',
                         'company_draft': 'Mirantis'}

        record_processor_inst = self.make_record_processor()

        updated_member_record = member_record
        updated_member_record['member_name'] = 'Bill Smith'
        updated_member_record['company_draft'] = 'Rackspace'

        result_member = record_processor_inst._process_member(
            updated_member_record).next()
        self.assertEqual(result_member['author_name'], 'Bill Smith')
        self.assertEqual(result_member['company_name'], 'Rackspace')

        result_user = utils.load_user(
            record_processor_inst.runtime_storage_inst, 'member:123456789')

        self.assertEqual(result_user['user_name'], 'Bill Smith')
        self.assertEqual(result_user['companies'],
                         [{'company_name': 'Rackspace', 'end_date': 0}])
Пример #9
0
    def _process_member(self, record):
        user_id = "member:" + record['member_id']
        record['primary_key'] = user_id
        record['date'] = utils.member_date_to_timestamp(record['date_joined'])
        record['author_name'] = record['member_name']
        record['country'] = record.get("country")
        record['email'] = record.get("email")
        record['module'] = 'unknown'
        company_draft = record['company_draft']

        company_name = self.domains_index.get(utils.normalize_company_name(
            company_draft)) or company_draft

        # author_email is a key to create new user
        record['author_email'] = record["email"] or user_id
        record['company_name'] = company_name
        # _update_record_and_user function will create new user if needed
        self._update_record_and_user(record)
        record['company_name'] = company_name
        user = utils.load_user(self.runtime_storage_inst,
                               record['user_id'] or user_id)
        user['user_name'] = record['author_name']
        user['companies'] = [{
            'company_name': company_name,
            'end_date': 0,
        }]
        user['company_name'] = company_name

        utils.store_user(self.runtime_storage_inst, user)

        record['company_name'] = company_name

        yield record
Пример #10
0
def _store_users(runtime_storage_inst, users):
    for user in users:
        stored_user = utils.load_user(runtime_storage_inst, user['user_id'])
        if stored_user:
            stored_user.update(user)
            user = stored_user
        utils.store_user(runtime_storage_inst, user)
Пример #11
0
def _update_members_company_name(runtime_storage_inst):
    LOG.debug('Update company names for members')
    record_processor_inst = record_processor.RecordProcessor(
        runtime_storage_inst)
    member_iterator = _get_changed_member_records(runtime_storage_inst,
                                                  record_processor_inst)

    for record in member_iterator:
        company_name = record['company_name']
        user = utils.load_user(runtime_storage_inst, record['user_id'])

        user['companies'] = [{
            'company_name': company_name,
            'end_date': 0,
        }]
        user['company_name'] = company_name

        utils.store_user(runtime_storage_inst, user)

        LOG.debug('Company name changed for user %s', user)

        record_id = record['record_id']
        runtime_storage_inst.memcached.set(
            runtime_storage_inst._get_record_name(record_id), record)
        runtime_storage_inst._commit_update(record_id)
Пример #12
0
def _update_members_company_name(runtime_storage_inst):
    LOG.debug('Update company names for members')
    record_processor_inst = record_processor.RecordProcessor(
        runtime_storage_inst)
    member_iterator = _get_changed_member_records(runtime_storage_inst,
                                                  record_processor_inst)

    for record in member_iterator:
        company_name = record['company_name']
        user = utils.load_user(runtime_storage_inst, record['user_id'])

        user['companies'] = [{
            'company_name': company_name,
            'end_date': 0,
        }]
        user['company_name'] = company_name

        utils.store_user(runtime_storage_inst, user)

        LOG.debug('Company name changed for user %s', user)

        record_id = record['record_id']
        runtime_storage_inst.memcached.set(
            runtime_storage_inst._get_record_name(record_id), record)
        runtime_storage_inst._commit_update(record_id)
Пример #13
0
    def test_process_commit_new_user(self):
        # User is new to us. Should set user name and empty ldap_id
        record_processor_inst = self.make_record_processor(
            companies=[{
                'company_name': 'IBM',
                'domains': ['ibm.com']
            }])

        processed_commit = list(
            record_processor_inst.process(
                generate_commits(author_email='*****@*****.**',
                                 author_name='John Doe')))[0]

        expected_commit = {
            'ldap_id': None,
            'author_email': '*****@*****.**',
            'author_name': 'John Doe',
            'company_name': 'IBM',
        }

        self.assertRecordsMatch(expected_commit, processed_commit)
        user = utils.load_user(record_processor_inst.runtime_storage_inst,
                               '*****@*****.**')
        self.assertIn('*****@*****.**', user['emails'])
        self.assertEqual('IBM', user['companies'][0]['company_name'])
        self.assertEqual(None, user['ldap_id'])
Пример #14
0
def _store_users(runtime_storage_inst, users):
    for user in users:
        stored_user = utils.load_user(runtime_storage_inst, user['user_id'])
        if stored_user:
            stored_user.update(user)
            user = stored_user
        utils.store_user(runtime_storage_inst, user)
Пример #15
0
    def test_create_member(self):
        member_record = {'member_id': '123456789',
                         'member_name': 'John Doe',
                         'member_uri': 'http://www.openstack.org/community'
                                       '/members/profile/123456789',
                         'date_joined': 'August 01, 2012 ',
                         'company_draft': 'Mirantis'}

        record_processor_inst = self.make_record_processor()
        result_member = record_processor_inst._process_member(
            member_record).next()

        self.assertEqual(result_member['primary_key'], 'member:123456789')
        self.assertEqual(result_member['date'], utils.member_date_to_timestamp(
            'August 01, 2012 '))
        self.assertEqual(result_member['author_name'], 'John Doe')
        self.assertEqual(result_member['company_name'], 'Mirantis')

        result_user = utils.load_user(
            record_processor_inst.runtime_storage_inst, 'member:123456789')

        self.assertEqual(result_user['user_name'], 'John Doe')
        self.assertEqual(result_user['company_name'], 'Mirantis')
        self.assertEqual(result_user['companies'],
                         [{'company_name': 'Mirantis', 'end_date': 0}])
Пример #16
0
    def test_process_email_then_review(self):
        # it is expected that the user profile will contain both email and
        # ldap-id
        record_processor_inst = self.make_record_processor()

        list(
            record_processor_inst.process([{
                'record_type': 'email',
                'message_id': '<message-id>',
                'author_email': '*****@*****.**',
                'subject': 'hello, world!',
                'body': 'lorem ipsum',
                'date': 1234567890
            }, {
                'record_type': 'review',
                'id': 'I1045730e47e9e6ad31fcdfbaefdad77e2f3b2c3e',
                'subject': 'Fix AttributeError in Keypair._add_details()',
                'owner': {
                    'name': 'John Doe',
                    'email': '*****@*****.**',
                    'username': '******'
                },
                'createdOn': 1379404951,
                'module': 'nova',
                'branch': 'master'
            }]))

        user = {
            'seq': 1,
            'core': [],
            'user_id': 'john_doe',
            'ldap_id': 'john_doe',
            'user_name': 'John Doe',
            'emails': ['*****@*****.**'],
            'companies': [{
                'company_name': '*independent',
                'end_date': 0
            }]
        }
        self.assertEqual(
            user,
            utils.load_user(record_processor_inst.runtime_storage_inst,
                            '*****@*****.**'))
        self.assertEqual(
            user,
            utils.load_user(record_processor_inst.runtime_storage_inst,
                            'john_doe'))
Пример #17
0
    def test_merge_users(self):
        record_processor_inst = self.make_record_processor(
            companies=[{'company_name': 'IBM', 'domains': ['ibm.com']}],
        )
        runtime_storage_inst = record_processor_inst.runtime_storage_inst

        runtime_storage_inst.set_records(record_processor_inst.process([
            {'record_type': 'email',
             'message_id': '<message-id>',
             'author_email': '*****@*****.**', 'author_name': 'John Doe',
             'subject': 'hello, world!',
             'body': 'lorem ipsum',
             'date': 1234567890},
            {'record_type': 'review',
             'id': 'I1045730e47e9e6ad31fcdfbaefdad77e2f3b2c3e',
             'subject': 'Fix AttributeError in Keypair._add_details()',
             'owner': {'name': 'John Doe',
                       'email': '*****@*****.**',
                       'username': '******'},
             'createdOn': 1379404951,
             'module': 'nova', 'branch': 'master'}
        ]))

        record_processor_inst.update()

        user = {'seq': 1,
                'core': [],
                'user_id': 'john_doe',
                'ldap_id': 'john_doe',
                'user_name': 'John Doe',
                'emails': ['*****@*****.**'],
                'companies': [{'company_name': 'IBM', 'end_date': 0}]}
        runtime_storage_inst = record_processor_inst.runtime_storage_inst
        self.assertEqual(1, runtime_storage_inst.get_by_key('user:count'))
        self.assertEqual(user, utils.load_user(runtime_storage_inst, 1))
        self.assertEqual(user, utils.load_user(runtime_storage_inst,
                                               'john_doe'))
        self.assertEqual(user, utils.load_user(runtime_storage_inst,
                                               '*****@*****.**'))

        # all records should have the same user_id and company name
        for record in runtime_storage_inst.get_all_records():
            self.assertEqual('john_doe', record['user_id'],
                             message='Record %s' % record['primary_key'])
            self.assertEqual('IBM', record['company_name'],
                             message='Record %s' % record['primary_key'])
Пример #18
0
    def update_user(self, record):
        email = record.get('author_email')
        user_e = utils.load_user(self.runtime_storage_inst, email) or {}

        user_name = record.get('author_name')

        ldap_id = record.get('ldap_id')
        user_l = utils.load_user(self.runtime_storage_inst, ldap_id) or {}

        user = self._create_user(ldap_id, email, user_name)

        if (user_e.get('seq') == user_l.get('seq')) and user_e.get('seq'):
            # sequence numbers are set and the same, merge is not needed
            user = user_e
        else:
            if user_e or user_l:
                user = self._merge_user_profiles(user_e, user_l, user)
            else:
                # Create New
                LOG.debug('Created new user: %s', user)

            utils.store_user(self.runtime_storage_inst, user)

        return user
Пример #19
0
    def test_process_commit_existing_user_new_email_known_company(self):
        # User is known but his email is new to us, and maps to other
        # company. Will create a new user with no ldap_id
        record_processor_inst = self.make_record_processor(users=[{
            'user_id':
            'john_doe',
            'ldap_id':
            'john_doe',
            'user_name':
            'John Doe',
            'emails': ['*****@*****.**'],
            'companies': [{
                'company_name': 'NEC',
                'end_date': 0
            }]
        }],
                                                           companies=[{
                                                               'company_name':
                                                               'IBM',
                                                               'domains':
                                                               ['ibm.com']
                                                           }])

        processed_commit = list(
            record_processor_inst.process(
                generate_commits(author_email='*****@*****.**',
                                 author_name='John Doe')))[0]

        expected_commit = {
            'ldap_id': None,
            'author_email': '*****@*****.**',
            'author_name': 'John Doe',
            'company_name': 'IBM',
        }

        self.assertRecordsMatch(expected_commit, processed_commit)
        self.assertIn(
            '*****@*****.**',
            utils.load_user(record_processor_inst.runtime_storage_inst,
                            '*****@*****.**')['emails'])
Пример #20
0
    def test_process_commit_new_user(self):
        # User is new to us. Should set user name and empty ldap_id
        record_processor_inst = self.make_record_processor(
            companies=[{'company_name': 'IBM', 'domains': ['ibm.com']}])

        processed_commit = list(record_processor_inst.process(
            generate_commits(author_email='*****@*****.**',
                             author_name='John Doe')))[0]

        expected_commit = {
            'ldap_id': None,
            'author_email': '*****@*****.**',
            'author_name': 'John Doe',
            'company_name': 'IBM',
        }

        self.assertRecordsMatch(expected_commit, processed_commit)
        user = utils.load_user(
            record_processor_inst.runtime_storage_inst, '*****@*****.**')
        self.assertIn('*****@*****.**', user['emails'])
        self.assertEqual('IBM', user['companies'][0]['company_name'])
        self.assertEqual(None, user['ldap_id'])
Пример #21
0
    def test_core_user_guess(self):
        record_processor_inst = self.make_record_processor(
            companies=[{'company_name': 'IBM', 'domains': ['ibm.com']}],
        )
        runtime_storage_inst = record_processor_inst.runtime_storage_inst

        timestamp = int(time.time())
        runtime_storage_inst.set_records(record_processor_inst.process([
            {'record_type': 'review',
             'id': 'I1045730e47e9e6ad31fcdfbaefdad77e2f3b2c3e',
             'subject': 'Fix AttributeError in Keypair._add_details()',
             'owner': {'name': 'John Doe',
                       'email': '*****@*****.**',
                       'username': '******'},
             'createdOn': timestamp,
             'module': 'nova',
             'branch': 'master',
             'patchSets': [
                 {'number': '1',
                  'revision': '4d8984e92910c37b7d101c1ae8c8283a2e6f4a76',
                  'ref': 'refs/changes/16/58516/1',
                  'uploader': {
                      'name': 'Bill Smith',
                      'email': '*****@*****.**',
                      'username': '******'},
                  'createdOn': timestamp,
                  'approvals': [
                      {'type': 'Code-Review', 'description': 'Code Review',
                       'value': '2', 'grantedOn': timestamp,
                       'by': {
                           'name': 'John Doe',
                           'email': '*****@*****.**',
                           'username': '******'}},
                      {'type': 'Code-Review', 'description': 'Code Review',
                       'value': '-1', 'grantedOn': timestamp - 1,  # differ
                       'by': {
                           'name': 'Homer Simpson',
                           'email': '*****@*****.**',
                           'username': '******'}}
                  ]
                  }]}
        ]))

        record_processor_inst.update()

        user_1 = {'seq': 1, 'user_id': 'john_doe',
                  'ldap_id': 'john_doe', 'user_name': 'John Doe',
                  'emails': ['*****@*****.**'],
                  'core': [('nova', 'master')],
                  'companies': [{'company_name': 'IBM', 'end_date': 0}]}
        user_2 = {'seq': 3, 'user_id': 'homer',
                  'ldap_id': 'homer', 'user_name': 'Homer Simpson',
                  'emails': ['*****@*****.**'],
                  'core': [],
                  'companies': [{'company_name': '*independent',
                                 'end_date': 0}]}
        runtime_storage_inst = record_processor_inst.runtime_storage_inst
        self.assertEqual(user_1, utils.load_user(runtime_storage_inst,
                                                 'john_doe'))
        self.assertEqual(user_2, utils.load_user(runtime_storage_inst,
                                                 'homer'))
Пример #22
0
    def test_process_commit_then_review_with_different_email(self):
        # In this case, we don't know how to associate the email from the
        # commit with the LDAP ID so two users are created.

        record_processor_inst = self.make_record_processor(
            companies=[{
                'company_name': 'IBM',
                'domains': ['ibm.com']
            }])

        list(
            record_processor_inst.process([{
                'record_type': 'commit',
                'commit_id': 'de7e8f297c193fb310f22815334a54b9c76a0be1',
                'author_name': 'John Doe',
                'author_email': '*****@*****.**',
                'date': 1234567890,
                'lines_added': 25,
                'lines_deleted': 9,
                'release_name': 'havana'
            }, {
                'record_type':
                'review',
                'id':
                'I1045730e47e9e6ad31fcdfbaefdad77e2f3b2c3e',
                'subject':
                'Fix AttributeError in Keypair._add_details()',
                'owner': {
                    'name': 'Bill Smith',
                    'email': '*****@*****.**',
                    'username': '******'
                },
                'createdOn':
                1379404951,
                'module':
                'nova',
                'branch':
                'master',
                'patchSets': [{
                    'number':
                    '1',
                    'revision':
                    '4d8984e92910c37b7d101c1ae8c8283a2e6f4a76',
                    'ref':
                    'refs/changes/16/58516/1',
                    'uploader': {
                        'name': 'Bill Smith',
                        'email': '*****@*****.**',
                        'username': '******'
                    },
                    'createdOn':
                    1385470730,
                    'approvals': [{
                        'type': 'Code-Review',
                        'description': 'Code Review',
                        'value': '1',
                        'grantedOn': 1385478464,
                        'by': {
                            'name': 'John Doe',
                            'email': '*****@*****.**',
                            'username': '******'
                        }
                    }]
                }]
            }]))
        userA = {
            'seq': 3,
            'user_id': 'john_doe',
            'ldap_id': 'john_doe',
            'user_name': 'John Doe',
            'emails': ['*****@*****.**'],
            'companies': [{
                'company_name': 'IBM',
                'end_date': 0
            }]
        }
        userB = {
            'seq': 1,
            'user_id': '*****@*****.**',
            'ldap_id': None,
            'user_name': 'John Doe',
            'emails': ['*****@*****.**'],
            'companies': [{
                'company_name': '*independent',
                'end_date': 0
            }]
        }
        self.assertEqual(
            userA,
            utils.load_user(record_processor_inst.runtime_storage_inst,
                            'john_doe'))
        self.assertEqual(
            userB,
            utils.load_user(record_processor_inst.runtime_storage_inst,
                            '*****@*****.**'))
        self.assertEqual(
            userA,
            utils.load_user(record_processor_inst.runtime_storage_inst,
                            '*****@*****.**'))
Пример #23
0
    def test_merge_users(self):
        record_processor_inst = self.make_record_processor(companies=[{
            'company_name':
            'IBM',
            'domains': ['ibm.com']
        }], )
        runtime_storage_inst = record_processor_inst.runtime_storage_inst

        runtime_storage_inst.set_records(
            record_processor_inst.process([{
                'record_type': 'email',
                'message_id': '<message-id>',
                'author_email': '*****@*****.**',
                'author_name': 'John Doe',
                'subject': 'hello, world!',
                'body': 'lorem ipsum',
                'date': 1234567890
            }, {
                'record_type': 'review',
                'id': 'I1045730e47e9e6ad31fcdfbaefdad77e2f3b2c3e',
                'subject': 'Fix AttributeError in Keypair._add_details()',
                'owner': {
                    'name': 'John Doe',
                    'email': '*****@*****.**',
                    'username': '******'
                },
                'createdOn': 1379404951,
                'module': 'nova',
                'branch': 'master'
            }]))

        record_processor_inst.update()

        user = {
            'seq': 1,
            'core': [],
            'user_id': 'john_doe',
            'ldap_id': 'john_doe',
            'user_name': 'John Doe',
            'emails': ['*****@*****.**'],
            'companies': [{
                'company_name': 'IBM',
                'end_date': 0
            }]
        }
        runtime_storage_inst = record_processor_inst.runtime_storage_inst
        self.assertEqual(1, runtime_storage_inst.get_by_key('user:count'))
        self.assertEqual(user, utils.load_user(runtime_storage_inst, 1))
        self.assertEqual(user, utils.load_user(runtime_storage_inst,
                                               'john_doe'))
        self.assertEqual(
            user, utils.load_user(runtime_storage_inst, '*****@*****.**'))

        # all records should have the same user_id and company name
        for record in runtime_storage_inst.get_all_records():
            self.assertEqual('john_doe',
                             record['user_id'],
                             message='Record %s' % record['primary_key'])
            self.assertEqual('IBM',
                             record['company_name'],
                             message='Record %s' % record['primary_key'])
Пример #24
0
    def test_core_user_guess(self):
        record_processor_inst = self.make_record_processor(companies=[{
            'company_name':
            'IBM',
            'domains': ['ibm.com']
        }], )
        runtime_storage_inst = record_processor_inst.runtime_storage_inst

        timestamp = int(time.time())
        runtime_storage_inst.set_records(
            record_processor_inst.process([{
                'record_type':
                'review',
                'id':
                'I1045730e47e9e6ad31fcdfbaefdad77e2f3b2c3e',
                'subject':
                'Fix AttributeError in Keypair._add_details()',
                'owner': {
                    'name': 'John Doe',
                    'email': '*****@*****.**',
                    'username': '******'
                },
                'createdOn':
                timestamp,
                'module':
                'nova',
                'branch':
                'master',
                'patchSets': [{
                    'number':
                    '1',
                    'revision':
                    '4d8984e92910c37b7d101c1ae8c8283a2e6f4a76',
                    'ref':
                    'refs/changes/16/58516/1',
                    'uploader': {
                        'name': 'Bill Smith',
                        'email': '*****@*****.**',
                        'username': '******'
                    },
                    'createdOn':
                    timestamp,
                    'approvals': [
                        {
                            'type': 'Code-Review',
                            'description': 'Code Review',
                            'value': '2',
                            'grantedOn': timestamp,
                            'by': {
                                'name': 'John Doe',
                                'email': '*****@*****.**',
                                'username': '******'
                            }
                        },
                        {
                            'type': 'Code-Review',
                            'description': 'Code Review',
                            'value': '-1',
                            'grantedOn': timestamp - 1,  # differ
                            'by': {
                                'name': 'Homer Simpson',
                                'email': '*****@*****.**',
                                'username': '******'
                            }
                        }
                    ]
                }]
            }]))

        record_processor_inst.update()

        user_1 = {
            'seq': 1,
            'user_id': 'john_doe',
            'ldap_id': 'john_doe',
            'user_name': 'John Doe',
            'emails': ['*****@*****.**'],
            'core': [('nova', 'master')],
            'companies': [{
                'company_name': 'IBM',
                'end_date': 0
            }]
        }
        user_2 = {
            'seq': 3,
            'user_id': 'homer',
            'ldap_id': 'homer',
            'user_name': 'Homer Simpson',
            'emails': ['*****@*****.**'],
            'core': [],
            'companies': [{
                'company_name': '*independent',
                'end_date': 0
            }]
        }
        runtime_storage_inst = record_processor_inst.runtime_storage_inst
        self.assertEqual(user_1,
                         utils.load_user(runtime_storage_inst, 'john_doe'))
        self.assertEqual(user_2, utils.load_user(runtime_storage_inst,
                                                 'homer'))
Пример #25
0
def get_user_from_runtime_storage(user_id):
    runtime_storage_inst = get_vault()['runtime_storage']
    user_index = get_vault()['user_index']
    if user_id not in user_index:
        user_index[user_id] = utils.load_user(runtime_storage_inst, user_id)
    return user_index[user_id]
Пример #26
0
def get_user_from_runtime_storage(user_id):
    runtime_storage_inst = get_vault()['runtime_storage']
    user_index = get_vault()['user_index']
    if user_id not in user_index:
        user_index[user_id] = utils.load_user(runtime_storage_inst, user_id)
    return user_index[user_id]