Skip to content

Commit 75ab9e5

Browse files
committed
move release constants
1 parent 655f055 commit 75ab9e5

File tree

9 files changed

+34
-34
lines changed

9 files changed

+34
-34
lines changed

src/sentry/api/serializers/rest_framework/release.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,31 @@
44

55
from sentry.api.serializers.rest_framework import CommitSerializer, ListField
66
from sentry.api.fields.user import UserField
7-
from sentry.constants import VERSION_LENGTH
7+
from sentry.constants import MAX_COMMIT_LENGTH, MAX_VERSION_LENGTH
88
from sentry.models import Release
99

1010

1111
class ReleaseHeadCommitSerializerDeprecated(serializers.Serializer):
12-
currentId = serializers.CharField(max_length=64)
12+
currentId = serializers.CharField(max_length=MAX_COMMIT_LENGTH)
1313
repository = serializers.CharField(max_length=64)
14-
previousId = serializers.CharField(max_length=64, required=False)
14+
previousId = serializers.CharField(max_length=MAX_COMMIT_LENGTH, required=False)
1515

1616

1717
class ReleaseHeadCommitSerializer(serializers.Serializer):
18-
commit = serializers.CharField(max_length=64)
18+
commit = serializers.CharField(max_length=MAX_COMMIT_LENGTH)
1919
repository = serializers.CharField(max_length=200)
20-
previousCommit = serializers.CharField(max_length=64, required=False)
20+
previousCommit = serializers.CharField(max_length=MAX_COMMIT_LENGTH, required=False)
2121

2222

2323
class ReleaseSerializer(serializers.Serializer):
24-
ref = serializers.CharField(max_length=VERSION_LENGTH, required=False)
24+
ref = serializers.CharField(max_length=MAX_VERSION_LENGTH, required=False)
2525
url = serializers.URLField(required=False)
2626
dateReleased = serializers.DateTimeField(required=False)
2727
commits = ListField(child=CommitSerializer(), required=False, allow_null=False)
2828

2929

3030
class ReleaseWithVersionSerializer(ReleaseSerializer):
31-
version = serializers.CharField(max_length=VERSION_LENGTH, required=True)
31+
version = serializers.CharField(max_length=MAX_VERSION_LENGTH, required=True)
3232
owner = UserField(required=False)
3333

3434
def validate_version(self, attrs, source):

src/sentry/constants.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ def get_all_languages():
3939
MODULE_ROOT = os.path.dirname(__import__('sentry').__file__)
4040
DATA_ROOT = os.path.join(MODULE_ROOT, 'data')
4141

42-
VERSION_LENGTH = 200
42+
BAD_RELEASE_CHARS = '\n\f\t/'
43+
MAX_VERSION_LENGTH = 200
44+
MAX_COMMIT_LENGTH = 64
45+
COMMIT_RANGE_DELIMITER = '..'
4346

