Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_auto_resolved(self, mock_is_over_resolve_age):
mock_is_over_resolve_age.return_value = True
user = self.create_user()
group = self.create_group(status=GroupStatus.UNRESOLVED)
result = serialize(group, user, serializer=GroupSerializerSnuba())
assert result["status"] == "resolved"
assert result["statusDetails"] == {"autoResolved": True}
)
other_project = self.create_project()
other_project_release = self.create_release(other_project)
other_project_deploy = Deploy.objects.create(
environment_id=self.environment_2.id,
organization_id=self.organization.id,
release=other_project_release,
date_finished=self.date - timedelta(minutes=350),
)
ReleaseProjectEnvironment.objects.create(
project_id=other_project.id,
release_id=other_project_release.id,
environment_id=self.environment_2.id,
last_deploy_id=other_project_deploy.id,
)
result = serialize([self.project, other_project], self.user, ProjectSummarySerializer())
assert result[0]["id"] == six.text_type(self.project.id)
assert result[0]["latestDeploys"] == {
self.environment_1.name: {
"version": env_1_release.version,
"dateFinished": env_1_deploy.date_finished,
},
self.environment_2.name: {
"version": env_2_release.version,
"dateFinished": env_2_deploy.date_finished,
},
}
assert result[1]["id"] == six.text_type(other_project.id)
assert result[1]["latestDeploys"] == {
self.environment_2.name: {
"version": other_project_release.version,
"dateFinished": other_project_deploy.date_finished,
def test_with_user(self):
user = self.create_user()
tagvalue = TagValue(
key="sentry:user",
value="username:ted",
times_seen=1,
first_seen=datetime(2018, 1, 1),
last_seen=datetime(2018, 1, 1),
)
result = serialize(tagvalue, user)
assert result["key"] == "user"
assert result["value"] == "username:ted"
assert result["name"] == "ted"
assert result["query"] == 'user.username:"ted"'
def test_simple(self):
activity = create_incident_activity(
incident=self.create_incident(),
activity_type=IncidentActivityType.COMMENT,
user=self.user,
comment="hello",
)
result = serialize(activity)
assert result["id"] == six.text_type(activity.id)
assert result["incidentIdentifier"] == six.text_type(activity.incident.identifier)
assert result["user"] == serialize(activity.user)
assert result["type"] == activity.type
assert result["value"] is None
assert result["previousValue"] is None
assert result["comment"] == activity.comment
assert result["dateCreated"] == activity.date_added
def test_is_ignored_with_valid_snooze(self):
now = timezone.now()
user = self.create_user()
group = self.create_group(status=GroupStatus.IGNORED)
snooze = GroupSnooze.objects.create(group=group, until=now + timedelta(minutes=1))
result = serialize(group, user)
assert result["status"] == "ignored"
assert result["statusDetails"]["ignoreCount"] == snooze.count
assert result["statusDetails"]["ignoreWindow"] == snooze.window
assert result["statusDetails"]["ignoreUserCount"] == snooze.user_count
assert result["statusDetails"]["ignoreUserWindow"] == snooze.user_window
assert result["statusDetails"]["ignoreUntil"] == snooze.until
assert result["statusDetails"]["actor"] is None
def _serialize_objects(self, items, request):
serializer_cls = self._get_serializer(request)
return serialize(items, request.user, serializer=serializer_cls())
def get(self, request, organization):
"""
List available auth providers that are available to use for an Organization
```````````````````````````````````````````````````````````````````````````
:pparam string organization_slug: the organization short name
:auth: required
"""
provider_list = []
for k, v in manager:
provider_list.append({"key": k, "name": v.name, "requiredFeature": v.required_feature})
return Response(serialize(provider_list, request.user))
List your Teams In the Current Organization
```````````````````````````````````````````
Return a list of the teams available to the authenticated session and
with the supplied organization. If the user is a super user, then all
teams within the organization are returned.
"""
if is_active_superuser(request):
# retrieve all teams within the organization
queryset = Team.objects.filter(
organization=organization, status=TeamStatus.VISIBLE
).order_by("slug")
return Response(serialize(list(queryset), request.user, TeamWithProjectsSerializer()))
else:
return Response(
serialize(list(request.access.teams), request.user, TeamWithProjectsSerializer())
)
if event is None:
return Response({"detail": "Event not found"}, status=404)
# populate event data
event.bind_node_data()
owners, rules = ProjectOwnership.get_owners(project.id, event.data)
# For sake of the API, we don't differentiate between
# the implicit "everyone" and no owners
if owners == ProjectOwnership.Everyone:
owners = []
return Response(
{
"owners": serialize(Actor.resolve_many(owners), request.user, ActorSerializer()),
# TODO(mattrobenolt): We need to change the API here to return
# all rules, just keeping this way currently for API compat
"rule": rules[0].matcher if rules else None,
"rules": rules or [],
}
# Next, check if this project already owns the ProjectDebugFile.
# This can under rare circumstances yield more than one file
# which is why we use first() here instead of get().
dif = (
ProjectDebugFile.objects.filter(project=project, file__checksum=checksum)
.select_related("file")
.order_by("-id")
.first()
)
if dif is not None:
file_response[checksum] = {
"state": ChunkFileState.OK,
"detail": None,
"missingChunks": [],
"dif": serialize(dif),
}
continue
# There is neither a known file nor a cached state, so we will
# have to create a new file. Assure that there are checksums.
# If not, we assume this is a poll and report NOT_FOUND
if not chunks:
file_response[checksum] = {"state": ChunkFileState.NOT_FOUND, "missingChunks": []}
continue
# Check if all requested chunks have been uploaded.
missing_chunks = find_missing_chunks(project.organization, chunks)
if missing_chunks:
file_response[checksum] = {
"state": ChunkFileState.NOT_FOUND,
"missingChunks": missing_chunks,