|
@@ -1,7 +1,9 @@
|
|
|
import pytest
|
|
|
+from django.contrib.auth.models import AnonymousUser
|
|
|
|
|
|
from flagpole.sentry_flagpole_context import (
|
|
|
InvalidContextDataException,
|
|
|
+ SentryContextData,
|
|
|
get_sentry_flagpole_context_builder,
|
|
|
organization_context_transformer,
|
|
|
project_context_transformer,
|
|
@@ -18,7 +20,9 @@ class TestSentryFlagpoleContext(TestCase):
|
|
|
project = self.create_project(organization=org)
|
|
|
sentry_flagpole_builder = get_sentry_flagpole_context_builder()
|
|
|
|
|
|
- sentry_context = sentry_flagpole_builder.build(dict(organization=org, project=project))
|
|
|
+ sentry_context = sentry_flagpole_builder.build(
|
|
|
+ SentryContextData(organization=org, project=project)
|
|
|
+ )
|
|
|
|
|
|
assert sentry_context.get("organization_slug") == org.slug
|
|
|
assert sentry_context.get("organization_slug") == org.slug
|
|
@@ -28,15 +32,15 @@ class TestSentryFlagpoleContext(TestCase):
|
|
|
|
|
|
class TestSentryOrganizationContextTransformer(TestCase):
|
|
|
def test_without_organization_passed(self):
|
|
|
- context_data = organization_context_transformer(dict())
|
|
|
- assert context_data == dict()
|
|
|
+ context_data = organization_context_transformer(SentryContextData())
|
|
|
+ assert context_data == {}
|
|
|
|
|
|
def test_with_invalid_organization(self):
|
|
|
with pytest.raises(InvalidContextDataException):
|
|
|
- organization_context_transformer(dict(organization=1234))
|
|
|
+ organization_context_transformer(SentryContextData(organization=1234)) # type: ignore[arg-type]
|
|
|
|
|
|
with pytest.raises(InvalidContextDataException):
|
|
|
- organization_context_transformer(dict(organization=self.create_project()))
|
|
|
+ organization_context_transformer(SentryContextData(organization=self.create_project()))
|
|
|
|
|
|
def test_with_valid_organization(self):
|
|
|
org = self.create_organization(slug="foobar", name="Foo Bar")
|
|
@@ -44,7 +48,7 @@ class TestSentryOrganizationContextTransformer(TestCase):
|
|
|
org.save()
|
|
|
assert bool(org.flags.early_adopter) is True
|
|
|
|
|
|
- context_data = organization_context_transformer(dict(organization=org))
|
|
|
+ context_data = organization_context_transformer(SentryContextData(organization=org))
|
|
|
|
|
|
assert context_data == {
|
|
|
"organization_slug": "foobar",
|
|
@@ -56,20 +60,20 @@ class TestSentryOrganizationContextTransformer(TestCase):
|
|
|
|
|
|
class TestProjectContextTransformer(TestCase):
|
|
|
def test_without_project_passed(self):
|
|
|
- context_data = project_context_transformer(dict())
|
|
|
- assert context_data == dict()
|
|
|
+ context_data = project_context_transformer(SentryContextData())
|
|
|
+ assert context_data == {}
|
|
|
|
|
|
def test_with_invalid_project_passed(self):
|
|
|
with pytest.raises(InvalidContextDataException):
|
|
|
- project_context_transformer(dict(project=123))
|
|
|
+ project_context_transformer(SentryContextData(project=123)) # type: ignore[arg-type]
|
|
|
|
|
|
with pytest.raises(InvalidContextDataException):
|
|
|
- project_context_transformer(dict(project=self.create_organization()))
|
|
|
+ project_context_transformer(SentryContextData(project=self.create_organization()))
|
|
|
|
|
|
def test_with_valid_project(self):
|
|
|
project = self.create_project(slug="foobar", name="Foo Bar")
|
|
|
|
|
|
- context_data = project_context_transformer(dict(project=project))
|
|
|
+ context_data = project_context_transformer(SentryContextData(project=project))
|
|
|
assert context_data == {
|
|
|
"project_slug": "foobar",
|
|
|
"project_name": "Foo Bar",
|
|
@@ -80,22 +84,22 @@ class TestProjectContextTransformer(TestCase):
|
|
|
@control_silo_test
|
|
|
class TestUserContextTransformer(TestCase):
|
|
|
def test_without_user_passed(self):
|
|
|
- context_data = project_context_transformer(dict())
|
|
|
- assert context_data == dict()
|
|
|
+ context_data = project_context_transformer(SentryContextData())
|
|
|
+ assert context_data == {}
|
|
|
|
|
|
def test_with_invalid_user_passed(self):
|
|
|
with pytest.raises(InvalidContextDataException):
|
|
|
- user_context_transformer(dict(actor=123))
|
|
|
+ user_context_transformer(SentryContextData(actor=123)) # type: ignore[arg-type]
|
|
|
|
|
|
with pytest.raises(InvalidContextDataException):
|
|
|
- user_context_transformer(dict(actor=self.create_organization()))
|
|
|
+ user_context_transformer(SentryContextData(actor=self.create_organization()))
|
|
|
|
|
|
def test_with_valid_user(self):
|
|
|
user = self.create_user(email="foobar@example.com")
|
|
|
# Create a new, unverified email to ensure we don't list it
|
|
|
self.create_useremail(user=user, email="unverified_email@example.com")
|
|
|
|
|
|
- context_data = user_context_transformer(dict(actor=user))
|
|
|
+ context_data = user_context_transformer(SentryContextData(actor=user))
|
|
|
assert context_data == {
|
|
|
"user_email": "foobar@example.com",
|
|
|
"user_domain": "example.com",
|
|
@@ -110,7 +114,7 @@ class TestUserContextTransformer(TestCase):
|
|
|
user_email.is_verified = False
|
|
|
user_email.save()
|
|
|
|
|
|
- context_data = user_context_transformer(dict(actor=user))
|
|
|
+ context_data = user_context_transformer(SentryContextData(actor=user))
|
|
|
assert context_data == {
|
|
|
"user_id": user.id,
|
|
|
"user_is-superuser": False,
|
|
@@ -119,7 +123,7 @@ class TestUserContextTransformer(TestCase):
|
|
|
|
|
|
def test_with_super_user_and_staff(self):
|
|
|
user = self.create_user(email="super_user_admin_person@sentry.io", is_superuser=True)
|
|
|
- context_data = user_context_transformer(dict(actor=user))
|
|
|
+ context_data = user_context_transformer(SentryContextData(actor=user))
|
|
|
assert context_data == {
|
|
|
"user_email": "super_user_admin_person@sentry.io",
|
|
|
"user_domain": "sentry.io",
|
|
@@ -131,7 +135,7 @@ class TestUserContextTransformer(TestCase):
|
|
|
user.is_staff = True
|
|
|
user.is_superuser = False
|
|
|
user.save()
|
|
|
- context_data = user_context_transformer(dict(actor=user))
|
|
|
+ context_data = user_context_transformer(SentryContextData(actor=user))
|
|
|
assert context_data == {
|
|
|
"user_email": "super_user_admin_person@sentry.io",
|
|
|
"user_domain": "sentry.io",
|
|
@@ -140,24 +144,7 @@ class TestUserContextTransformer(TestCase):
|
|
|
"user_is-staff": True,
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-class TestTeamContextTransformer(TestCase):
|
|
|
- pass
|
|
|
- # def test_with_missing_team(self):
|
|
|
- # context_data = team_context_transformer(dict())
|
|
|
- # assert context_data == dict()
|
|
|
- #
|
|
|
- # def test_with_invalid_team(self):
|
|
|
- # with pytest.raises(InvalidContextDataException):
|
|
|
- # team_context_transformer(dict(team="invalid"))
|
|
|
- #
|
|
|
- # with pytest.raises(InvalidContextDataException):
|
|
|
- # team_context_transformer(dict(team=self.create_organization()))
|
|
|
- #
|
|
|
- # def test_with_valid_team(self):
|
|
|
- # team = self.create_team(organization=self.create_organization())
|
|
|
- #
|
|
|
- # context_data = team_context_transformer(dict(team=team))
|
|
|
- # assert context_data == {
|
|
|
- # "team_id": team.id
|
|
|
- # }
|
|
|
+ def test_with_anonymous_user(self):
|
|
|
+ user = AnonymousUser()
|
|
|
+ context_data = user_context_transformer(SentryContextData(actor=user))
|
|
|
+ assert context_data == {}
|