Exemplo n.º 1
0
    def test_debug(self, safe_urlread, safe_urlopen, mock_get_all_package_versions):
        mock_get_all_package_versions.return_value = {"foo": "1.0"}

        with self.settings(DEBUG=True):
            send_beacon()

        assert not safe_urlopen.mock_calls
Exemplo n.º 2
0
    def test_anonymous(self, safe_urlread, safe_urlopen, mock_get_all_package_versions):
        mock_get_all_package_versions.return_value = {"foo": "1.0"}
        safe_urlread.return_value = json.dumps({"notices": [], "version": {"stable": "1.0.0"}})

        assert options.set("system.admin-email", "*****@*****.**")
        assert options.set("beacon.anonymous", True)
        send_beacon()

        install_id = options.get("sentry:install-id")
        assert install_id and len(install_id) == 40

        safe_urlopen.assert_called_once_with(
            BEACON_URL,
            json={
                "install_id": install_id,
                "version": sentry.get_version(),
                "docker": sentry.is_docker(),
                "python_version": platform.python_version(),
                "data": {
                    "organizations": 1,
                    "users": 0,
                    "projects": 1,
                    "teams": 1,
                    "events.24h": 0,
                },
                "anonymous": True,
                "packages": mock_get_all_package_versions.return_value,
            },
            timeout=5,
        )
        safe_urlread.assert_called_once_with(safe_urlopen.return_value)

        assert options.get("sentry:latest_version") == "1.0.0"
Exemplo n.º 3
0
    def test_simple(self, safe_urlread, safe_urlopen):
        safe_urlread.return_value = json.dumps({
            'notices': [],
            'version': {
                'stable': '1.0.0'
            },
        })

        with self.settings(SENTRY_ADMIN_EMAIL='*****@*****.**'):
            send_beacon()

        install_id = options.get('sentry:install-id')
        assert install_id and len(install_id) == 40

        safe_urlopen.assert_called_once_with(BEACON_URL,
                                             json={
                                                 'install_id': install_id,
                                                 'version':
                                                 sentry.get_version(),
                                                 'data': {
                                                     'organizations': 1,
                                                     'users': 0,
                                                     'projects': 1,
                                                     'teams': 1,
                                                     'events.24h': 0,
                                                 },
                                                 'admin_email':
                                                 '*****@*****.**',
                                             },
                                             timeout=5)
        safe_urlread.assert_called_once_with(safe_urlopen.return_value)

        assert options.get('sentry:latest_version') == '1.0.0'
Exemplo n.º 4
0
    def test_disabled(self, safe_urlread, safe_urlopen, mock_get_all_package_versions):
        mock_get_all_package_versions.return_value = {"foo": "1.0"}

        with self.settings(SENTRY_BEACON=False):
            send_beacon()

        assert not safe_urlopen.mock_calls
Exemplo n.º 5
0
    def test_with_broadcasts(self, safe_urlread, safe_urlopen, mock_get_all_package_versions):
        broadcast_id = uuid4().hex
        mock_get_all_package_versions.return_value = {}
        safe_urlread.return_value = json.dumps(
            {
                "notices": [
                    {
                        "id": broadcast_id,
                        "title": "Hello!",
                        "message": "Hello world",
                        "active": True,
                    }
                ],
                "version": {"stable": "1.0.0"},
            }
        )

        with self.settings():
            send_beacon()

        broadcast = Broadcast.objects.get(upstream_id=broadcast_id)

        assert broadcast.title == "Hello!"
        assert broadcast.message == "Hello world"
        assert broadcast.is_active

        safe_urlread.return_value = json.dumps({"notices": [], "version": {"stable": "1.0.0"}})

        with self.settings():
            send_beacon()

        # test explicit disable
        broadcast = Broadcast.objects.get(upstream_id=broadcast_id)

        assert not broadcast.is_active
Exemplo n.º 6
0
    def test_simple(self, safe_urlread, safe_urlopen):
        self.create_project(platform='java')

        safe_urlread.return_value = json.dumps({
            'notices': [],
            'version': {'stable': '1.0.0'},
        })

        with self.settings(SENTRY_ADMIN_EMAIL='*****@*****.**'):
            send_beacon()

        install_id = options.get('sentry:install-id')
        assert install_id and len(install_id) == 40

        safe_urlopen.assert_called_once_with(BEACON_URL, json={
            'install_id': install_id,
            'version': sentry.get_version(),
            'data': {
                'platforms': ['java'],
                'organizations': 2,
                'users': 2,
                'projects': 2,
                'teams': 2,
                'events.24h': 0,
            },
            'admin_email': '*****@*****.**',
        }, timeout=5)
        safe_urlread.assert_called_once_with(safe_urlopen.return_value)

        assert options.get('sentry:latest_version') == '1.0.0'
