Set user as independent if profile contains no info

If user profile contains only closed intervals for affiliation
then mark user as independent when the last interval ends

Change-Id: I57e452108390e9c062527710d085c2f49a1f79fb
This commit is contained in:
Ilya Shakhat 2015-04-02 13:06:21 +03:00
parent d8134a0067
commit 207c2e8993
3 changed files with 18 additions and 0 deletions

View File

@ -37,6 +37,10 @@ def _normalize_user(user):
return x["end_date"] - y["end_date"]
user['companies'].sort(key=utils.cmp_to_key(end_date_comparator))
if user['companies']:
if user['companies'][-1]['end_date'] != 0:
user['companies'].append(dict(company_name='*independent',
end_date=0))
user['user_id'] = user_processor.make_user_id(
launchpad_id=user.get('launchpad_id'),
emails=user.get('emails'),

View File

@ -25,6 +25,15 @@ DEFAULT_DATA = {
{'company_name': 'NEC', 'end_date': None},
]
},
{
'launchpad_id': 'smith',
'user_name': 'Smith',
'emails': ['smith@gmail.com', 'smith@nec.com'],
'companies': [
{'company_name': 'IBM', 'end_date': '2013-May-01'},
{'company_name': 'NEC', 'end_date': '2014-Jun-01'}
]
},
{
'launchpad_id': 'ivan_ivanov',
'user_name': 'Ivan Ivanov',

View File

@ -52,6 +52,11 @@ class TestDefaultDataProcessor(testtools.TestCase):
data['users'][0]['user_id'],
message='User id should be set')
# verify that *independent company is added automatically
self.assertEqual(3, len(data['users'][1]['companies']))
self.assertEqual(0, data['users'][1]['companies'][-1]['end_date'],
message='The last company end date should be 0')
def test_update_project_list(self):
with mock.patch('stackalytics.processor.default_data_processor.'
'_retrieve_project_list_from_gerrit') as retriever: