Esempio n. 1
0
    def setUp(self):
        self.app = ApplicationFactory(name='TestApp')
        self.channel = ChannelFactory(name='alpha')
        self.stable_channel = ChannelFactory(name='stable')
        self.win_v1 = VersionFactory(version='10.0.0.0',
                                     app=self.app,
                                     channel=self.channel)
        self.win_v2 = VersionFactory(version='42.0.1.0',
                                     app=self.app,
                                     channel=self.channel)
        self.win_stable_v = VersionFactory(version='23.0.0.0',
                                           app=self.app,
                                           channel=self.stable_channel)
        self.win_disabled_v = VersionFactory(version='55.0.2.0',
                                             app=self.app,
                                             channel=self.channel,
                                             is_enabled=False)

        self.mac_v1 = SparkleVersionFactory(short_version='10.0.0.0',
                                            version='0.0',
                                            app=self.app,
                                            channel=self.channel)
        self.mac_v2 = SparkleVersionFactory(short_version='42.0.1.0',
                                            version='1.0',
                                            app=self.app,
                                            channel=self.channel)
        self.mac_stable_v = SparkleVersionFactory(short_version='23.0.0.0',
                                                  version='0.0',
                                                  app=self.app,
                                                  channel=self.stable_channel)
        self.mac_disabled_v = SparkleVersionFactory(short_version='55.0.2.0',
                                                    version='2.0',
                                                    app=self.app,
                                                    channel=self.channel,
                                                    is_enabled=False)
        self.exp_res = {
            self.app.name: {
                "win": {
                    self.channel.name: {
                        "url": self.win_v2.file_absolute_url,
                        "version": self.win_v2.version
                    },
                    self.stable_channel.name: {
                        "url": self.win_stable_v.file_absolute_url,
                        "version": self.win_stable_v.version
                    }
                },
                "mac": {
                    self.channel.name: {
                        "url": self.mac_v2.file_absolute_url,
                        "version": self.mac_v2.short_version
                    },
                    self.stable_channel.name: {
                        "url": self.mac_stable_v.file_absolute_url,
                        "version": self.mac_stable_v.short_version
                    }
                }
            }
        }
Esempio n. 2
0
    def test_sparkle_critical(self):
        app = ApplicationFactory.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='chrome')
        channel = ChannelFactory.create(name='stable')
        first_version = SparkleVersionFactory.create(
            app=app,
            channel=channel,
            version='782.110',
            short_version='13.0.782.110',
            file=SimpleUploadedFile('./chrome1.dmg', b'_' * 23963192),
            file_size=23963192)
        first_version.save()

        first_crit_version = SparkleVersionFactory.create(
            app=app,
            channel=channel,
            version='782.111',
            short_version='13.0.782.111',
            is_critical=True,
            file=SimpleUploadedFile('./chrome2.dmg', b'_' * 23963192),
            file_size=23963192)
        first_crit_version.save()

        last_version = SparkleVersionFactory.create(
            app=app,
            channel=channel,
            version='782.112',
            short_version='13.0.782.112',
            file=SimpleUploadedFile('./chrome3.dmg', b'_' * 23963192),
            file_size=23963192)
        last_version.save()

        second_crit_version = SparkleVersionFactory.create(
            app=app,
            channel=channel,
            version='782.113',
            short_version='13.0.782.113',
            is_critical=True,
            file=SimpleUploadedFile('./chrome4.dmg', b'_' * 23963192),
            file_size=23963192)
        second_crit_version.save()

        response = self.client.get("%s?appVersionShort=13.0.782.110" % reverse('sparkle_appcast', args=(app.name, channel.name)),
                                   HTTP_HOST='example.com')

        self.assertEqual(response.status_code, 200)

        self.assertXmlDocument(response.content)
        self.assertXmlEquivalentOutputs(response.content,
                                        fixtures.first_crit_response_sparkle)

        response = self.client.get("%s?appVersionShort=13.0.782.111" % reverse('sparkle_appcast', args=(app.name, channel.name)),
                                   HTTP_HOST='example.com')

        self.assertEqual(response.status_code, 200)

        self.assertXmlDocument(response.content)
        self.assertXmlEquivalentOutputs(response.content,
                                        fixtures.second_crit_response_sparkle)
Esempio n. 3
0
    def test_sparkle_critical(self):
        app = ApplicationFactory.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='chrome')
        channel = ChannelFactory.create(name='stable')
        first_version = SparkleVersionFactory.create(
            app=app,
            channel=channel,
            version='782.110',
            short_version='13.0.782.110',
            file=SimpleUploadedFile('./chrome1.dmg', b'_' * 23963192),
            file_size=23963192)
        first_version.save()

        first_crit_version = SparkleVersionFactory.create(
            app=app,
            channel=channel,
            version='782.111',
            short_version='13.0.782.111',
            is_critical=True,
            file=SimpleUploadedFile('./chrome2.dmg', b'_' * 23963192),
            file_size=23963192)
        first_crit_version.save()

        last_version = SparkleVersionFactory.create(
            app=app,
            channel=channel,
            version='782.112',
            short_version='13.0.782.112',
            file=SimpleUploadedFile('./chrome3.dmg', b'_' * 23963192),
            file_size=23963192)
        last_version.save()

        second_crit_version = SparkleVersionFactory.create(
            app=app,
            channel=channel,
            version='782.113',
            short_version='13.0.782.113',
            is_critical=True,
            file=SimpleUploadedFile('./chrome4.dmg', b'_' * 23963192),
            file_size=23963192)
        second_crit_version.save()

        response = self.client.get("%s?appVersionShort=13.0.782.110" % reverse('sparkle_appcast', args=(app.name, channel.name)),
                                   HTTP_HOST='example.com')

        self.assertEqual(response.status_code, 200)

        self.assertXmlDocument(response.content)
        self.assertXmlEquivalentOutputs(response.content,
                                        fixtures.first_crit_response_sparkle)

        response = self.client.get("%s?appVersionShort=13.0.782.111" % reverse('sparkle_appcast', args=(app.name, channel.name)),
                                   HTTP_HOST='example.com')

        self.assertEqual(response.status_code, 200)

        self.assertXmlDocument(response.content)
        self.assertXmlEquivalentOutputs(response.content,
                                        fixtures.second_crit_response_sparkle)
Esempio n. 4
0
 def test_public_sparkle_update(self):
     ChannelFactory._meta.database = 'root'
     channel_name = 'test'
     channel = ChannelFactory(name=channel_name)
     app_name = 'SparrowTestApp'
     ApplicationFactory._meta.database='root'
     app = ApplicationFactory(name=app_name)
     file = SimpleUploadedFile("test.dmg", b"content")
     SparkleVersionFactory._meta.database='root'
     SparkleVersionFactory.create(channel=channel, app=app, file=file)
     url = '%s%s' % (self.live_server_url, reverse('sparkle_appcast', kwargs=dict(app_name=app_name, channel=channel_name)))  # replace by reverse
     resp = requests.get(url)
     root = objectify.fromstring(resp.content)
     self.assertTrue(app_name in str(root.channel.item.title))
    def test_monitoring(self):
        for key in self.cache_keys:
            self.assertEqual(cache.get(key, 0), 0)

        VersionFactory.create(file_size=100)
        SparkleVersionFactory.create(file_size=100)
        Crash.objects.create(archive_size=80, minidump_size=20)
        Symbols.objects.create(file_size=100)
        Feedback.objects.create(screenshot_size=25, blackbox_size=25, attached_file_size=25, system_logs_size=25)

        monitoring_size()

        for key in self.cache_keys:
            self.assertEqual(cache.get(key), 100)
Esempio n. 6
0
    def test_filter_by_enabled(self):
        version = SparkleVersionFactory.create(
            version='37.0.2062.125',
            file=SimpleUploadedFile('./chrome_installer.exe', False))
        version_disabled = SparkleVersionFactory.create(
            app=version.app,
            channel=version.channel,
            is_enabled=False,
            version='38.0.2062.125',
            file=SimpleUploadedFile('./chrome_installer2.exe', False))

        self.assertEqual(SparkleVersion.objects.all().count(), 2)
        self.assertEqual(SparkleVersion.objects.filter_by_enabled().count(), 1)
        self.assertIn(version, SparkleVersion.objects.filter_by_enabled())
        self.assertNotIn(version_disabled, SparkleVersion.objects.filter_by_enabled())
Esempio n. 7
0
    def test_sparkle(self):
        app = ApplicationFactory.create(
            id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='chrome')
        channel = ChannelFactory.create(name='stable')
        obj = SparkleVersionFactory.create(app=app,
                                           channel=channel,
                                           version='782.112',
                                           short_version='13.0.782.112',
                                           minimum_system_version='10.14.4',
                                           file=SimpleUploadedFile(
                                               './chrome.dmg',
                                               b'_' * 23963192),
                                           file_size=23963192)
        obj.save()

        response = self.client.get(reverse('sparkle_appcast',
                                           args=(app.name, channel.name)),
                                   HTTP_HOST='example.com')

        self.assertEqual(response.status_code, 200)

        self.assertXmlDocument(response.content)
        self.assertXmlEquivalentOutputs(
            response.content,
            fixtures.response_sparkle_with_minimum_system_version)
