本文整理汇总了Python中sentry.models.Environment类的典型用法代码示例。如果您正苦于以下问题:Python Environment类的具体用法?Python Environment怎么用?Python Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Environment类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_transfer_to_team
def test_transfer_to_team(self):
from_org = self.create_organization()
from_team = self.create_team(organization=from_org)
to_org = self.create_organization()
to_team = self.create_team(organization=to_org)
project = self.create_project(teams=[from_team])
rule = Rule.objects.create(
project=project,
environment_id=Environment.get_or_create(project, 'production').id,
label='Golden Rule',
data={},
)
project.transfer_to(team=to_team)
project = Project.objects.get(id=project.id)
assert project.teams.count() == 1
assert project.teams.first() == to_team
assert project.organization_id == to_org.id
updated_rule = project.rule_set.get(label='Golden Rule')
assert updated_rule.id == rule.id
assert updated_rule.environment_id != rule.environment_id
assert updated_rule.environment_id == Environment.get_or_create(project, 'production').id
开发者ID:Kayle009,项目名称:sentry,代码行数:27,代码来源:test_project.py
示例2: test_multiple_environments
def test_multiple_environments(self):
group = self.create_group()
self.login_as(user=self.user)
environment = Environment.get_or_create(group.project, 'production')
environment2 = Environment.get_or_create(group.project, 'staging')
url = u'/api/0/issues/{}/?enable_snuba=1'.format(group.id)
from sentry.api.endpoints.group_details import tsdb
with mock.patch(
'sentry.api.endpoints.group_details.tsdb.get_range',
side_effect=tsdb.get_range) as get_range:
response = self.client.get(
'%s&environment=production&environment=staging' % (url,),
format='json'
)
assert response.status_code == 200
assert get_range.call_count == 2
for args, kwargs in get_range.call_args_list:
assert kwargs['environment_ids'] == [environment.id, environment2.id]
response = self.client.get('%s&environment=invalid' % (url,), format='json')
assert response.status_code == 404
开发者ID:yaoqi,项目名称:sentry,代码行数:25,代码来源:test_group_details.py
示例3: test_simple
def test_simple(self):
project = self.create_project()
with pytest.raises(Environment.DoesNotExist):
Environment.get_for_organization_id(
project.organization_id,
'prod',
)
env = Environment.get_or_create(
project=project,
name='prod',
)
assert env.name == 'prod'
assert env.projects.first().id == project.id
env2 = Environment.get_or_create(
project=project,
name='prod',
)
assert env2.id == env.id
with self.assertNumQueries(0):
assert Environment.get_for_organization_id(
project.organization_id,
'prod',
).id == env.id
开发者ID:Kayle009,项目名称:sentry,代码行数:29,代码来源:test_environment.py
示例4: test_with_environment
def test_with_environment(self):
self.login_as(user=self.user)
project = self.create_project()
Environment.get_or_create(
project,
'production',
)
conditions = [
{
'id': 'sentry.rules.conditions.first_seen_event.FirstSeenEventCondition',
'key': 'foo',
'match': 'eq',
'value': 'bar',
}
]
actions = [{'id': 'sentry.rules.actions.notify_event.NotifyEventAction'}]
url = reverse(
'sentry-api-0-project-rules',
kwargs={
'organization_slug': project.organization.slug,
'project_slug': project.slug,
}
)
response = self.client.post(
url,
data={
'name': 'hello world',
'environment': 'production',
'conditions': conditions,
'actions': actions,
'actionMatch': 'any',
'frequency': 30,
},
format='json'
)
assert response.status_code == 200, response.content
assert response.data['id']
assert response.data['environment'] == 'production'
rule = Rule.objects.get(id=response.data['id'])
assert rule.label == 'hello world'
assert rule.environment_id == Environment.get_or_create(
rule.project,
'production',
).id
开发者ID:Kayle009,项目名称:sentry,代码行数:51,代码来源:test_project_rules.py
示例5: test_environment
def test_environment(self):
group = self.group
environment = Environment.get_or_create(group.project, 'production')
from sentry.api.serializers.models.group import tsdb
with mock.patch(
'sentry.api.serializers.models.group.tsdb.get_range',
side_effect=tsdb.get_range) as get_range:
serialize(
[group],
serializer=StreamGroupSerializer(
environment_func=lambda: environment,
stats_period='14d',
),
)
assert get_range.call_count == 1
for args, kwargs in get_range.call_args_list:
assert kwargs['environment_id'] == environment.id
def get_invalid_environment():
raise Environment.DoesNotExist()
with mock.patch(
'sentry.api.serializers.models.group.tsdb.make_series',
side_effect=tsdb.make_series) as make_series:
serialize(
[group],
serializer=StreamGroupSerializer(
environment_func=get_invalid_environment,
stats_period='14d',
)
)
assert make_series.call_count == 1
开发者ID:hosmelq,项目名称:sentry,代码行数:35,代码来源:test_group.py
示例6: test_environment
def test_environment(self):
group = self.group
environment = Environment.get_or_create(group.project, 'production')
with mock.patch(
'sentry.api.serializers.models.group.snuba_tsdb.get_range',
side_effect=snuba_tsdb.get_range) as get_range:
serialize(
[group],
serializer=StreamGroupSerializerSnuba(
environment_ids=[environment.id],
stats_period='14d',
),
)
assert get_range.call_count == 1
for args, kwargs in get_range.call_args_list:
assert kwargs['environment_ids'] == [environment.id]
with mock.patch(
'sentry.api.serializers.models.group.snuba_tsdb.get_range',
side_effect=snuba_tsdb.get_range) as get_range:
serialize(
[group],
serializer=StreamGroupSerializerSnuba(
environment_ids=None,
stats_period='14d',
)
)
assert get_range.call_count == 1
for args, kwargs in get_range.call_args_list:
assert kwargs['environment_ids'] is None
开发者ID:Kayle009,项目名称:sentry,代码行数:32,代码来源:test_group.py
示例7: test_environment
def test_environment(self):
group = self.create_group()
self.login_as(user=self.user)
environment = Environment.get_or_create(group.project, 'production')
url = u'/api/0/issues/{}/'.format(group.id)
from sentry.api.endpoints.group_details import tsdb
with mock.patch(
'sentry.api.endpoints.group_details.tsdb.get_range',
side_effect=tsdb.get_range) as get_range:
response = self.client.get(url, {'environment': 'production'}, format='json')
assert response.status_code == 200
assert get_range.call_count == 2
for args, kwargs in get_range.call_args_list:
assert kwargs['environment_ids'] == [environment.id]
with mock.patch(
'sentry.api.endpoints.group_details.tsdb.make_series',
side_effect=tsdb.make_series) as make_series:
response = self.client.get(url, {'environment': 'invalid'}, format='json')
assert response.status_code == 200
assert make_series.call_count == 2
开发者ID:Kayle009,项目名称:sentry,代码行数:25,代码来源:test_group_details.py
示例8: test_with_environment
def test_with_environment(self):
self.login_as(user=self.user)
team = self.create_team()
project1 = self.create_project(teams=[team], name='foo')
self.create_project(teams=[team], name='bar')
rule = project1.rule_set.all()[0]
rule.update(
environment_id=Environment.get_or_create(
rule.project,
'production',
).id,
)
url = reverse(
'sentry-api-0-project-rule-details',
kwargs={
'organization_slug': project1.organization.slug,
'project_slug': project1.slug,
'rule_id': rule.id,
}
)
response = self.client.get(url, format='json')
assert response.status_code == 200, response.content
assert response.data['id'] == six.text_type(rule.id)
assert response.data['environment'] == 'production'
开发者ID:hosmelq,项目名称:sentry,代码行数:28,代码来源:test_project_rule_details.py
示例9: create_environment
def create_environment(self, **kwargs):
project = kwargs.get('project', self.project)
name = kwargs.get('name', petname.Generate(1, ' ', letters=10))
return Environment.get_or_create(
project=project,
name=name
)
开发者ID:NuttasitBoonwat,项目名称:sentry,代码行数:7,代码来源:fixtures.py
示例10: test_simple
def test_simple(self):
project = self.create_project()
env = Environment.get_or_create(
project=project,
name='prod',
)
assert env.name == 'prod'
assert env.projects.first().id == project.id
env2 = Environment.get_or_create(
project=project,
name='prod',
)
assert env2.id == env.id
开发者ID:duanshuaimin,项目名称:sentry,代码行数:17,代码来源:test_environment.py
示例11: test_environment
def test_environment(self):
self.login_as(user=self.user)
group = self.create_group()
events = {}
for name in ['production', 'development']:
environment = Environment.get_or_create(group.project, name)
tagstore.get_or_create_tag_key(
project_id=group.project_id,
environment_id=environment.id,
key='environment',
)
tagstore.create_tag_value(
project_id=group.project_id,
environment_id=environment.id,
key='environment',
value=name,
)
events[name] = event = self.create_event(
group=group,
tags={'environment': name},
)
tagstore.create_event_tags(
project_id=group.project_id,
group_id=group.id,
environment_id=environment.id,
event_id=event.id,
tags=[
('environment', name),
],
)
url = u'/api/0/issues/{}/events/'.format(group.id)
response = self.client.get(url + '?environment=production', format='json')
assert response.status_code == 200, response.content
assert set(map(lambda x: x['id'], response.data)) == set([
six.text_type(events['production'].id),
])
url = u'/api/0/issues/{}/events/'.format(group.id)
response = self.client.get(url + '?environment=invalid', format='json')
assert response.status_code == 200, response.content
assert response.data == []
url = u'/api/0/issues/{}/events/'.format(group.id)
response = self.client.get(
url + '?environment=production&query=environment:development',
format='json')
assert response.status_code == 200, response.content
assert response.data == []
开发者ID:yaoqi,项目名称:sentry,代码行数:58,代码来源:test_group_events.py
示例12: get_environment
def get_environment(self):
from sentry.models import Environment
if not hasattr(self, '_environment_cache'):
self._environment_cache = Environment.objects.get(
organization_id=self.project.organization_id,
name=Environment.get_name_or_default(self.get_tag('environment')),
)
return self._environment_cache
开发者ID:getsentry,项目名称:sentry,代码行数:9,代码来源:event.py
示例13: get
def get(self, request, project, environment):
try:
instance = EnvironmentProject.objects.select_related('environment').get(
project=project,
environment__name=Environment.get_name_from_path_segment(environment),
)
except EnvironmentProject.DoesNotExist:
raise ResourceDoesNotExist
return Response(serialize(instance, request.user))
开发者ID:Kayle009,项目名称:sentry,代码行数:10,代码来源:project_environment_details.py
示例14: _setup_tags_for_event
def _setup_tags_for_event(self, event):
tags = dict(event.data['tags'])
try:
environment = self.environments[tags['environment']]
except KeyError:
environment = self.environments[tags['environment']] = Environment.get_or_create(
event.project,
tags['environment'],
)
GroupEnvironment.objects.get_or_create(
environment_id=environment.id,
group_id=event.group_id,
)
for key, value in tags.items():
for environment_id in [AGGREGATE_ENVIRONMENT_ID, environment.id]:
tag_value, created = tagstore.get_or_create_group_tag_value(
project_id=event.project_id,
group_id=event.group_id,
environment_id=environment_id,
key=key,
value=value,
)
if created: # XXX: Hack for tagstore compat
tag_value.update(
times_seen=1,
first_seen=event.datetime,
last_seen=event.datetime,
)
else:
updates = {
'times_seen': tag_value.times_seen + 1,
}
if event.datetime < tag_value.first_seen:
updates['first_seen'] = event.datetime
if event.datetime > tag_value.last_seen:
updates['last_seen'] = event.datetime
if updates:
tag_value.update(**updates)
tagstore.create_event_tags(
project_id=event.project_id,
group_id=event.group_id,
environment_id=environment_id,
event_id=event.id,
tags=tags.items(),
date_added=event.datetime,
)
开发者ID:binlee1990,项目名称:sentry,代码行数:54,代码来源:tests.py
示例15: test_get_environment
def test_get_environment(self):
environment = Environment.get_or_create(self.project, 'production')
event = self.create_event(
data={'tags': [
('environment', 'production'),
]}
)
event.get_environment() == environment
with self.assertNumQueries(0):
event.get_environment() == environment
开发者ID:binlee1990,项目名称:sentry,代码行数:12,代码来源:test_event.py
示例16: test_get_environment
def test_get_environment(self):
environment = Environment.get_or_create(self.project, 'production')
event = self.store_event(
data={
'environment': 'production'
},
project_id=self.project.id
)
assert event.get_environment() == environment
with self.assertNumQueries(0):
event.get_environment() == environment
开发者ID:yaoqi,项目名称:sentry,代码行数:13,代码来源:test_event.py
示例17: create_event
def create_event(self, *args, **kwargs):
event = super(SnubaSearchTest, self).create_event(*args, **kwargs)
data = event.data.data
tags = dict(data.get('tags', []))
if tags['environment'] not in self.environments:
self.environments[tags['environment']] = Environment.get_or_create(
event.project,
tags['environment'],
)
return event
开发者ID:Kayle009,项目名称:sentry,代码行数:13,代码来源:test_backend.py
示例18: _get_event_environment
def _get_event_environment(event, project, cache):
from sentry.models import Environment
environment_name = event.get_tag('environment')
if environment_name not in cache:
try:
environment = Environment.get_for_organization_id(
project.organization_id, environment_name)
except Environment.DoesNotExist:
logger.warn(
'event.environment.does_not_exist',
extra={
'project_id': project.id,
'environment_name': environment_name,
}
)
environment = Environment.get_or_create(project, environment_name)
cache[environment_name] = environment
return cache[environment_name]
开发者ID:yogeshmangaj,项目名称:sentry,代码行数:22,代码来源:merge.py
示例19: _get_environment_from_request
def _get_environment_from_request(self, request, organization_id):
if not hasattr(request, '_cached_environment'):
environment_param = request.GET.get('environment')
if environment_param is None:
environment = None
else:
environment = Environment.get_for_organization_id(
name=environment_param,
organization_id=organization_id,
)
request._cached_environment = environment
return request._cached_environment
开发者ID:Kayle009,项目名称:sentry,代码行数:14,代码来源:base.py
示例20: validate_environment
def validate_environment(self, attrs, source):
name = attrs.get(source)
if name is None:
return attrs
try:
attrs['environment'] = Environment.get_for_organization_id(
self.context['project'].organization_id,
name,
).id
except Environment.DoesNotExist:
raise serializers.ValidationError(u'This environment has not been created.')
return attrs
开发者ID:Kayle009,项目名称:sentry,代码行数:14,代码来源:rule.py
注:本文中的sentry.models.Environment类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论