|
| 1 | +from sentry.codecov.helper import CodecovUser, resolve_codecov_user |
| 2 | +from sentry.testutils.cases import TestCase |
| 3 | +from sentry.testutils.silo import all_silo_test |
| 4 | + |
| 5 | + |
| 6 | +@all_silo_test |
| 7 | +class TestCodecovUserResolution(TestCase): |
| 8 | + def setUp(self): |
| 9 | + self.organization = self.create_organization() |
| 10 | + self.user = self.create_user() |
| 11 | + |
| 12 | + def test_get_auth_provider_identity_for_user(self): |
| 13 | + auth_provider = self.create_auth_provider( |
| 14 | + organization_id=self.organization.id, provider="github" |
| 15 | + ) |
| 16 | + self.create_auth_identity( |
| 17 | + auth_provider=auth_provider, |
| 18 | + user=self.user, |
| 19 | + ident=12345, |
| 20 | + data={"access_token": "this_is_the_access_token_stored_here"}, |
| 21 | + ) |
| 22 | + assert resolve_codecov_user(self.user.id, self.organization.id) == CodecovUser( |
| 23 | + external_id="12345", auth_token="this_is_the_access_token_stored_here" |
| 24 | + ) |
| 25 | + |
| 26 | + def test_get_auth_identity_for_user(self): |
| 27 | + # Create the Auth Provider to fall through |
| 28 | + self.create_auth_provider(organization_id=self.organization.id, provider="github") |
| 29 | + |
| 30 | + identity_provider = self.create_identity_provider(type="github") |
| 31 | + self.create_identity( |
| 32 | + user=self.user, |
| 33 | + identity_provider=identity_provider, |
| 34 | + external_id="identity_id_12345", |
| 35 | + data={"access_token": "this_is_the_access_token_stored_here"}, |
| 36 | + ) |
| 37 | + |
| 38 | + assert resolve_codecov_user(self.user.id, self.organization.id) == CodecovUser( |
| 39 | + external_id="identity_id_12345", auth_token="this_is_the_access_token_stored_here" |
| 40 | + ) |
| 41 | + |
| 42 | + def test_no_linked_identity(self): |
| 43 | + assert resolve_codecov_user(self.user.id, self.organization.id) is None |
0 commit comments