Exemplo n.º 7
0
    def test_with_broadcasts(self, safe_urlread, safe_urlopen,
                             mock_get_all_package_versions):
        broadcast_id = uuid4().hex
        mock_get_all_package_versions.return_value = {}
        safe_urlread.return_value = json.dumps({
            'notices': [{
                'id': broadcast_id,
                'title': 'Hello!',
                'message': 'Hello world',
                'active': True,
            }],
            'version': {'stable': '1.0.0'},
        })

        with self.settings():
            send_beacon()

        broadcast = Broadcast.objects.get(upstream_id=broadcast_id)

        assert broadcast.title == 'Hello!'
        assert broadcast.message == 'Hello world'
        assert broadcast.is_active

        safe_urlread.return_value = json.dumps({
            'notices': [],
            'version': {'stable': '1.0.0'},
        })

        with self.settings():
            send_beacon()

        # test explicit disable
        broadcast = Broadcast.objects.get(upstream_id=broadcast_id)

        assert not broadcast.is_active
Exemplo n.º 8
0
    def test_simple(self, safe_urlread, safe_urlopen,
                    mock_get_all_package_versions):
        mock_get_all_package_versions.return_value = {'foo': '1.0'}
        safe_urlread.return_value = json.dumps({
            'notices': [],
            'version': {'stable': '1.0.0'},
        })

        assert options.set('system.admin-email', '*****@*****.**')
        send_beacon()

        install_id = options.get('sentry:install-id')
        assert install_id and len(install_id) == 40

        safe_urlopen.assert_called_once_with(BEACON_URL, json={
            'install_id': install_id,
            'version': sentry.get_version(),
            'data': {
                'organizations': 1,
                'users': 0,
                'projects': 1,
                'teams': 1,
                'events.24h': 0,
            },
            'admin_email': '*****@*****.**',
            'packages': mock_get_all_package_versions.return_value,
        }, timeout=5)
        safe_urlread.assert_called_once_with(safe_urlopen.return_value)

        assert options.get('sentry:latest_version') == '1.0.0'
Exemplo n.º 9
0
    def test_with_broadcasts(self, safe_urlread, safe_urlopen, mock_get_all_package_versions):
        broadcast_id = uuid4().hex
        mock_get_all_package_versions.return_value = {}
        safe_urlread.return_value = json.dumps(
            {
                "notices": [{"id": broadcast_id, "title": "Hello!", "message": "Hello world", "active": True}],
                "version": {"stable": "1.0.0"},
            }
        )

        with self.settings():
            send_beacon()

        broadcast = Broadcast.objects.get(upstream_id=broadcast_id)

        assert broadcast.title == "Hello!"
        assert broadcast.message == "Hello world"
        assert broadcast.is_active

        safe_urlread.return_value = json.dumps({"notices": [], "version": {"stable": "1.0.0"}})

        with self.settings():
            send_beacon()

        # test explicit disable
        broadcast = Broadcast.objects.get(upstream_id=broadcast_id)

        assert not broadcast.is_active
Exemplo n.º 10
0
    def test_simple(self, safe_urlread, safe_urlopen, mock_get_all_package_versions):
        mock_get_all_package_versions.return_value = {"foo": "1.0"}
        safe_urlread.return_value = json.dumps({"notices": [], "version": {"stable": "1.0.0"}})

        with self.settings(SENTRY_ADMIN_EMAIL="*****@*****.**"):
            send_beacon()

        install_id = options.get("sentry:install-id")
        assert install_id and len(install_id) == 40

        safe_urlopen.assert_called_once_with(
            BEACON_URL,
            json={
                "install_id": install_id,
                "version": sentry.get_version(),
                "data": {"organizations": 1, "users": 0, "projects": 1, "teams": 1, "events.24h": 0},
                "admin_email": "*****@*****.**",
                "packages": mock_get_all_package_versions.return_value,
            },
            timeout=5,
        )
        safe_urlread.assert_called_once_with(safe_urlopen.return_value)

        assert options.get("sentry:latest_version") == "1.0.0"
Exemplo n.º 11
0
    def test_with_broadcasts(self, safe_urlread, safe_urlopen,
                             mock_get_all_package_versions):
        broadcast_id = uuid4().hex
        mock_get_all_package_versions.return_value = {}
        safe_urlread.return_value = json.dumps({
            "notices": [{
                "id": broadcast_id,
                "title": "Hello!",
                "message": "Hello world",
                "active": True,
            }],
            "version": {
                "stable": "1.0.0"
            },
        })

        with self.settings():
            send_beacon()

        assert Broadcast.objects.count() == 1

        broadcast = Broadcast.objects.get(upstream_id=broadcast_id)

        assert broadcast.title == "Hello!"
        assert broadcast.message == "Hello world"
        assert broadcast.is_active

        # ensure we arent duplicating the broadcast
        with self.settings():
            send_beacon()

        assert Broadcast.objects.count() == 1

        broadcast = Broadcast.objects.get(upstream_id=broadcast_id)

        assert broadcast.title == "Hello!"
        assert broadcast.message == "Hello world"
        assert broadcast.is_active

        # now remove it and it should become inactive
        safe_urlread.return_value = json.dumps({
            "notices": [],
            "version": {
                "stable": "1.0.0"
            }
        })

        with self.settings():
            send_beacon()

        assert Broadcast.objects.count() == 1

        broadcast = Broadcast.objects.get(upstream_id=broadcast_id)

        assert not broadcast.is_active