stackalytics/tests/unit/test_default_data_processor.py
Ilya Shakhat 82600d8805 Merge user profiles during default data update
* Existing user profiles are updated with data read from default-data
* Refactoring of default data processor
* Removed unused code from normalizer (validity is enforced by schema)
* Add more restrictions into the schema

Fixes bug 1260696

Change-Id: Iab1f190ff8a7e2a0c0800712174565437149e119
2013-12-20 20:29:45 +04:00

73 lines
2.7 KiB
Python

# Copyright (c) 2013 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 copy
import mock
import testtools
from stackalytics.processor import default_data_processor
from stackalytics.processor import normalizer
from tests.unit import test_data
class TestDefaultDataProcessor(testtools.TestCase):
def setUp(self):
super(TestDefaultDataProcessor, self).setUp()
self.get_users = mock.Mock(return_value=[
test_data.USERS,
])
normalized_data = copy.deepcopy(test_data.DEFAULT_DATA)
normalizer.normalize_default_data(normalized_data)
def tearDown(self):
super(TestDefaultDataProcessor, self).tearDown()
def test_normalizer(self):
data = copy.deepcopy(test_data.DEFAULT_DATA)
normalizer.normalize_default_data(data)
self.assertIn('releases', data['repos'][0])
self.assertEqual([], data['repos'][0]['releases'],
message='Empty list of releases expected')
self.assertEqual(0, data['users'][0]['companies'][-1]['end_date'],
message='The last company end date should be 0')
self.assertIn('user_id', data['users'][0])
self.assertEqual(test_data.USERS[0]['launchpad_id'],
data['users'][0]['user_id'],
message='User id should be set')
def test_update_project_list(self):
with mock.patch('stackalytics.processor.default_data_processor.'
'_retrieve_project_list_from_github') as retriever:
retriever.return_value = [
{'module': 'nova', 'uri': 'git://github.com/openstack/nova'},
{'module': 'qa', 'uri': 'git://github.com/openstack/qa'},
]
dd = {
'repos': [
{'module': 'qa', 'uri': 'git://github.com/openstack/qa'},
],
'project_sources': ['any']
}
default_data_processor._update_project_list(dd)
self.assertEqual(2, len(dd['repos']))
self.assertIn('qa', set([r['module'] for r in dd['repos']]))
self.assertIn('nova', set([r['module'] for r in dd['repos']]))