Пример #1
0
    def test_omaha_versions(self, mocked_get_logger):
        gpm['Version__limit_size'] = 1
        version_size = 1000 * 1024 * 1023
        versions = VersionFactory.create_batch(2, file_size=version_size)
        deleted_version = versions[0]
        self.assertEqual(Version.objects.count(), 2)

        extra_meta = dict(count=1,
                          reason='manual',
                          meta=True,
                          log_id='36446dc3-ae7c-42ad-ae4e-6a826dcf0a00',
                          model='Version',
                          limit_duplicated=None,
                          limit_size=1,
                          limit_days=None,
                          size='999.0 MB')
        log_extra_msg = add_extra_to_log_message('Manual cleanup',
                                                 extra=extra_meta)

        extra = dict(Version_id=deleted_version.id,
                     element_created=deleted_version.created.strftime(
                         "%d. %B %Y %I:%M%p"),
                     log_id='36446dc3-ae7c-42ad-ae4e-6a826dcf0a00')
        log_msg = add_extra_to_log_message('Manual cleanup element',
                                           extra=extra)
        mocked_logger = mocked_get_logger.return_value

        with patch('uuid.uuid4') as mocked_uuid4:
            mocked_uuid4.side_effect = (uuid.UUID(
                '36446dc3-ae7c-42ad-ae4e-6a826dcf0a%02d' % x)
                                        for x in range(100))
            deferred_manual_cleanup(['omaha', 'Version'], limit_size=1)
        self.assertEqual(mocked_logger.info.call_count, 2)
        mocked_logger.info.assert_any_call(log_extra_msg)
        mocked_logger.info.assert_any_call(log_msg)
Пример #2
0
    def test_omaha_versions(self, mocked_get_logger):
        gpm['Version__limit_size'] = 1
        version_size = 1000*1024*1023
        versions = VersionFactory.create_batch(2, file_size=version_size)
        deleted_version = versions[0]
        self.assertEqual(Version.objects.count(), 2)

        extra_meta = dict(count=1, reason='manual', meta=True, log_id='36446dc3-ae7c-42ad-ae4e-6a826dcf0a00',
                          model='Version', limit_duplicated=None, limit_size=1, limit_days=None, size='999.0 MB')
        log_extra_msg = add_extra_to_log_message('Manual cleanup', extra=extra_meta)

        extra = dict(Version_id=deleted_version.id, element_created=deleted_version.created.strftime("%d. %B %Y %I:%M%p"),
                     log_id='36446dc3-ae7c-42ad-ae4e-6a826dcf0a00')
        log_msg = add_extra_to_log_message('Manual cleanup element', extra=extra)
        mocked_logger = mocked_get_logger.return_value

        with patch('uuid.uuid4') as mocked_uuid4:
            mocked_uuid4.side_effect = (uuid.UUID('36446dc3-ae7c-42ad-ae4e-6a826dcf0a%02d' % x) for x in range(100))
            deferred_manual_cleanup(['omaha', 'Version'], limit_size=1)
        self.assertEqual(mocked_logger.info.call_count, 2)
        mocked_logger.info.assert_any_call(log_extra_msg)
        mocked_logger.info.assert_any_call(log_msg)
Пример #3
0
 def test_get_size(self):
     file_size = 42
     VersionFactory.create_batch(10, file_size=file_size)
     size = Version.objects.get_size()
     self.assertEqual(size, file_size * 10)
Пример #4
0
 def test_get_size(self):
     file_size = 42
     VersionFactory.create_batch(10, file_size=file_size)
     size = Version.objects.get_size()
     self.assertEqual(size, file_size*10)