/
test_orgauthtoken.py
34 lines (28 loc) · 1.13 KB
/
test_orgauthtoken.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pytest
from django.core.exceptions import ValidationError
from sentry.models import Organization, OrgAuthToken
from sentry.testutils import TestCase
from sentry.testutils.silo import region_silo_test
@region_silo_test(stable=True)
class OrgAuthTokenTest(TestCase):
def test_get_scopes(self):
token = OrgAuthToken(scope_list=["project:read", "project:releases"])
assert token.get_scopes() == ["project:read", "project:releases"]
def test_has_scope(self):
token = OrgAuthToken(scope_list=["project:read", "project:releases"])
assert token.has_scope("project:read")
assert token.has_scope("project:releases")
assert not token.has_scope("project:write")
def test_validate_scope(self):
org = Organization(name="Test org", slug="test-org")
token = OrgAuthToken(
organization_id=org.id,
name="test token",
token_hashed="test-token",
scope_list=["project:xxxx"],
)
with pytest.raises(
ValidationError,
match="project:xxxx is not a valid scope.",
):
token.full_clean()