Example #1
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
    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}])
    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
        }])