Esempio n. 8
0
 def test_version_upload_to(self):
     version = SparkleVersionFactory.create(file=SimpleUploadedFile('./chrome_installer.exe', False))
     self.assertEqual(version_upload_to(version, 'chrome_installer.exe'),
                      'sparkle/{}/{}/{}/chrome_installer.exe'.format(
                          version.app.name,
                          version.channel.name,
                          version.version,     #TODO: Uncomment after merge with master
                      ))
Esempio n. 9
0
 def test_version_upload_to(self):
     version = SparkleVersionFactory.create(file=SimpleUploadedFile('./chrome_installer.exe', False))
     self.assertEqual(version_upload_to(version, 'chrome_installer.exe'),
                      'sparkle/{}/{}/{}/chrome_installer.exe'.format(
                          version.app.name,
                          version.channel.name,
                          version.version,     #TODO: Uncomment after merge with master
                      ))
Esempio n. 10
0
    def test_filter_by_enabled(self):
        version = SparkleVersionFactory.create(version='37.0.2062.125',
                                               file=SimpleUploadedFile(
                                                   './chrome_installer.exe',
                                                   False))
        version_disabled = SparkleVersionFactory.create(
            app=version.app,
            channel=version.channel,
            is_enabled=False,
            version='38.0.2062.125',
            file=SimpleUploadedFile('./chrome_installer2.exe', False))

        self.assertEqual(SparkleVersion.objects.all().count(), 2)
        self.assertEqual(SparkleVersion.objects.filter_by_enabled().count(), 1)
        self.assertIn(version, SparkleVersion.objects.filter_by_enabled())
        self.assertNotIn(version_disabled,
                         SparkleVersion.objects.filter_by_enabled())
Esempio n. 11
0
    def test_monitoring(self):
        for key in self.cache_keys:
            self.assertEqual(cache.get(key, 0), 0)

        VersionFactory.create(file_size=100)
        SparkleVersionFactory.create(file_size=100)
        Crash.objects.create(archive_size=80, minidump_size=20)
        Symbols.objects.create(file_size=100)
        Feedback.objects.create(screenshot_size=25,
                                blackbox_size=25,
                                attached_file_size=25,
                                system_logs_size=25)

        monitoring_size()

        for key in self.cache_keys:
            self.assertEqual(cache.get(key), 100)
Esempio n. 12
0
 def test_public_sparkle_update(self):
     ChannelFactory._meta.database = 'root'
     channel_name = 'test'
     channel = ChannelFactory(name=channel_name)
     app_name = 'SparrowTestApp'
     ApplicationFactory._meta.database = 'root'
     app = ApplicationFactory(name=app_name)
     file = SimpleUploadedFile("test.dmg", b"content")
     SparkleVersionFactory._meta.database = 'root'
     SparkleVersionFactory.create(channel=channel, app=app, file=file)
     url = '%s%s' % (self.live_server_url,
                     reverse('sparkle_appcast',
                             kwargs=dict(app_name=app_name,
                                         channel=channel_name))
                     )  # replace by reverse
     resp = requests.get(url)
     root = objectify.fromstring(resp.content)
     self.assertTrue(app_name in str(root.channel.item.title))
Esempio n. 13
0
 def test_with_mac_versions(self):
     self.assertEqual(Platform.objects.count(), 4)
     self.assertEqual(Version.objects.count(), 2)
     mac_version = SparkleVersionFactory(app=self.app)
     self.assertEqual(
         SparkleVersion.objects.filter(app=self.app).count(), 1)
     platforms = get_platforms_by_appid(self.app)
     self.assertEqual(len(platforms), 3)
     assert self.a_platform in platforms
     assert self.b_platform in platforms
     assert self.mac_platform in platforms
     assert self.empty_platform not in platforms
Esempio n. 14
0
    def test_auto_fill_file_size(self):
        version = SparkleVersionFactory.create(file=SimpleUploadedFile('./chrome_installer.exe', b' ' * 10))
        data = dict(
            app=version.app.id,
            channel=version.channel.id,
            version='4.3.2.1',
            release_notes=version.release_notes,
            file=version.file,
        )

        new_version = SparkleVersionSerializer(data=data)
        self.assertTrue(new_version.is_valid())
        new_version_instance = new_version.save()
        self.assertEqual(new_version_instance.file_size, 10)
Esempio n. 15
0
 def test_serializer(self):
     version = SparkleVersionFactory.create(file=SimpleUploadedFile('./chrome_installer.exe', False))
     self.assertDictEqual(SparkleVersionSerializer(version).data, dict(
         id=version.id,
         is_enabled=version.is_enabled,
         app=version.app.id,
         channel=version.channel.id,
         version=version.version,
         short_version=version.short_version,
         release_notes=version.release_notes,
         file=version.file.url,
         file_size=version.file_size,
         dsa_signature=version.dsa_signature,
         created=version.created.strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
         modified=version.modified.strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
     ))
