Show current company instead of the latest
Change-Id: I8c2116f2906e03c539fa21450b0b02201b5fd7aa Closes-Bug: #1495517
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import operator
|
import operator
|
||||||
import re
|
import re
|
||||||
|
import time
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
|
||||||
@@ -103,13 +104,22 @@ def extend_record(record):
|
|||||||
return record
|
return record
|
||||||
|
|
||||||
|
|
||||||
|
def get_current_company(user):
|
||||||
|
now = time.time()
|
||||||
|
idx = -1
|
||||||
|
for i, r in enumerate(user['companies']):
|
||||||
|
if now < r['end_date']:
|
||||||
|
idx = i
|
||||||
|
return user['companies'][idx]['company_name']
|
||||||
|
|
||||||
|
|
||||||
def extend_user(user):
|
def extend_user(user):
|
||||||
user = user.copy()
|
user = user.copy()
|
||||||
|
|
||||||
user['id'] = user['user_id']
|
user['id'] = user['user_id']
|
||||||
user['text'] = user['user_name']
|
user['text'] = user['user_name']
|
||||||
if user['companies']:
|
if user['companies']:
|
||||||
company_name = user['companies'][-1]['company_name']
|
company_name = get_current_company(user)
|
||||||
user['company_link'] = make_link(
|
user['company_link'] = make_link(
|
||||||
company_name, '/', {'company': company_name, 'user_id': ''})
|
company_name, '/', {'company': company_name, 'user_id': ''})
|
||||||
else:
|
else:
|
||||||
|
@@ -194,7 +194,7 @@ def get_engineers_extended(records, **kwargs):
|
|||||||
return
|
return
|
||||||
|
|
||||||
user = vault.get_user_from_runtime_storage(record['id'])
|
user = vault.get_user_from_runtime_storage(record['id'])
|
||||||
record['company'] = user['companies'][-1]['company_name']
|
record['company'] = helpers.get_current_company(user)
|
||||||
record['core'] = get_core_engineer_branch(user, modules)
|
record['core'] = get_core_engineer_branch(user, modules)
|
||||||
return record
|
return record
|
||||||
|
|
||||||
@@ -434,7 +434,7 @@ def get_users_json(record_ids, **kwargs):
|
|||||||
if core_modules:
|
if core_modules:
|
||||||
r['core'] = core_modules
|
r['core'] = core_modules
|
||||||
if user['companies']:
|
if user['companies']:
|
||||||
r['company_name'] = user['companies'][-1]['company_name']
|
r['company_name'] = helpers.get_current_company(user)
|
||||||
add_flag = True
|
add_flag = True
|
||||||
if add_flag:
|
if add_flag:
|
||||||
result.append(r)
|
result.append(r)
|
||||||
|
95
stackalytics/tests/unit/test_helpers.py
Normal file
95
stackalytics/tests/unit/test_helpers.py
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
# Copyright (c) 2015 Mirantis Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
# implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import mock
|
||||||
|
import testtools
|
||||||
|
|
||||||
|
from stackalytics.dashboard import helpers
|
||||||
|
|
||||||
|
|
||||||
|
class TestHelpers(testtools.TestCase):
|
||||||
|
|
||||||
|
@mock.patch('time.time')
|
||||||
|
def test_get_current_company(self, mock_time_time):
|
||||||
|
current_timestamp = 1234567890
|
||||||
|
mock_time_time.return_value = current_timestamp
|
||||||
|
|
||||||
|
user = {
|
||||||
|
'user_id': 'smith',
|
||||||
|
'user_name': 'John Smith',
|
||||||
|
'companies': [{
|
||||||
|
'company_name': 'Current',
|
||||||
|
'end_date': current_timestamp + 1
|
||||||
|
}, {
|
||||||
|
'company_name': 'TheCompany',
|
||||||
|
'end_date': 0
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
|
self.assertEqual('Current', helpers.get_current_company(user))
|
||||||
|
|
||||||
|
@mock.patch('stackalytics.dashboard.helpers.make_link')
|
||||||
|
def test_extend_user(self, mock_make_link):
|
||||||
|
company_link = mock.Mock()
|
||||||
|
mock_make_link.return_value = company_link
|
||||||
|
|
||||||
|
user = {
|
||||||
|
'user_id': 'smith',
|
||||||
|
'user_name': 'John Smith',
|
||||||
|
'companies': [{
|
||||||
|
'company_name': 'TheCompany',
|
||||||
|
'end_date': 0
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = {
|
||||||
|
'user_id': 'smith',
|
||||||
|
'user_name': 'John Smith',
|
||||||
|
'companies': [{
|
||||||
|
'company_name': 'TheCompany',
|
||||||
|
'end_date': 0
|
||||||
|
}],
|
||||||
|
'id': 'smith',
|
||||||
|
'company_link': company_link,
|
||||||
|
'text': 'John Smith',
|
||||||
|
}
|
||||||
|
|
||||||
|
observed = helpers.extend_user(user)
|
||||||
|
self.assertEqual(expected, observed)
|
||||||
|
mock_make_link.assert_called_once_with('TheCompany', '/', mock.ANY)
|
||||||
|
|
||||||
|
@mock.patch('time.time')
|
||||||
|
@mock.patch('stackalytics.dashboard.helpers.make_link')
|
||||||
|
def test_extend_user_current_company(self, mock_make_link, mock_time_time):
|
||||||
|
company_link = mock.Mock()
|
||||||
|
mock_make_link.return_value = company_link
|
||||||
|
current_timestamp = 1234567890
|
||||||
|
mock_time_time.return_value = current_timestamp
|
||||||
|
|
||||||
|
user = {
|
||||||
|
'user_id': 'smith',
|
||||||
|
'user_name': 'John Smith',
|
||||||
|
'companies': [{
|
||||||
|
'company_name': 'Current',
|
||||||
|
'end_date': current_timestamp + 1
|
||||||
|
}, {
|
||||||
|
'company_name': 'TheCompany',
|
||||||
|
'end_date': 0
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
|
helpers.extend_user(user)
|
||||||
|
|
||||||
|
mock_make_link.assert_called_once_with('Current', '/', mock.ANY)
|
Reference in New Issue
Block a user