diff --git a/tests/relay_integration/lang/javascript/test_plugin.py b/tests/relay_integration/lang/javascript/test_plugin.py index b155d01a0cb03c..bb2f03c0839dae 100644 --- a/tests/relay_integration/lang/javascript/test_plugin.py +++ b/tests/relay_integration/lang/javascript/test_plugin.py @@ -7,7 +7,6 @@ import pytest import responses -from django.utils.encoding import force_bytes from sentry.models import ( ArtifactBundle, @@ -183,7 +182,7 @@ def test_source_expansion(self, mock_fetch_by_url): }, } - mock_fetch_by_url.return_value.body = force_bytes("\n".join("hello world")) + mock_fetch_by_url.return_value.body = "\n".join("hello world").encode() mock_fetch_by_url.return_value.encoding = None mock_fetch_by_url.return_value.headers = {} @@ -236,7 +235,7 @@ def test_inlined_sources(self, mock_discover_sourcemap, mock_fetch_by_url): mock_discover_sourcemap.return_value = BASE64_SOURCEMAP mock_fetch_by_url.return_value.url = "http://example.com/test.min.js" - mock_fetch_by_url.return_value.body = force_bytes("\n".join("")) + mock_fetch_by_url.return_value.body = "\n".join("").encode() mock_fetch_by_url.return_value.encoding = None event = self.post_and_retrieve_event(data) @@ -283,7 +282,7 @@ def test_invalid_base64_sourcemap_returns_an_error( mock_discover_sourcemap.return_value = INVALID_BASE64_SOURCEMAP mock_fetch_by_url.return_value.url = "http://example.com/test.min.js" - mock_fetch_by_url.return_value.body = force_bytes("\n".join("")) + mock_fetch_by_url.return_value.body = "\n".join("").encode() mock_fetch_by_url.return_value.encoding = None event = self.post_and_retrieve_event(data) @@ -342,7 +341,7 @@ def test_sourcemap_cache_is_constructed_only_once_if_an_error_is_raised( mock_discover_sourcemap.return_value = BASE64_SOURCEMAP mock_fetch_by_url.return_value.url = "http://example.com/test.min.js" - mock_fetch_by_url.return_value.body = force_bytes("\n".join("")) + mock_fetch_by_url.return_value.body = "\n".join("").encode() mock_fetch_by_url.return_value.encoding = None mock_from_bytes.side_effect = Exception() diff --git a/tests/sentry/buffer/test_redis.py b/tests/sentry/buffer/test_redis.py index 6d2bfe2d66b8b2..9286f2e4d41847 100644 --- a/tests/sentry/buffer/test_redis.py +++ b/tests/sentry/buffer/test_redis.py @@ -4,7 +4,6 @@ import pytest from django.utils import timezone -from django.utils.encoding import force_str from freezegun import freeze_time from sentry import options @@ -141,8 +140,8 @@ def test_incr_saves_to_redis(self): key = self.buf._make_key(model, filters=filters) self.buf.incr(model, columns, filters, extra={"foo": "bar", "datetime": now}) result = client.hgetall(key) - # Force keys to strings - result = {force_str(k): v for k, v in result.items()} + if not self.buf.is_redis_cluster: + result = {k.decode(): v for k, v in result.items()} f = result.pop("f") if self.buf.is_redis_cluster: @@ -171,8 +170,8 @@ def load_value(x): assert pending == [key.encode("utf-8")] self.buf.incr(model, columns, filters, extra={"foo": "baz", "datetime": now}) result = client.hgetall(key) - # Force keys to strings - result = {force_str(k): v for k, v in result.items()} + if not self.buf.is_redis_cluster: + result = {k.decode(): v for k, v in result.items()} f = result.pop("f") assert load_values(f) == {"pk": 1, "datetime": now} assert load_value(result.pop("e+datetime")) == now diff --git a/tests/sentry/db/models/fields/test_jsonfield.py b/tests/sentry/db/models/fields/test_jsonfield.py index 3f6242e757480c..3059595b643812 100644 --- a/tests/sentry/db/models/fields/test_jsonfield.py +++ b/tests/sentry/db/models/fields/test_jsonfield.py @@ -1,7 +1,6 @@ import pytest from django import forms from django.db import models -from django.utils.encoding import force_str from sentry.db.models.fields.jsonfield import JSONField from sentry.testutils import TestCase @@ -91,7 +90,7 @@ def test_formfield_clean_blank(self): formfield = field.formfield() self.assertRaisesMessage( forms.ValidationError, - force_str(formfield.error_messages["required"]), + str(formfield.error_messages["required"]), formfield.clean, value="", ) @@ -101,7 +100,7 @@ def test_formfield_clean_none(self): formfield = field.formfield() self.assertRaisesMessage( forms.ValidationError, - force_str(formfield.error_messages["required"]), + str(formfield.error_messages["required"]), formfield.clean, value=None, ) diff --git a/tests/sentry/db/postgres/test_base.py b/tests/sentry/db/postgres/test_base.py index 5b9565cd36d511..5fbbb4d37cb381 100644 --- a/tests/sentry/db/postgres/test_base.py +++ b/tests/sentry/db/postgres/test_base.py @@ -1,5 +1,3 @@ -from django.utils.encoding import force_bytes, force_str - from sentry.constants import MAX_CULPRIT_LENGTH from sentry.testutils import TestCase @@ -10,14 +8,14 @@ def test_null_bytes(self): cursor = connection.cursor() cursor.execute("SELECT %s", [b"Ma\x00tt"]) - assert force_bytes(cursor.fetchone()[0]) == b"Matt" + assert bytes(cursor.fetchone()[0]) == b"Matt" cursor.execute("SELECT %s", ["Ma\x00tt"]) assert cursor.fetchone()[0] == "Matt" cursor = connection.cursor() cursor.execute("SELECT %(name)s", {"name": b"Ma\x00tt"}) - assert force_bytes(cursor.fetchone()[0]) == b"Matt" + assert bytes(cursor.fetchone()[0]) == b"Matt" cursor.execute("SELECT %(name)s", {"name": "Ma\x00tt"}) assert cursor.fetchone()[0] == "Matt" @@ -31,12 +29,12 @@ def test_null_bytes_at_max_len_bytes(self): assert len(long_str) <= MAX_CULPRIT_LENGTH cursor.execute("SELECT %s", [long_str]) - long_str_from_db = force_bytes(cursor.fetchone()[0]) + long_str_from_db = bytes(cursor.fetchone()[0]) assert long_str_from_db == (b"a" * (MAX_CULPRIT_LENGTH - 1)) assert len(long_str_from_db) <= MAX_CULPRIT_LENGTH cursor.execute("SELECT %(long_str)s", {"long_str": long_str}) - long_str_from_db = force_bytes(cursor.fetchone()[0]) + long_str_from_db = bytes(cursor.fetchone()[0]) assert long_str_from_db == (b"a" * (MAX_CULPRIT_LENGTH - 1)) assert len(long_str_from_db) <= MAX_CULPRIT_LENGTH @@ -65,9 +63,9 @@ def test_lone_surrogates(self): bad_str = "Hello\ud83dWorld🇦🇹!" cursor.execute("SELECT %s", [bad_str]) - bad_str_from_db = force_str(cursor.fetchone()[0]) + bad_str_from_db = cursor.fetchone()[0] assert bad_str_from_db == "HelloWorld🇦🇹!" cursor.execute("SELECT %(bad_str)s", {"bad_str": bad_str}) - bad_str_from_db = force_str(cursor.fetchone()[0]) + bad_str_from_db = cursor.fetchone()[0] assert bad_str_from_db == "HelloWorld🇦🇹!" diff --git a/tests/sentry/web/frontend/test_account_identity.py b/tests/sentry/web/frontend/test_account_identity.py index 7b578e2ee81a49..cd551b0498abdc 100644 --- a/tests/sentry/web/frontend/test_account_identity.py +++ b/tests/sentry/web/frontend/test_account_identity.py @@ -1,6 +1,5 @@ import pytest from django.urls import reverse -from django.utils.encoding import force_bytes from sentry import identity from sentry.identity.providers.dummy import DummyProvider @@ -35,7 +34,7 @@ def test_associate_identity(self): resp = self.client.post(path) assert resp.status_code == 200 - assert resp.content == force_bytes(DummyProvider.TEMPLATE) + assert resp.content == DummyProvider.TEMPLATE.encode() resp = self.client.post(path, data={"email": "rick@example.com"}) ident = Identity.objects.get(user=user)