Esempio n. 16
0
    def test_sparkle(self):
        app = ApplicationFactory.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='chrome')
        channel = ChannelFactory.create(name='stable')
        obj = SparkleVersionFactory.create(
            app=app,
            channel=channel,
            version='782.112',
            short_version='13.0.782.112',
            file=SimpleUploadedFile('./chrome.dmg', b'_' * 23963192),
            file_size=23963192)
        obj.save()

        response = self.client.get(reverse('sparkle_appcast', args=(app.name, channel.name)),
                                   HTTP_HOST='example.com')

        self.assertEqual(response.status_code, 200)

        self.assertXmlDocument(response.content)
        self.assertXmlEquivalentOutputs(response.content,
                                        fixtures.response_sparkle)
Esempio n. 17
0
    def test_sparkle_with_dsa_signature(self):
        app = ApplicationFactory.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C9C}', name='chrome_dsa')
        channel = ChannelFactory.create(name='stable')
        obj = SparkleVersionFactory.create(
            app=app,
            channel=channel,
            version='782.112',
            short_version='13.0.782.112',
            dsa_signature='MCwCFCdoW13VBGJWIfIklKxQVyetgxE7AhQTVuY9uQT0KOV1UEk21epBsGZMPg==',
            file=SimpleUploadedFile('./chrome.dmg', b'_' * 23963192),
            file_size=23963192)
        obj.save()

        response = self.client.get(reverse('sparkle_appcast', args=(app.name, channel.name)),
                                   HTTP_HOST='example.com')

        self.assertEqual(response.status_code, 200)

        self.assertXmlDocument(response.content)
        self.assertXmlEquivalentOutputs(fixtures.response_sparkle_with_dsa,
                                        response.content)
Esempio n. 18
0
    def test_sparkle_with_dsa_signature(self):
        app = ApplicationFactory.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C9C}', name='chrome_dsa')
        channel = ChannelFactory.create(name='stable')
        obj = SparkleVersionFactory.create(
            app=app,
            channel=channel,
            version='782.112',
            short_version='13.0.782.112',
            dsa_signature='MCwCFCdoW13VBGJWIfIklKxQVyetgxE7AhQTVuY9uQT0KOV1UEk21epBsGZMPg==',
            file=SimpleUploadedFile('./chrome.dmg', b'_' * 23963192),
            file_size=23963192)
        obj.save()

        response = self.client.get(reverse('sparkle_appcast', args=(app.name, channel.name)),
                                   HTTP_HOST='example.com')

        self.assertEqual(response.status_code, 200)

        self.assertXmlDocument(response.content)
        self.assertXmlEquivalentOutputs(fixtures.response_sparkle_with_dsa,
                                        response.content)
Esempio n. 19
0
    def test_sparkle_versions(self, mocked_get_logger):
        gpm['SparkleVersion__limit_size'] = 1
        version_size = 1000*1024*1023
        versions = SparkleVersionFactory.create_batch(2, file_size=version_size)
        deleted_version = versions[0]
        self.assertEqual(SparkleVersion.objects.count(), 2)

        extra_meta = dict(count=1, reason='manual', meta=True, log_id='36446dc3-ae7c-42ad-ae4e-6a826dcf0a00',
                          model='SparkleVersion', 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(SparkleVersion_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(['sparkle', 'SparkleVersion'], 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)
Esempio n. 20
0
    def test_sparkle_versions(self, mocked_get_logger):
        gpm['SparkleVersion__limit_size'] = 1
        version_size = 1000*1024*1023
        versions = SparkleVersionFactory.create_batch(2, file_size=version_size)
        deleted_version = versions[0]
        self.assertEqual(SparkleVersion.objects.count(), 2)

        extra_meta = dict(count=1, reason='manual', meta=True, log_id='36446dc3-ae7c-42ad-ae4e-6a826dcf0a00',
                          model='SparkleVersion', 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(SparkleVersion_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(['sparkle', 'SparkleVersion'], 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)
Esempio n. 21
0
 def test_property(self):
     version = SparkleVersionFactory.create(file=SimpleUploadedFile('./chrome_installer.exe', ''))
     self.assertEqual(version.size, 123)
Esempio n. 22
0
 def test_get_size(self):
     file_size = 42
     SparkleVersionFactory.create_batch(10, file_size=file_size)
     size = SparkleVersion.objects.get_size()
     self.assertEqual(size, file_size*10)
Esempio n. 23
0
 def test_get_size(self):
     file_size = 42
     SparkleVersionFactory.create_batch(10, file_size=file_size)
     size = SparkleVersion.objects.get_size()
     self.assertEqual(size, file_size * 10)
Esempio n. 24
0
 def test_property(self):
     version = SparkleVersionFactory.create(file=SimpleUploadedFile('./chrome_installer.exe', ''))
     self.assertEqual(version.size, 123)