4447
SORT_OPTIONS = OrderedDict(
4548
(

src/sentry/models/release.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
JSONField, Model, sane_repr
2424
)
2525

26+
from sentry.constants import BAD_RELEASE_CHARS, COMMIT_RANGE_DELIMITER
2627
from sentry.models import CommitFileChange
2728
from sentry.signals import issue_resolved
2829

@@ -35,9 +36,7 @@
3536

3637
_sha1_re = re.compile(r'^[a-f0-9]{40}$')
3738
_dotted_path_prefix_re = re.compile(r'^([a-zA-Z][a-zA-Z0-9-]+)(\.[a-zA-Z][a-zA-Z0-9-]+)+-')
38-
BAD_RELEASE_CHARS = '\n\f\t/'
3939
DB_VERSION_LENGTH = 250
40-
COMMIT_RANGE_DELIMITER = '..'
4140

4241

4342
class ReleaseProject(Model):

tests/sentry/api/endpoints/test_organization_release_details.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from datetime import datetime
55
from django.core.urlresolvers import reverse
66

7-
from sentry.constants import VERSION_LENGTH
7+
from sentry.constants import MAX_VERSION_LENGTH
88
from sentry.models import (
99
Activity, Environment, File, Release, ReleaseCommit, ReleaseFile, ReleaseProject, ReleaseProjectEnvironment, Repository
1010
)
@@ -760,10 +760,10 @@ def test_do_not_allow_null_refs(self):
760760

761761
def test_ref_limited_by_max_version_length(self):
762762
serializer = OrganizationReleaseSerializer(data={
763-
'ref': 'a' * VERSION_LENGTH,
763+
'ref': 'a' * MAX_VERSION_LENGTH,
764764
})
765765
assert serializer.is_valid()
766766
serializer = OrganizationReleaseSerializer(data={
767-
'ref': 'a' * (VERSION_LENGTH + 1),
767+
'ref': 'a' * (MAX_VERSION_LENGTH + 1),
768768
})
769769
assert not serializer.is_valid()

tests/sentry/api/endpoints/test_organization_releases.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
from exam import fixture
1212

1313
from sentry.api.endpoints.organization_releases import ReleaseSerializerWithProjects
14-
from sentry.constants import VERSION_LENGTH
14+
from sentry.constants import BAD_RELEASE_CHARS, MAX_VERSION_LENGTH
1515
from sentry.models import (
1616
Activity,
1717
ApiKey,
1818
ApiToken,
19-
BAD_RELEASE_CHARS,
2019
Commit,
2120
CommitAuthor,
2221
CommitFileChange,
@@ -1447,24 +1446,24 @@ def test_ref_limited_by_max_version_length(self):
14471446
serializer = ReleaseSerializerWithProjects(data={
14481447
'version': self.version,
14491448
'projects': self.projects,
1450-
'ref': 'a' * VERSION_LENGTH,
1449+
'ref': 'a' * MAX_VERSION_LENGTH,
14511450
})
14521451
assert serializer.is_valid()
14531452
serializer = ReleaseSerializerWithProjects(data={
14541453
'version': self.version,
14551454
'projects': self.projects,
1456-
'ref': 'a' * (VERSION_LENGTH + 1),
1455+
'ref': 'a' * (MAX_VERSION_LENGTH + 1),
14571456
})
14581457
assert not serializer.is_valid()
14591458

14601459
def test_version_limited_by_max_version_length(self):
14611460
serializer = ReleaseSerializerWithProjects(data={
1462-
'version': 'a' * VERSION_LENGTH,
1461+
'version': 'a' * MAX_VERSION_LENGTH,
14631462
'projects': self.projects,
14641463
})
14651464
assert serializer.is_valid()
14661465
serializer = ReleaseSerializerWithProjects(data={
1467-
'version': 'a' * (VERSION_LENGTH + 1),
1466+
'version': 'a' * (MAX_VERSION_LENGTH + 1),
14681467
'projects': self.projects,
14691468
})
14701469
assert not serializer.is_valid()

tests/sentry/api/endpoints/test_project_release_details.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from django.core.urlresolvers import reverse
55

66
from sentry.api.endpoints.project_release_details import ReleaseSerializer
7-
from sentry.constants import VERSION_LENGTH
7+
from sentry.constants import MAX_VERSION_LENGTH
88
from sentry.models import (Activity, File, Release, ReleaseCommit, ReleaseFile, ReleaseProject)
99
from sentry.testutils import APITestCase
1010

@@ -295,10 +295,10 @@ def test_do_not_allow_null_commits(self):
295295

296296
def test_ref_limited_by_max_version_length(self):
297297
serializer = ReleaseSerializer(data={
298-
'ref': 'a' * VERSION_LENGTH,
298+
'ref': 'a' * MAX_VERSION_LENGTH,
299299
})
300300
assert serializer.is_valid()
301301
serializer = ReleaseSerializer(data={
302-
'ref': 'a' * (VERSION_LENGTH + 1),
302+
'ref': 'a' * (MAX_VERSION_LENGTH + 1),
303303
})
304304
assert not serializer.is_valid()

tests/sentry/api/endpoints/test_project_releases.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
from exam import fixture
77

88
from sentry.api.endpoints.project_releases import ReleaseWithVersionSerializer
9-
from sentry.constants import VERSION_LENGTH
9+
from sentry.constants import BAD_RELEASE_CHARS, MAX_VERSION_LENGTH
1010
from sentry.models import (
11-
BAD_RELEASE_CHARS,
1211
CommitAuthor,
1312
CommitFileChange,
1413
Environment,
@@ -743,22 +742,22 @@ def test_do_not_allow_null_commits(self):
743742
def test_ref_limited_by_max_version_length(self):
744743
serializer = ReleaseWithVersionSerializer(data={
745744
'version': self.version,
746-
'ref': 'a' * VERSION_LENGTH,
745+
'ref': 'a' * MAX_VERSION_LENGTH,
747746
})
748747
assert serializer.is_valid()
749748
serializer = ReleaseWithVersionSerializer(data={
750749
'version': self.version,
751-
'ref': 'a' * (VERSION_LENGTH + 1),
750+
'ref': 'a' * (MAX_VERSION_LENGTH + 1),
752751
})
753752
assert not serializer.is_valid()
754753

755754
def test_version_limited_by_max_version_length(self):
756755
serializer = ReleaseWithVersionSerializer(data={
757-
'version': 'a' * VERSION_LENGTH,
756+
'version': 'a' * MAX_VERSION_LENGTH,
758757
})
759758
assert serializer.is_valid()
760759
serializer = ReleaseWithVersionSerializer(data={
761-
'version': 'a' * (VERSION_LENGTH + 1),
760+
'version': 'a' * (MAX_VERSION_LENGTH + 1),
762761
})
763762
assert not serializer.is_valid()
764763

tests/sentry/event_manager/test_event_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from time import time
1414

1515
from sentry.app import tsdb
16-
from sentry.constants import VERSION_LENGTH
16+
from sentry.constants import MAX_VERSION_LENGTH
1717
from sentry.event_manager import HashDiscarded, EventManager, EventUser
1818
from sentry.grouping.utils import hash_from_values
1919
from sentry.models import (
@@ -688,7 +688,7 @@ def test_release_project_slug(self):
688688

689689
def test_release_project_slug_long(self):
690690
project = self.create_project(name='foo')
691-
partial_version_len = VERSION_LENGTH - 4
691+
partial_version_len = MAX_VERSION_LENGTH - 4
692692
release = Release.objects.create(
693693
version='foo-%s' % ('a' * partial_version_len, ), organization=project.organization
694694
)

tests/sentry/event_manager/test_validate_data.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from datetime import datetime, timedelta
66

7-
from sentry.constants import VERSION_LENGTH, MAX_CULPRIT_LENGTH
7+
from sentry.constants import MAX_VERSION_LENGTH, MAX_CULPRIT_LENGTH
88
from sentry.event_manager import EventManager
99

1010

@@ -174,7 +174,7 @@ def test_extra_as_string():
174174

175175
def test_release_tag_max_len():
176176
release_key = u"sentry:release"
177-
release_value = "a" * VERSION_LENGTH
177+
release_value = "a" * MAX_VERSION_LENGTH
178178
data = validate_and_normalize(
179179
{"message": "foo", "tags": [[release_key, release_value]]}
180180
)
@@ -197,8 +197,8 @@ def test_site_too_long():
197197

198198

199199
def test_release_too_long():
200-
data = validate_and_normalize({"release": "a" * (VERSION_LENGTH + 1)})
201-
assert len(data.get("release")) == VERSION_LENGTH
200+
data = validate_and_normalize({"release": "a" * (MAX_VERSION_LENGTH + 1)})
201+
assert len(data.get("release")) == MAX_VERSION_LENGTH
202202

203203

204204
def test_release_as_non_string():

0 commit comments

Comments
 (0)