773
774
self.mock_review_stats.assert_called_with(
774
775
origin='any', distroseries='onion', days=3)
777
def test_force_download_all_stats(self):
778
# If the download_all option is used, all stats are
779
# downloaded, rather than the optimised last X days.
780
onion = self.factory.make_distroseries(code_name='onion')
781
orig_timestamp = datetime.utcnow() - timedelta(2)
782
import_record = ReviewStatsImport.objects.create(
783
distroseries=onion, last_import=orig_timestamp)
785
call_command('import_ratings_stats', 'onion', download_all=True)
787
self.mock_review_stats.assert_called_with(origin='any',
788
distroseries='onion')
776
790
def test_update_app_stats(self):
777
791
# Any stats provided in the api call will be used to update our
778
792
# apps in the db.
1108
1122
class ImportAllRatingsStatsTestCase(TestCaseWithFactory):
1109
@patch('sys.stdout')
1110
def test_handle(self, mock_stdout):
1111
patch_attr = ('webcatalog.management.commands.'
1112
'import_all_ratings_stats.call_command')
1113
with patch_settings(UBUNTU_SERIES_FOR_VERSIONS=TEST_VERSIONS):
1114
with patch(patch_attr) as mock_call_command:
1115
call_command('import_all_ratings_stats')
1117
self.assertEqual(mock_call_command.call_count, len(TEST_VERSIONS))
1125
patcher = patch('webcatalog.management.commands.'
1126
'import_all_ratings_stats.call_command')
1127
self.mock_call_command = patcher.start()
1128
self.addCleanup(patcher.stop)
1130
patcher = patch('sys.stdout')
1132
self.addCleanup(patcher.stop)
1134
def test_handle_download(self):
1135
with patch_settings(UBUNTU_SERIES_FOR_VERSIONS=TEST_VERSIONS):
1136
call_command('import_all_ratings_stats')
1139
call('import_ratings_stats', series, verbosity=1,
1140
download_all=False) for series in TEST_VERSIONS.values()]
1141
self.mock_call_command.assert_has_calls(expected_calls,
1144
def test_handle_download_all(self):
1145
with patch_settings(UBUNTU_SERIES_FOR_VERSIONS=TEST_VERSIONS):
1146
call_command('import_all_ratings_stats', download_all=True)
1149
call('import_ratings_stats', series, verbosity=1,
1150
download_all=True) for series in TEST_VERSIONS.values()]
1151
self.mock_call_command.assert_has_calls(expected_calls,