|
@@ -5,6 +5,37 @@ from sentry.testutils import APITestCase
|
|
|
|
|
|
|
|
|
|
class GroupTagsTest(APITestCase):
|
|
class GroupTagsTest(APITestCase):
|
|
|
|
+ def _create_tags(self, group, environment_id=None):
|
|
|
|
+ for key, values in group.data['tags']:
|
|
|
|
+ tagstore.create_tag_key(
|
|
|
|
+ project_id=group.project_id,
|
|
|
|
+ environment_id=environment_id,
|
|
|
|
+ key=key,
|
|
|
|
+ )
|
|
|
|
+ tagstore.create_group_tag_key(
|
|
|
|
+ project_id=group.project_id,
|
|
|
|
+ group_id=group.id,
|
|
|
|
+ environment_id=environment_id,
|
|
|
|
+ key=key,
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ if not isinstance(values, list):
|
|
|
|
+ values = [values]
|
|
|
|
+ for value in values:
|
|
|
|
+ tagstore.create_tag_value(
|
|
|
|
+ project_id=group.project_id,
|
|
|
|
+ environment_id=environment_id,
|
|
|
|
+ key=key,
|
|
|
|
+ value=value,
|
|
|
|
+ )
|
|
|
|
+ tagstore.create_group_tag_value(
|
|
|
|
+ project_id=group.project_id,
|
|
|
|
+ group_id=group.id,
|
|
|
|
+ environment_id=environment_id,
|
|
|
|
+ key=key,
|
|
|
|
+ value=value,
|
|
|
|
+ )
|
|
|
|
+
|
|
def test_simple(self):
|
|
def test_simple(self):
|
|
this_group = self.create_group()
|
|
this_group = self.create_group()
|
|
this_group.data['tags'] = (['foo', ['bar', 'quux']], ['biz', 'baz'], [
|
|
this_group.data['tags'] = (['foo', ['bar', 'quux']], ['biz', 'baz'], [
|
|
@@ -17,35 +48,7 @@ class GroupTagsTest(APITestCase):
|
|
other_group.save()
|
|
other_group.save()
|
|
|
|
|
|
for group in (this_group, other_group):
|
|
for group in (this_group, other_group):
|
|
- for key, values in group.data['tags']:
|
|
|
|
- tagstore.create_tag_key(
|
|
|
|
- project_id=group.project_id,
|
|
|
|
- environment_id=None,
|
|
|
|
- key=key,
|
|
|
|
- )
|
|
|
|
- tagstore.create_group_tag_key(
|
|
|
|
- project_id=group.project_id,
|
|
|
|
- group_id=group.id,
|
|
|
|
- environment_id=None,
|
|
|
|
- key=key,
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
- if not isinstance(values, list):
|
|
|
|
- values = [values]
|
|
|
|
- for value in values:
|
|
|
|
- tagstore.create_tag_value(
|
|
|
|
- project_id=group.project_id,
|
|
|
|
- environment_id=None,
|
|
|
|
- key=key,
|
|
|
|
- value=value,
|
|
|
|
- )
|
|
|
|
- tagstore.create_group_tag_value(
|
|
|
|
- project_id=group.project_id,
|
|
|
|
- group_id=group.id,
|
|
|
|
- environment_id=None,
|
|
|
|
- key=key,
|
|
|
|
- value=value,
|
|
|
|
- )
|
|
|
|
|
|
+ self._create_tags(group)
|
|
|
|
|
|
self.login_as(user=self.user)
|
|
self.login_as(user=self.user)
|
|
|
|
|
|
@@ -84,4 +87,18 @@ class GroupTagsTest(APITestCase):
|
|
self.login_as(user=self.user)
|
|
self.login_as(user=self.user)
|
|
url = u'/api/0/issues/{}/tags/'.format(this_group.id)
|
|
url = u'/api/0/issues/{}/tags/'.format(this_group.id)
|
|
response = self.client.get(url, {'environment': 'notreal'}, format='json')
|
|
response = self.client.get(url, {'environment': 'notreal'}, format='json')
|
|
- assert response.data == []
|
|
|
|
|
|
+ assert response.status_code == 404
|
|
|
|
+
|
|
|
|
+ def test_valid_env(self):
|
|
|
|
+ group = self.create_group()
|
|
|
|
+ group.data['tags'] = (['foo', 'bar'], ['biz', 'baz'])
|
|
|
|
+ group.save()
|
|
|
|
+
|
|
|
|
+ env = self.create_environment(project=group.project)
|
|
|
|
+ self._create_tags(group, environment_id=env.id)
|
|
|
|
+
|
|
|
|
+ self.login_as(user=self.user)
|
|
|
|
+ url = u'/api/0/issues/{}/tags/'.format(group.id)
|
|
|
|
+ response = self.client.get(url, {'environment': env.name}, format='json')
|
|
|
|
+ assert response.status_code == 200
|
|
|
|
+ assert len(response.data) == 2
|