Skip to content

Commit

Permalink
wrote some early tests using Alex's schema (#52778)
Browse files Browse the repository at this point in the history
WIP of tests for exportable models. 

related prs are #52669

---------

Co-authored-by: Alex Zaslavsky <[email protected]>
  • Loading branch information
kneeyo1 and azaslavsky authored Jul 19, 2023
1 parent 4705814 commit 47d7971
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/sentry/backup/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
PendingIncidentSnapshot,
TimeSeriesSnapshot,
)
from sentry.models import (
ApiApplication,
ApiAuthorization,
ApiKey,
ApiToken,
Authenticator,
AuthIdentity,
AuthProvider,
)
from sentry.models.actor import ACTOR_TYPES, Actor
from sentry.models.counter import Counter
from sentry.models.dashboard import Dashboard, DashboardTombstone
Expand Down Expand Up @@ -299,6 +308,60 @@ def test_organization(self):
self.create_organization(owner=user)
return self.import_export_then_validate()

@targets_models(Actor)
def test_actor(self):
self.create_user(email="[email protected]")
self.create_team(name="pre save team", organization=self.organization)
return self.import_export_then_validate()

@targets_models(ApiAuthorization, ApiApplication)
def test_api_authorization_application(self):
user = self.create_user()
app = ApiApplication.objects.create(name="test", owner=user)
ApiAuthorization.objects.create(
application=app, user=self.create_user("[email protected]")
)
return self.import_export_then_validate()

@targets_models(ApiToken)
def test_apitoken(self):
user = self.create_user()
app = ApiApplication.objects.create(
owner=user, redirect_uris="http://example.com\nhttp://sub.example.com/path"
)
ApiToken.objects.create(application=app, user=user, token=uuid4().hex, expires_at=None)
return self.import_export_then_validate()

@targets_models(ApiKey)
def test_apikey(self):
user = self.create_user()
org = self.create_organization(owner=user)
ApiKey.objects.create(key=uuid4().hex, organization_id=org.id)
return self.import_export_then_validate()

@targets_models(Authenticator)
def test_authenticator(self):
user = self.create_user()
Authenticator.objects.create(user=user, type=1)
return self.import_export_then_validate()

@targets_models(AuthIdentity, AuthProvider)
def test_auth_identity_provider(self):
user = self.create_user()
test_data = {
"key1": "value1",
"key2": 42,
"key3": [1, 2, 3],
"key4": {"nested_key": "nested_value"},
}
AuthIdentity.objects.create(
user=user,
auth_provider=AuthProvider.objects.create(organization_id=1, provider="sentry"),
ident="123456789",
data=test_data,
)
return self.import_export_then_validate()

@targets_models(OrganizationAccessRequest, OrganizationMember, OrganizationMemberTeam, Team)
def test_organization_membership(self):
organization = self.create_organization(name="test_org", owner=self.user)
Expand Down

0 comments on commit 47d7971

Please sign in to comment.